Drag and drop SL and TP in the tester. - page 13

 
Artyom Trishkin:
Or you can combine it with the keypad buttons ;)
Yes, also an option.
 
khorosh:
So this is where I am wrong. In case we need to pull both SL and TP from the order opening line, we can't do that, because there is a problem of how to know what to pull. So we need to identify the type of action on a real chart as in the direction of the cursor, either using a keyboard key or creating a button to set the type of action. The first option is used on the real chart and is the best in my opinion.
Ctrl+mouse - stop. Just mouse - take. And drag wherever you need at once.
 
Artyom Trishkin:
Yes, it is clear. What I mean is this: if there is no stop, we can pull the line of the order itself and the stop will be set where we "pull" the line to. This is the case if we don't have takeout processing. And if we have processing of both stops and toes, but the order has neither, then if we draw the order line, what should we set? A take or a stop?

if there is no stop and take

For example for buy: if you pull up, then tap, if you pull down, then sl

 
pako:

if there is no stop and take

For example for buy: if you pull up, then tap, if you pull down, then sl

This is how it works in the terminal. And to move the stop to the profit zone for Buy - that's what we're discussing.
 
Artyom Trishkin:
This is the way it is in the terminal. And to make the Buy stop move to the profit zone - that's what we are discussing.
That's what I'm saying: make it like in the terminal
 
pako:
I'm talking about making it like the terminal.
It has already been said about doing it as in the terminal. Now it's about how NOT to do it in the terminal.
 
Artyom Trishkin:
The way it is done in the terminal has already been explained. Now it's about how NOT to do it in the terminal.
I seem to be writing in Russian
 
pako:
I think I write in Russian.
I'm answering in the same language... ;)
 

This morning, with a clear head, I found a solution. In addition, I got rid of the extra loop in the modification function. I have made a modification function for two variants:

1) If SL and TP are not set for an order, click on the order and SL and TP will pop up at 50 points. If needed, drag and drop them where needed. If the order already has SL and TP, we drag them wherever we want.

2) A variant of how it is done on a real chart. If we do not have SL and TP, we drag them out of the order line, and then move them wherever we want.

The first variant:

void ModifySlTp(double priceModify=0)
 {
  double sl=0,tp=0;
  if(TicketModifyOrder==0)
    {  
     for(int i=0; i<OrdersTotal(); i++) 
      { 
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
         { 
          if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) 
            {
             if(MathAbs(OrderStopLoss()-priceModify)<30*Point())   {OnSL=true;}
             if(MathAbs(OrderTakeProfit()-priceModify)<30*Point()) {OnTP=true;}
             if(MathAbs(OrderOpenPrice()-priceModify)<30*Point())  {OnOrd=true;} 
               { 
                if(OnSL || OnTP || OnOrd)
                  {
                   TicketModifyOrder=OrderTicket(); break;
                  }
               }
            }
         }  
      }
    }
   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)
           {
            if(typOrdBuy)
              {
               sl = NormalizeDouble(OrderOpenPrice()-500*Point(),Digits);
               tp = NormalizeDouble(OrderOpenPrice()+500*Point(),Digits);
              }
            if(typOrdSell)
              {
               sl = NormalizeDouble(OrderOpenPrice()+500*Point(),Digits);
               tp = NormalizeDouble(OrderOpenPrice()-500*Point(),Digits);
              }
           }
         if(OnSL) {sl=NormalizeDouble(priceModify,Digits);tp=OrderTakeProfit();}
         if(OnTP) {tp=NormalizeDouble(priceModify,Digits);sl=OrderStopLoss();}   
                                           
          ModifyOrder1(-1, sl, tp, 0);   
        }           
     }  
 }

The second option:

void ModifySlTp(double priceModify=0)
 {
  double sl=0,tp=0;
  if(TicketModifyOrder==0)
    {  
     for(int i=0; i<OrdersTotal(); i++) 
      { 
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
         { 
          if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) 
            {
             if(MathAbs(OrderStopLoss()-priceModify)<50*Point())   {OnSL=true;}
             if(MathAbs(OrderTakeProfit()-priceModify)<50*Point()) {OnTP=true;}
             if(MathAbs(OrderOpenPrice()-priceModify)<50*Point())  {OnOrd=true;} 
               { 
                if(OnSL || OnTP || OnOrd)
                  {
                   TicketModifyOrder=OrderTicket(); break;
                  }
               }
            }
         }  
      }
    }
   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)
           {
            if(typOrdBuy)
              {
               if(priceModify>OrderOpenPrice()) {tp=NormalizeDouble(priceModify,Digits);sl=OrderStopLoss();}
               if(priceModify<OrderOpenPrice()) {sl=NormalizeDouble(priceModify,Digits);tp=OrderTakeProfit();} 
              }
            if(typOrdSell)
              {
               if(priceModify<OrderOpenPrice()) {tp=NormalizeDouble(priceModify,Digits);sl=OrderStopLoss();}
               if(priceModify>OrderOpenPrice()) {sl=NormalizeDouble(priceModify,Digits);tp=OrderTakeProfit();} 
              }
           }
         if(OnSL) {sl=NormalizeDouble(priceModify,Digits);tp=OrderTakeProfit();}
         if(OnTP) {tp=NormalizeDouble(priceModify,Digits);sl=OrderStopLoss();}   
                                           
          ModifyOrder1(-1, sl, tp, 0);   
        }           
     }  
 } 

We should not forget to declare the global variables OnSL, OnTp and OnOrd. And also, in the Expert Advisor wherethe TicketModifyOrder is reset,add the resetting of these variables. And correct names of some variables and name of modification function in EA.

I am waiting for applause from the grateful public. Let's applaud and disperse gentlemen).

 

I've also thought of a 3rd option. This is for those who do not like to carry SL and TP. The algorithm for setting the SL and TP is as follows: you should click once on the order, thus select it (we define the ticket) and then click once at the chart point where you want to set the SL (usually it is a point beyond the local price minimum and maximum). At the same time, the SL will be set at the chosen point and the TP will be set at a point which is Kt times farther away from the order price than the SL is from the order price . Ktp is how many times SL is greater than SL and is defined in an external variable. Note that TicketModifyOrder and OnOrd are now reset not in the OnTick() body but in the function itself. The resetting of these variables in the OnTick() body should be removed. It would also be possible in this variant to make it possible to drag and drop SL and TP, but I'm too lazy to think about it. You can just switch to 1 variant, if you need. And switch in the form of a button.

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) 
           {
            OnOrd=false;
            if(MathAbs(OrderOpenPrice()-priceModify)<30*Point()) {OnOrd=true;}    
            if(OnOrd)
              {
               TicketModifyOrder=OrderTicket();
               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)
           {
            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);
              }                                               
            ModifyOrder1(-1, sl, tp, 0);
            TicketModifyOrder = 0;
           }   
        }           
     }  
 }
Reason: