Arrastre y suelte SL y TP en el probador. - página 14

 
Aún así decidí añadir el arrastre de SL y TP a la 3ª variante. Es decir, después de que el algoritmo 3 opciones establecidas SL y TP, podemos arrastrarlos donde sea necesario. Esta es, en mi opinión, la mejor opción (universal). En el void OnTick() debería haber una línea: if(PriceModify<Point()) {OnSL=0;OnTP=0;}
void ModifySlTp2(double priceModify=0)
 {
  double sl=0,tp=0;
  
  for(int i=0; i<OrdersTotal(); i++) 
     { 
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
        { 
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) 
           {
            if(MathAbs(OrderOpenPrice()-priceModify)<10*Point())  {OnOrd=true;}    
            if(MathAbs(OrderStopLoss()-priceModify)<10*Point())   {OnSL=true;}
            if(MathAbs(OrderTakeProfit()-priceModify)<10*Point()) {OnTP=true;}
            if(OnOrd || OnSL || OnTP) {TicketModifyOrder=OrderTicket();}
            if(OnOrd) {OnOrd=false; return;}
           }
        }  
     }  
   if(TicketModifyOrder>0)
     {
      if(OrderSelect(TicketModifyOrder, SELECT_BY_TICKET))
        {
         bool typOrdBuy = OrderType()==OP_BUY  || OrderType()==OP_BUYSTOP  || OrderType()==OP_BUYLIMIT;
         bool typOrdSell= OrderType()==OP_SELL || OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT;
         if(!OnOrd && !OnSL && !OnTP)
           {
            if(typOrdBuy)
              {
               sl = NormalizeDouble(priceModify,Digits);
               tp = NormalizeDouble(OrderOpenPrice()+Ktp*(OrderOpenPrice()-sl),Digits);
              }
            if(typOrdSell)
              {
               sl = NormalizeDouble(priceModify,Digits);
               tp = NormalizeDouble(OrderOpenPrice()-Ktp*(sl-OrderOpenPrice()),Digits);
              }
            }    
            if(OnSL) {sl=NormalizeDouble(priceModify,Digits);tp=OrderTakeProfit();}
            if(OnTP) {tp=NormalizeDouble(priceModify,Digits);sl=OrderStopLoss();}
                                                             
            ModifyOrder1(-1, sl, tp, 0); 
            if(OnSL || OnTP) {TicketModifyOrder=0;} 
        }           
     }  
 }
 

Hoy he probado una estrategia en el probador. La práctica demostró que es más conveniente arrastrar sl y tp si se hace un ajuste de las 2 constantes.

Aquí está:

...

if(MathAbs(OrderOpenPrice()-priceModify)<10*Point())  {OnOrd=true;}    
if(MathAbs(OrderStopLoss()-priceModify)<30*Point())   {OnSL=true;}
if(MathAbs(OrderTakeProfit()-priceModify)<30*Point()) {OnTP=true;}
if(OnOrd || OnSL || OnTP) {TicketModifyOrder=OrderTicket();}
if(OnOrd) {OnOrd=false; return;}

...



 
Gracias por su ayuda. Eso es útil. Estaba buscando cómo abrir órdenes en el probador. Se hace a través de variables globales. Pero es un inconveniente que el indicador tenga que ser colocado en un gráfico.