Download MetaTrader 5
To add comments, please log in or register
Are you used to trading from your smartphone? Mobile version of MetaTrader 5 will suit you best!
Keep Marcos
120
Keep Marcos 2016.02.20 20:22 

Heey people!

I'm trying to set TrallingStop the next candle. But has no results.

 Thank you.

Sorry English error. 

static datetime new_time = 0;           
 if(OrdersTotal()>0)
      {
         for(int i=0; i<=OrdersTotal(); i++)
         {
            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            {
               if(isNewBar(new_time))
               if(OrderType() == OP_BUY)        OrderModify(OrderTicket(),0,Close[0],0,0,CLR_NONE); 
 }
 }
 }


bool isNewBar(datetime& new_time)
{
   if (new_time != Time[0])               // this helps to avoid placing TRADES on the
   {                                      // same PEAK or BOTTOM multiple times.
      new_time = Time[0];                 //
      return(true);
   }
   else 
      return(false);

 The code is correct because if you take: Its ok

OrderModify(OrderTicket(),0,Bid*1000*Point,0,0,CLR_NONE); 
Keith Watford
Moderator
7888
Keith Watford 2016.02.20 23:08  
OrderModify(OrderTicket(),0,Close[0],0,0,CLR_NONE); 

At the open of a new bar Close[0] is the current price, you cannot usually modify a trade SL with current price. Did you mean Low[1] ?

if(isNewBar(new_time))

Only call this once per tick, before looping through the orders. If you call it in a loop, the 2nd etc time will always return false.

Keep Marcos
120
Keep Marcos 2016.02.20 23:20  

Gumrai  Tank very much to answer.

No understand you talked about false return.

is good thus?

static datetime Time0;
  bool    newBar;
  
   newBar = Time[0] > Time0; 
  static datetime new_time = 0;
  
   
   if (newBar){  
   Time0 = Time[0];
    double barClosePrice = Close[1];        
 if(OrdersTotal()>0)
      {
         for(int i=0; i<=OrdersTotal(); i++)
         {
            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            {
              
               if(OrderType() == OP_BUY)        OrderModify(OrderTicket(),0,Low[1],0,CLR_NONE); 
 }
 }                                                                           
 }
}

 

  thank you for helping me

Keep Marcos
120
Keep Marcos 2016.02.20 23:37  
I can not define the stop in each new candle Low[1].
What's wrong with my code? :(
Keep Marcos
120
Keep Marcos 2016.02.20 23:44  
Keep Marcos
120
Keep Marcos 2016.02.20 23:54  

The stop was set after 25 candles.

Help me please :( 

whroeder1
13602
whroeder1 2016.02.21 01:22  
  1. if(OrdersTotal()>0){
       for(int i=0; i<=OrdersTotal(); i++)
    Orders are positions 0 .. OrdersTotal -1.  remove the equals sign and the if statement is unnecessary.
  2. OrderModify(OrderTicket(),0,Low[1],0,CLR_NONE);
Keep Marcos
120
Keep Marcos 2016.02.21 12:08  
you can tell the error please?
whroeder1
13602
whroeder1 2016.02.22 12:28  
KeepMarcos: you can tell the error please?
You can't modify the opening price of a open order..
/
To add comments, please log in or register