Button Object in Strategy Tester

 

Hi,

I'm using MT5 terminal build 1730 64-bit.

I'm running EA in strategy tester (visual mode).

This EA has panel with buttons BUY and SELL for manual trading.

Why buttons aren't changing state (pressed or not) when I'm clicking it during testing as it works in MT4?

 

Maybe I wrote not clearly but once again ...


I'm using MT5 terminal build 1730 64-bit.

and the question is why in MT5 strategy tester I can't change object Button state as I can do this in MT4 strategy tester.


When I click Button Object in strategy Tester (visual mode) in MT4 and execute code:

bool state = ObjectGetInteger(ChartID(), "buttonSell", OBJPROP_STATE);

then I get state = TRUE.

In MT5 I'm always getting state = FALSE.

 
old_gold:

Maybe I wrote not clearly but once again ...


I'm using MT5 terminal build 1730 64-bit.

and the question is why in MT5 strategy tester I can't change object Button state as I can do this in MT4 strategy tester.


When I click Button Object in strategy Tester (visual mode) in MT4 and execute code:

then I get state = TRUE.

In MT5 I'm always getting state = FALSE.

Hi Old
I have the same problem

has a solution been found?

 

There is no OnChartEvent in tester (MT5), you will have to check the buttons on OnTick.


void HandleKeyPress() 
  {
  
    if (ObjectGetInteger(0,"X",OBJPROP_STATE)) 
    {
       ObjectSetInteger(0,"X",OBJPROP_STATE,false);
       ButtonEvent(88); // 88 == button X
    }  
  }

void ButtonEvent (long key) 
  {
     OnChartEvent(CHARTEVENT_KEYDOWN,key, 0, "" );
  }


Code example shows Key event, but Click works the same.

 
Enrique Dangeroux:

There is no OnChartEvent in tester (MT5), you will have to check the buttons on OnTick.



Code example shows Key event, but Click works the same.

I did exactly like that, like for MT4

I run the code at every tick

The problem is that it seems that the button cannot be pressed

Hence, the state is not changed

 

You can also use OnMillisecondTimer() for example 500 ms.

{
    if (ObjectGetInteger(0,"X",OBJPROP_STATE)) // check state
    {
       ObjectSetInteger(0,"X",OBJPROP_STATE,false);// push back
       // Do something...
    }
}
 
Bump. The workaround doesn't seem to work on MT5 anymore. In the strategy tester the buttons can't even be pushed down. If anyone knows something that might work please let us know. I would really appreciate it.
 
Kevin Keena:
Bump. The workaround doesn't seem to work on MT5 anymore. In the strategy tester the buttons can't even be pushed down. If anyone knows something that might work please let us know. I would really appreciate it.

Hi please show your code.

 
int OnInit()
  {
//Create a button to Turn off EA.
   ObjectCreate(0,"Turn off EA",OBJ_BUTTON,0,0,0);

   ObjectSetInteger(0,"Turn off EA",OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_XDISTANCE,10);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_YDISTANCE,10);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_XSIZE,50);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_YSIZE,50);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_BGCOLOR,clrFireBrick);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_BORDER_COLOR,clrBlack);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_BORDER_TYPE,BORDER_FLAT);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_BACK,false);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_SELECTED,false);
   ObjectSetString(0,"Turn off EA",OBJPROP_TEXT,"x");
   ObjectSetInteger(0,"Turn off EA",OBJPROP_COLOR,clrDarkGray);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_FONTSIZE,10);
   ObjectSetInteger(0,"Turn off EA",OBJPROP_STATE,false);

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(MQLInfoInteger(MQL_TESTER)==true)
      if(ObjectGetInteger(0,"Turn off EA",OBJPROP_STATE))
        ExpertRemove();

  }

In the tester on MT5, the button does not interact with the clicks.

 
Documentation on MQL5: Common Functions / ExpertRemove
Documentation on MQL5: Common Functions / ExpertRemove
  • www.mql5.com
ExpertRemove - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5