• Sign up >>

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

To add comments, please log in or register
Gary Heard
450
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

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);
   }   
  }
Md Ahsan Ullah Raju
798
Md Ahsan Ullah Raju  
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. 

12
To add comments, please log in or register