Button Object in Strategy Tester - page 2

 
Anyone found a solution for this problem? 
 
Pedro Miguel Madeira Varela: Anyone found a solution for this problem? 

Yes! Read the thread from start to finish and you will understand!

 
Fernando Carreiro #:

Yes! Read the thread from start to finish and you will understand!

Sorry for resurrecting this old thread, but it doesn't look like anyone found the solution. Could you please point it out? Thanks!
 
Andriy Moraru #:
Sorry for resurrecting this old thread, but it doesn't look like anyone found the solution. Could you please point it out? Thanks!
no problem, the buttons work in the tester
 
Dz Mak #:
no problem, the buttons work in the tester
They don't seem to change the OBJPROP_STATE value on click. Is it some other property that is changed?
 
@Andriy Moraru #: They don't seem to change the OBJPROP_STATE value on click. Is it some other property that is changed?

The following post is very old and I don't know if it still works, but maybe it can be helpful to you ...

Forum on trading, automated trading systems and testing trading strategies

Chart Event For MT4 Backtester

Fernando Carreiro, 2016.04.03 15:40

I know this is a an old thread, but I recently needed to debug some of my code that implements "buttons" to control certain aspects of an EA I was coding and had need for it to work in the Strategy Tester.

The solution I came up with was to check the button states on every incoming tick when the EA was in Visual Mode.

In other words, something like this:

void CheckResetButton()
{
   if( bool( ObjectGetInteger( 0, idResetButtonObject, OBJPROP_STATE ) ) )
   {
      Print( "Reset Button Clicked" );
      ObjectSetInteger( 0, idResetButtonObject, OBJPROP_STATE, false );
   }
}

void OnTick()
{
   // Only needed in Visual Testing Mode
   if( IsVisualMode() )
   {
      // Check Chart Buttons in Visual Mode
      CheckResetButton();
   }

   return;
}
 
Fernando Carreiro #:

The following post is very old and I don't know if it still works, but maybe it can be helpful to you ...

Unfortunately, that solution only works in MT4 and doesn't work in MT5.
 
Has a solution been found?
 
Tahjyei Thompson #:
Has a solution been found?

yes

#define SYSTEM_TAG "TEST_"
int clicks=0;
int OnInit()
  {
  clicks=0;
  ObjectsDeleteAll(0,SYSTEM_TAG);
  ObjectCreate(0,SYSTEM_TAG+"_BTN",OBJ_BUTTON,0,0,0);
  ObjectSetInteger(0,SYSTEM_TAG+"_BTN",OBJPROP_XSIZE,200);
  ObjectSetInteger(0,SYSTEM_TAG+"_BTN",OBJPROP_YSIZE,30);
  ObjectSetInteger(0,SYSTEM_TAG+"_BTN",OBJPROP_XDISTANCE,20);
  ObjectSetInteger(0,SYSTEM_TAG+"_BTN",OBJPROP_YDISTANCE,30);
  ObjectSetString(0,SYSTEM_TAG+"_BTN",OBJPROP_TEXT,"button");
  return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
  ObjectsDeleteAll(0,SYSTEM_TAG);
  }
void OnTick()
  {
  if(MQLInfoInteger(MQL_TESTER)==1&&MQLInfoInteger(MQL_VISUAL_MODE)==1){
    if(ObjectGetInteger(0,SYSTEM_TAG+"_BTN",OBJPROP_STATE)==1){
      clicks++;
      ObjectSetString(0,SYSTEM_TAG+"_BTN",OBJPROP_TEXT,"Clicks "+IntegerToString(clicks));
      ObjectSetInteger(0,SYSTEM_TAG+"_BTN",OBJPROP_STATE,false);
      }
    }
  
  }
 
Lorentzos Roussos #:

yes

Perfect!! :)