Totally baffled, can you spot whats going on??

 

Hi all, 

I've written some "if" functions that delete a stop_order if the price goes past the high/low of the applicable candle in these three bar signals. However, if you take a look at the screen shot below, the sellstop  order at 1.11737 has deleted incorrectly just before it would have entered into a sell order, and the buystop order at 1.12202 has correctly deleted after the price went below the pin bar.. I've provided the "if" function for both so you can compare. I've tried all sorts like giving them different magic numbers, changing the sell "If" to bid > the stop loss of the sellstop order and so on, but to no success. Am I missing something obvious?? 

note: you probably know this already but High[2] refers to the second candle back in the three bar pattern - at least for describing the signal. Is it possible that the "if" function doesn't recognise this numbering system? If so then how is it working for one but not the other...


Thanks for any help!!!!!!

 

//Below is the code of the sell stop order delete

for (int s=OrdersTotal()-1; s >= 0; s--)
   {
   if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
     if(OrderMagicNumber()==sellmagic)
       if(OrderSymbol()==Symbol())
        if(OrderType()==OP_SELLSTOP)
           if(Bid>High[2])    //This line here describes the price level at which to delete the stop order
                 OrderDelete(OrderTicket(),CLR_NONE);
}

//Below is the code for the buy stop order delete

for(int b=OrdersTotal()-1; b >= 0; b--)
   {
   if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
     if(OrderMagicNumber()==buymagic)
       if(OrderSymbol()==Symbol())
        if(OrderType()==OP_BUYSTOP)
           if(Ask<Low[2])    //This line here describes the price level at which to delete the stop order
                 OrderDelete(OrderTicket(),CLR_NONE);  
   }


 

I don't see why you said there is a problem. Your code delete a sell_stop if bid price is above high price of candle "2" back from current candle, which was the case obviously.

 
Alain Verleyen:

I don't see why you said there is a problem. Your code delete a sell_stop if bid price is above high price of candle "2" back from current candle, which was the case obviously.


The sell stop on the left, the red horizontal line, should have only deleted if price went above the black pin bar no? The buy stop to the right deleted correctly after price went below the white pin bar.. unless I'm getting something wrong here? 

 
Jowin6789: should have only deleted if price went above the black pin bar no?
if(OrderType()==OP_SELLSTOP)
           if(Bid>High[2])

No! you aren't checking for a pin bar. The Bid of the white bar is plainly above the high of the middle black bar.


 
whroeder1:

No! you aren't checking for a pin bar. The Bid of the white bar is plainly above the high of the middle black bar.



Ah! Right, ok I see now. I had described the three bar pattern highlighted with the left blue rectangle as below, so I was using the same naming convention to delete the order. High[2] I thought would still be the pin bar in the middle of the left blue rectangle. 

Is there a way I can get it to count backwards in time from the sell_stop order. Basically I want to cancel the sell order if the price goes against it past the top of the pin bar...

 if(body<maxsize 
      && Open[3]<Low[2]
      && Open[2]-Low[2]<maxsize
      && High[2]>High[3]
      && High[2]>High[4]
      && Close[1]<Low[2]
      && High[1]<High[2])