Change SL on an old order that is in deep DD...

 

Lets say we place a Long order without stops. After a few minutes the price falls and it goes into deep drawdown.

The price then settles a few hours later, and we want to place a SL on that old order that is far away both in time and price.....Can't do it !

Strange because I think I've done it several times when trading manually. I know the book says: Bid - SL > StopLevel SL here would be

the stoploss price for that old order, eg 1000 points below its open price.

Is this true... can we set or modify SL only when on the profitable side ?

 
DayTrader:

Lets say we place a Long order without stops. After a few minutes the price falls and it goes into deep drawdown.

The price then settles a few hours later, and we want to place a SL on that old order that is far away both in time and price.....Can't do it !

Strange because I think I've done it several times when trading manually. I know the book says: Bid - SL > StopLevel SL here would be

the stoploss price for that old order, eg 1000 points below its open price.

Is this true... can we set or modify SL only when on the profitable side ?


No you can also set a stoploss if the trade is in loss think the way you have programmed it was wrong did you check on errors in terminal...

and how did you code it ??

 

Ok here is the Results, only the last trade is troublesome, the price falls just after entry and for 6 months I cant place SL

**************

13 2011.10.24 01:30 buy 5 0.10 1.38579 0.00000 0.00000 0.00 4959.78
14 2011.10.24 04:30 modify 5 0.10 1.38579 1.38480 0.00000 0.00 4959.78
15 2011.10.24 11:52 s/l 5 0.10 1.38480 1.38480 0.00000 -9.90 4949.88
16 2011.10.28 02:30 buy 6 0.10 1.41702 0.00000 0.00000 0.00 4949.88
17 2011.10.28 05:30 modify 6 0.10 1.41702 1.41603 0.00000 0.00 4949.88
18 2011.10.28 07:35 s/l 6 0.10 1.41603 1.41603 0.00000 -9.90 4939.98
19 2011.10.28 10:45 buy 7 0.10 1.41681 0.00000 0.00000 0.00 4939.98
20 2011.10.28 13:45 modify 7 0.10 1.41681 1.41582 0.00000 0.00 4939.98
21 2011.10.28 14:13 s/l 7 0.10 1.41582 1.41582 0.00000 -9.90 4930.08
22 2011.11.14 09:00 buy 8 0.10 1.37519 0.00000 0.00000 0.00 4930.08
23 2012.05.31 23:59 close at stop 8 0.10 1.23643 0.00000 0.00000 -1418.72 3511.36

*************

No errors in the Journal, GetLastError reports 0 everywhere.

In the Journal the Print debug line prints: 2012.06.10 00:37:42 2012.05.31 23:59 TEST-06 EURUSD,M15: OOOOOOOOOOOOOO Ticket: 8 OrderOpenPrice: 1.3752 NewSLprice: 1.3742

so here we see that the SL price is in fact 100 points below the order open price.

Test conditions are SL=99 points, TP=11 points, Spread=16 points, and stop- and freezelevels=10 points. No mismatched chart errors.

Note that I've put in a delay of 3hrs, this to simulate a server/network error or trade context busy, or whatever that prevents me from putting the ECN SL right away.

Also note the debug V-line... this to verify that order No 8 actually passes above conditions... and it does, 3hrs after entry the chart is full of V-lines.

This is really strange, we're 1000s of points away from the SL price but cant modify it.

The test code:

//-------------------------------
void DoInitialStops()
   {
   double SL = StopLoss;
   double TP = TakeProfit;
   double NewSLprice;
   double NewTPprice;
   bool Result;
   bool SLoutsideStopLevel;
   bool TPoutsideStopLevel;
   //

   //
   int Orders = OrdersTotal() - 1;
   for (int i = Orders; i >= 0; i--)
      {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
           
      if (OrderMagicNumber() == MagicNumber  || OrderMagicNumber() == MagicNumber1 && OrderSymbol() == Symbol())
         {         
         if (  (TimeCurrent() - OrderOpenTime()) < 3*3600) return(0);//DEBUG: place stop after a 3hr server disconnect
         
       
         if (OrderType() == OP_BUY && OrderStopLoss() == 0)
            {                                                  
            NewSLprice = NormalizeDouble(OrderOpenPrice() - (SL * Point), Digits);//SL Refered to entryprice  
            //if the new SL is sufficiently away from current market as determined by stoplevel and freezelevel:   
            if ((Bid - NewSLprice) > StopLevel * Point)  SLoutsideStopLevel = TRUE;
             
            if(SLoutsideStopLevel) if(OrderTicket()==8) DrawVline (Aqua, Time[0]);//DEBUG
            if(OrderTicket()==8) Print("OOOOOOOOOOOOOO  ","Ticket:  ", OrderTicket(),"   OrderOpenPrice:  ",OrderOpenPrice(),"   NewSLprice:  ",NewSLprice);//DEBUG
                                                               
            if (  SLoutsideStopLevel)  Result = OrderModify(OrderTicket(), OrderOpenPrice(), NewSLprice, 0, 0, Aqua);   

            }
//*********            
         }                  
      }            
                  

           
   return(0);
   }
//-------------------------------  
 
DayTrader:

Ok here is the Results, only the last trade is troublesome, the price falls just after entry and for 6 months I cant place SL

............

This is really strange, we're 1000s of points away from the SL price but cant modify it.

The test code:


Buy Orderopenprice 1.37519

new Sl price NewSLprice: 1.3742

But after placing the price drops and i think it dropped lower then 1.3742 and then it is not possible to trie to set a Sl for a buy above The actual Bid Price

The StopLoss for a buy has to be set lower then actual Bid price

1000 points away from SL but SL >>>> BID ( distant SL from Orderopenprice 100 points)

if ((Bid - NewSLprice) > StopLevel * Point)  SLoutsideStopLevel = TRUE;

we have now something like 1.30 - 1.3742 that is < 0 So it is false and there is no modify

NewSLprice = NormalizeDouble(OrderOpenPrice() - (SL * Point), Digits);//SL Refered to entryprice  

Change OrderOpenPrice() in this line.....

 
DayTrader:

Is this true... can we set or modify SL only when on the profitable side ?

No, but you do have to check the stop loss relative to the market price.
 

In this line ...

if (  (TimeCurrent() - OrderOpenTime()) < 3*3600) return(0);//DEBUG: place stop after a 3hr server disconnect

Even though it is for debug, you probably should write it as

if( (TimeCurrent() - OrderOpenTime()) < 3*3600 )
    continue;                                   //DEBUG: place stop after a 3hr server disconnect

The difference being that the return prevents you setting stops on any other orders earlier in the list which may be have been placed earlier in time.

 

This block is "untidy" ...

      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
           
      if (OrderMagicNumber() == MagicNumber  || OrderMagicNumber() == MagicNumber1 && OrderSymbol() == Symbol())

The OrderSelect hasn't been tested and you are relying on the precedence of logical OR above logical AND which is non-standard for C and therefore more difficult to read and debug.

Might I suggest ...

   if( OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() ){
      if( OrderMagicNumber()==MagicNumber || OrderMagicNumber()==MagicNumber1 ){
           // do stuff here
      }
   }
 

This code is no good ...

            NewSLprice = NormalizeDouble(OrderOpenPrice() - (SL * Point), Digits);//SL Refered to entryprice  
            //if the new SL is sufficiently away from current market as determined by stoplevel and freezelevel:   
            if ((Bid - NewSLprice) > StopLevel * Point)  SLoutsideStopLevel = TRUE;

What you are saying is that if the StopLoss is too close to the market, or the wrong side of the market, then don't bother setting a stop at all and don't bother even mentioning it!

What you really need to say is "if the stop loss is the wrong side of the market, close the order right now"

Either that or put on a stop relative to the market, even though that is not what you originally planned.

 
dabbler:

In this line ...

Even though it is for debug, you probably should write it as

The difference being that the return prevents you setting stops on any other orders earlier in the list which may be have been placed earlier in time.




Not the case, all the earlier orders in the list had their stops set. But further down the road when we start dealing with TPs and sells then continue is the way to go.
 
dabbler:

This block is "untidy" ...

The OrderSelect hasn't been tested and you are relying on the precedence of logical OR above logical AND which is non-standard for C and therefore more difficult to read and debug.

Might I suggest ...

if( OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() ){
if( OrderMagicNumber()==MagicNumber || OrderMagicNumber()==MagicNumber1 ){
// do stuff here
}
}

Made no difference...
 

dabbler
:

This code is no good ...

What you are saying is that if the StopLoss is too close to the market, or the wrong side of the market, then don't bother setting a stop at all and don't bother even mentioning it! Uh..what do you mean?

What you really need to say is "if the stop loss is the wrong side of the market, close the order right now" Nope! A valid order has been entered based on signals This function is to set stops only.

Either that or put on a stop relative to the market, even though that is not what you originally planned.

Ok... The SL which is a point value intended as a max-loss for the order, so a SL of say 99 points will must place the SL 99 points below order open price. CAN NOT place stop 99 above market, that is just pointless.

But perhaps we instead should calculate how far away the intended SL (order open price - SL) is from the market, and use THAT in stoplevel calculations...is that what you mean?