Faites glisser et déposez SL et TP dans le testeur. - page 14

 
J'ai quand même décidé d'ajouter le traînage SL et TP à la 3ème variante. C'est-à-dire qu'après que les 3 options de l'algorithme aient fixé le SL et le TP, nous pouvons les faire glisser là où c'est nécessaire. C'est à mon avis la meilleure option (universelle). Dans le void OnTick() il devrait y avoir une ligne : 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;} 
        }           
     }  
 }
 

J'ai testé une stratégie dans le testeur aujourd'hui. La pratique a montré qu'il est plus pratique de faire glisser sl et tp si l'on procède à un ajustement des 2 constantes.

C'est ici :

...

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;}

...



 
Merci pour votre aide. C'est utile. Je cherchais à savoir comment ouvrir des ordres dans le testeur. Cela se fait par le biais de variables globales. L'inconvénient est que l'indicateur doit être placé sur un graphique.