TrailingStop

Back to topics list To post a new topic, please log in or register
avatar
2
lorran.dba 2015.04.20 10:49
 

Good Morning,

 I am creating an EA and I have a difificult to put TrailingStop Move 

 

Are 2 orders OCO Order Cancel Order, BuyStop and SellStop but doent work in my function TrailingStop

 

   int BTP = BuyTakeProfit   *Point * 10;  

   int STP = SellTakeProfit  *Point * 10;  

  

   for(cnt=0;cnt<total;cnt++)

   {

        OrderSelect(cnt, SELECT_BY_TICKET, MODE_TRADES);


      if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol())  //In this part of the order takes is never to buy or sell

        

      {

         if(OrderType()==OP_BUY)

         {

           // if(TrailingStop>0)  

              if(BTP>0)

            {                 

               //if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-Point*(TrailingStop+TrailingStep),Digits))||(OrderStopLoss()==0))

               

               if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-Point*(BTP+5*10),Digits))||(OrderStopLoss()==0))

               {

                  //OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Green); //Ori

                  

                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*BTP,Digits),OrderTakeProfit(),0,Green);

                  return(0);

               }

            }

         }

         else 

         {

            //if(TrailingStop>0)  

              if(STP>0)

            {                 

                //if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+Point*(TrailingStop+TrailingStep),Digits)))||(OrderStopLoss()==0)) //Ori

                

                if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+Point*(STP+5*10),Digits)))||(OrderStopLoss()==0))

               {

                  //OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*TrailingStop,Digits),OrderTakeProfit(),0,Red); //Ori

                  

                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*STP,Digits),OrderTakeProfit(),0,Red);

                  return(0);

               }

            }

         }

      }

   } 

 Regards,

 

Lorran 

     

 

avatar
13006
WHRoeder 2015.04.20 13:59 #
 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Check your return codes (OrderSelect and OrderModify) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. You must count down when closing/deleting in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum

avatar
2
lorran.dba 2015.04.20 14:13 #
 
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Check your return codes (OrderSelect and OrderModify) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. You must count down when closing/deleting in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum

In this, it remove the order not choose, until here ok.

 

 


      cont = IsTradeAllowed();

      err1 = 0;

    

    

      while(cont)

  

            if(OrderSelect(bt, SELECT_BY_TICKET, MODE_TRADES))

               {

                  if(OrderType() <= OP_SELL)

                     {

                        RemoveOrder(st);

                        cont = false;

                        

                     }

               }

            else

               err++;


            if(OrderSelect(st, SELECT_BY_TICKET, MODE_TRADES))

               {

                  if(OrderType() <= OP_SELL)

                     {

                        RemoveOrder(bt);

                        cont = false;

                        

                     }

               }

            else

               err++;

            if(err > 0)

               err1++;

            if(err1 > TIMEOUT) 

               cont = false;

            Sleep(300);

            cont = cont && IsTradeAllowed(); 

 

 

void RemoveOrder(int ticket)

   {

      if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))

         if(OrderType() <= OP_SELL)

            OrderClose(ticket, OrderLots(), OrderClosePrice(), Slippage);

         else

            OrderDelete(ticket);

      CheckError();

   } 

Back to topics list  

To add comments, please log in or register