Moving SL to BE question

 

Hi there, 

 I have a question regarding moving SL to BE in my EA. Could you please help me?

I want to move to BE when price moves X pips in my favour. Here is part of my code:

 

   void TrailOrder(int type)

{

   

                  

      {

         if(type==OP_BUY)

                  

         {

            if(Bid-OrderOpenPrice()>TrailingStop*Point)

            

               {

                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);

                  Print("Bid-open=",Bid-OrderOpenPrice());

                  Print("TrailingStop*Point=", TrailingStop*Point);

               }

            

         }

         if(type==OP_SELL)

         {

            if((OrderOpenPrice()-Ask)>(TrailingStop*Point))

            

               {

                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red);

               }

            

         }

      }

   

}

 

 

 

Sorry for dumb question. Im very new in programming. Thank you in advance for your help. I guess condition is never met. I think there is some logical mistake. I tried to print out when conditions are met but never happened. 

 

Please use SRC (besides video icon) when posting codes. Just edit your post.


You need to use loop to identify opened trades. By the way, what you want is actually available at many places. Try googling it.

 
void TrailOrder(int type)

{

   

                  

      {

         if(type==OP_BUY)

                  

         {

            if(Bid-OrderOpenPrice()>TrailingStop*Point)

            

               {

                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);

                  Print("Bid-open=",Bid-OrderOpenPrice());

                  Print("TrailingStop*Point=", TrailingStop*Point);
deysmacro:

Please use SRC (besides video icon) when posting codes. Just edit your post.

You need to use loop to identify opened trades. By the way, what you want is actually available at many places. Try googling it.

               }                       }          if(type==OP_SELL)          {             if((OrderOpenPrice()-Ask)>(TrailingStop*Point))                             {                   OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red);                }                       }       }    }
 
deysmacro:

Please use SRC (besides video icon) when posting codes. Just edit your post.


You need to use loop to identify opened trades. By the way, what you want is actually available at many places. Try googling it.

aah, so I haven't chosen trade which to modify?
 
Search at google trailing stop mql4. There are many working examples that you can use.