How to use OnChartEvent buttons to work in Tester - page 2

 

Here is the fix if anyone who wants to know.


Sections highlighted in yellow is the workaround to get the buttons to work in the strategy tester


Enjoy

void OnTick()
   {
//---
   if( IsVisualMode() )
   {
      long   lparam = 0;
      double dparam = 0.0;
      string sparam = "";
//---
      sparam = "buybutton";
      if( bool( ObjectGetInteger( 0, sparam, OBJPROP_STATE ) ) )
        OnChartEvent( CHARTEVENT_OBJECT_CLICK, lparam, dparam, sparam );
//---
      sparam = "sellbutton";
      if( bool( ObjectGetInteger( 0, sparam, OBJPROP_STATE ) ) )
        OnChartEvent( CHARTEVENT_OBJECT_CLICK, lparam, dparam, sparam );
   }
//---
   for(int i=OrdersTotal()-1;i>=0;i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==magic)
            if(OrderSymbol()==Symbol())
               if(OrderType()==OP_BUY)
                  if(Ask>OrderOpenPrice())
                     if(OrderStopLoss()<Bid-(Stop_Loss*Point*P))
                        ticket1=OrderModify(OrderTicket(),OrderOpenPrice(),Bid - (Stop_Loss*Point*P),OrderTakeProfit(),0,clrNONE);
                        
                          
                        
          
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(OrderMagicNumber()==magic)
            if(OrderSymbol()==Symbol())
               if(OrderType()==OP_SELL)
                  if(Bid<OrderOpenPrice())
                     if(OrderStopLoss()>Ask+(Stop_Loss*Point*P))   
                        ticket2=OrderModify(OrderTicket(),OrderOpenPrice(),Bid + (Stop_Loss*Point*P),OrderTakeProfit(),0,clrNONE);
   }    
   }             
            

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   
   if(id==CHARTEVENT_OBJECT_CLICK && sparam=="buybutton")
   {
      if(OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid - (Stop_Loss*Point*P),Bid + (Take_Profit*Point*P),NULL,magic,0,clrBlue)==-1)
         Print("did not place buy order");
      buybutton.Pressed(false);
   }
   
   if(id==CHARTEVENT_OBJECT_CLICK && sparam=="sellbutton")
   {
      if(OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+(Stop_Loss*Point*P),Ask-(Take_Profit*Point*P),NULL,magic,0,clrRed)==-1)
         Print("did not place buy order");
      buybutton.Pressed(false);
   }   
  }
 
Gary Heard:

Here is the fix if anyone who wants to know.


Sections highlighted in yellow is the workaround to get the buttons to work in the strategy tester


Enjoy

Thank you very much, it is working fine for me. 

 
Marco vd Heijden:
For simple control you can read the OBJPROP_STATE via ObjectGetInteger() function.
Thank you. Now i can make it at tester.
 
Gary Heard:

Here is the fix if anyone who wants to know.


Sections highlighted in yellow is the workaround to get the buttons to work in the strategy tester


Enjoy

Thanks... i get idea from you.
 

2021 year.

Buttons dont work in tester.

ObjectGetInteger( 0, sparam, OBJPROP_STATE )

Always ZERO. Imposible click buton and button dont change state.

How use button s in tester ?

 
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.

This topic is in the MT4 section. Why are you asking about MT5?

 

Excellent Gary!

You gave a solution that other members with more experience did not.

I read always the same answers from those members to this topic... but you made it!

Congratulations

 
Gary Heard #:

Here is the fix if anyone who wants to know.


Sections highlighted in yellow is the workaround to get the buttons to work in the strategy tester


Enjoy

Thank you. I'm very enjoy.

 
Gary Heard #:

Here is the fix if anyone who wants to know.


Sections highlighted in yellow is the workaround to get the buttons to work in the strategy tester


Enjoy

Unfortunately it doesn't work with CHARTEVENT_OBJECT_ENDEDIT. Does anybody have a solution? Thanks!

Reason: