Moving SL to BE question

Back to topics list To post a new topic, please log in or register
avatar
3
ProsteJaa 2015.02.07 13:05
 

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. 

avatar
1211
deysmacro 2015.02.07 13:21 #
 

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.

avatar
3
ProsteJaa 2015.02.07 13:28 #
 
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);                }                       }       }    }

avatar
3
ProsteJaa 2015.02.07 13:29 #
 
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?
avatar
1211
deysmacro 2015.02.07 13:52 #
 
Search at google trailing stop mql4. There are many working examples that you can use.
Back to topics list  

To add comments, please log in or register