GLUCK?! Mouse click event handling!!! - page 13

 
sergeev:


hurry up! Only now!!! download this unique product!

And you get a version with a specially designed bug - small line blips!


:))


do you have a solution to this problem? I've looked through everything - I can't think of anything else yet, and it's not a bug, changing the lines is deliberate, but it blips - I've written the problem before.

I wouldn't even say it's a blip, it's a shift in lines along the x axis.

 

Dear fellow traders!

I just copied an example from .chm manual in the description of OrderSendAsync function, with a simple button responding to a click, in my case it looks like this:

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
//--- обработка события CHARTEVENT_CLICK ("Нажатие кнопки мышки на графике")
   if( id == CHARTEVENT_OBJECT_CLICK )
   {
      Print( "=> ", __FUNCTION__, ": sparam = ", sparam );
      if( sparam=="Finalize" )
      {
         PrintFormat( "Closing position %s",_Symbol );
         while( !ClosePosition() );

         //--- отожмем нажатую кнопку обратно
         ObjectSetInteger( 0, "Finalize", OBJPROP_STATE, false );
      }
      ChartRedraw();
   }      
}

void CreateFinalizeButton()
{
//--- проверим наличие объекта с именем "Finalize"
   if(ObjectFind(0,"Finalize")>=0)
   {
      //--- если найденный объект не является кнопкой, удалим его
      if(ObjectGetInteger(0,"Finalize",OBJPROP_TYPE)!=OBJ_BUTTON)
         ObjectDelete(0,"Finalize");
   }
   else
      ObjectCreate(0,"Finalize",OBJ_BUTTON,0,0,0); // создадим кнопку "Finalize"
//--- настроим кнопку "Finalize"
   ObjectSetInteger( 0, "Finalize", OBJPROP_CORNER, CORNER_LEFT_LOWER );
   ObjectSetInteger( 0, "Finalize", OBJPROP_XDISTANCE, 100 );
   ObjectSetInteger( 0, "Finalize", OBJPROP_YDISTANCE, 50 );
   ObjectSetInteger( 0, "Finalize", OBJPROP_XSIZE, 150 );
   ObjectSetInteger( 0, "Finalize", OBJPROP_YSIZE, 30 );
   ObjectSetString( 0, "Finalize", OBJPROP_TEXT, "Finalize" );
   ObjectSetInteger( 0, "Finalize", OBJPROP_COLOR, clrBlue );
//--- принудительно обновим график, чтобы кнопки отрисовались немедленно
   ChartRedraw();
}

As it turns out, it triggers when the timeframe changes. Can you please tell me how this problem can be solved?

 
surava:

Dear fellow traders!

I just copied an example from .chm manual in the description of OrderSendAsync function, with a simple button responding to a click, in my case it looks like this:

As it turns out, it triggers when the timeframe changes. Can you please tell me how this problem can be solved?

The standard example for OrderSendAsync does not react on change of the chart period. This means that you have messed up something. You need more information: terminal type, build of the terminal and all of your code.
 
Karputov Vladimir:
The standard example for OrderSendAsync does not react to change of chart period. This means that you have messed up something. You need more information: terminal type, terminal build and your entire code.

Vladimir, thank you for your prompt response!

Here is the information on the terminal:


Here is the code (just started to learn how trading functions work):

#property copyright "surava"
#property link      "https://www.mql5.com"
#property version   "1.00"

ulong MagicNumber = 1649353089;

int OnInit()
{
   CreateFinalizeButton();

   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   while( !ClosePosition() );
   
   if( ObjectFind( 0, "Finalize" ) >= 0 )
      ObjectDelete(0,"Finalize");
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+
void OnTrade()
{
 
}
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
{
   if( trans.type != TRADE_TRANSACTION_REQUEST )
      return;
   
   Print( "============= New transaction =============" );
   Print( __FUNCTION__, " Trans action: ", EnumToString( trans.type ) ); 
   Print( __FUNCTION__, " Trans order state: ", EnumToString( trans.order_state ) );    
   Print( __FUNCTION__, " Result order type: ", EnumToString( request.action ) );
   Print( __FUNCTION__, " Request action: ", EnumToString( request.type ) );
   Print( __FUNCTION__, " Deal price: ", result.price );   
   Print( __FUNCTION__, " Result comment: ", result.comment ); 
}

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
//--- обработка события CHARTEVENT_CLICK ("Нажатие кнопки мышки на графике")
   if( id == CHARTEVENT_OBJECT_CLICK )
   {
      Print( "=> ", __FUNCTION__, ": sparam = ", sparam );
      if( sparam=="Finalize" )
      {
         PrintFormat( "Closing position %s",_Symbol );
         while( !ClosePosition() );

         //--- отожмем нажатую кнопку обратно
         ObjectSetInteger( 0, "Finalize", OBJPROP_STATE, false );
      }
      ChartRedraw();
   }      
}

void CreateFinalizeButton()
{
//--- проверим наличие объекта с именем "Finalize"
   if(ObjectFind(0,"Finalize")>=0)
   {
      //--- если найденный объект не является кнопкой, удалим его
      if(ObjectGetInteger(0,"Finalize",OBJPROP_TYPE)!=OBJ_BUTTON)
         ObjectDelete(0,"Finalize");
   }
   else
      ObjectCreate(0,"Finalize",OBJ_BUTTON,0,0,0); // создадим кнопку "Finalize"
//--- настроим кнопку "Finalize"
   ObjectSetInteger( 0, "Finalize", OBJPROP_CORNER, CORNER_LEFT_LOWER );
   ObjectSetInteger( 0, "Finalize", OBJPROP_XDISTANCE, 100 );
   ObjectSetInteger( 0, "Finalize", OBJPROP_YDISTANCE, 50 );
   ObjectSetInteger( 0, "Finalize", OBJPROP_XSIZE, 150 );
   ObjectSetInteger( 0, "Finalize", OBJPROP_YSIZE, 30 );
   ObjectSetString( 0, "Finalize", OBJPROP_TEXT, "Finalize" );
   ObjectSetInteger( 0, "Finalize", OBJPROP_COLOR, clrBlue );
//--- принудительно обновим график, чтобы кнопки отрисовались немедленно
   ChartRedraw();
}

bool ClosePosition( bool async = true )
{
   int numPos = PositionsTotal();
   PrintFormat( "Positions number: %d", numPos );
   
   if( PositionSelect( _Symbol ) )
      Print( "PositionSelect returned true" );
   else
      Print( "PositionSelect returned false" );
      
   if( numPos == 0 )
      return true;
       
   double volume = PositionGetDouble( POSITION_VOLUME );
   uint posType = PositionGetInteger( POSITION_TYPE );

   MqlTradeRequest req={0};
   req.action      = TRADE_ACTION_DEAL;
   req.symbol      = _Symbol;
   req.magic       = MagicNumber;
   req.volume      = volume;
   switch( posType )
   {
   case POSITION_TYPE_BUY:
      req.type = ORDER_TYPE_SELL;
      req.price = SymbolInfoDouble( req.symbol, SYMBOL_BID );
      break;
   case POSITION_TYPE_SELL:
      req.type = ORDER_TYPE_BUY;
      req.price = SymbolInfoDouble( req.symbol, SYMBOL_ASK );
      break;
   default:
      Print( "Wrong position type" );
      return true;
   }
   req.deviation   = 3;
   req.comment     = "Closing opened position";
   MqlTradeResult  res={0};
   if( !OrderSend( req, res ) )
   {
      Print(__FUNCTION__,": ошибка ",GetLastError(),", retcode = ",res.retcode);
      return false;
   }
   return true;
}
 
surava:

Vladimir, thank you for your prompt response!

Here is the information on the terminal:


Here is the code (just started to learn how the trading functions work):

At a glance - remove while.
 
Karputov Vladimir:
At first glance, remove while.
It does not cost anything to remove it, but it is obvious that the problem lies elsewhere. As for me - I'd rather the problem with a position not closed in time will result in an endless loop than a loss, which you may not even be able to notice right away).
 

I see what the problem is. Just explain this logic, please, why the button handler is affected by the presence/absence of the line

input bool DescriptionModeFull=true;

???

 

Looks like it's not just this line. I'll have to do some more dancing to get the crooked metatrader to work properly...

I.e. in my example it worked fine, but in the real programme it didn't((

 
surava:

I.e. in my example it worked fine, but in the real programme it didn't((

Maybe there's a kink somewhere else? You won't get very far with that approach

 
surava:

Looks like it's not just this line. I'll have to do some more dancing to get the crooked metatrader to work properly...

I.e. in my example it worked fine, but in the real programme it didn't((

Maybe my tambourine is not big enough?