Delay on OHLC prices of the current (0-indexed) bar ?

 

Hello

I wrote a function in order to detect whether my SL was hit: inside the OnTrade() function I compare the Low of the current bar iLow(symbol_,PERIOD_CURRENT,0) with my SL level. For Example if I was long and Low<= SL,  I would know the SL was triggered.

It turns out that rarely works.... when SL is triggered, the Low of the current bar is often higher (in this example- Long) than the SL level when I make this control at the moment the SL is triggered (inside the OnTrade() function).

Could it be that OHLC prices of the current bar are updated with delay, or am I missing something?


Does anyone suggest an easy and straightforward way to detect whether a SL is triggered?


Thank you.

 
 
MarkCast:

Hello

I wrote a function in order to detect whether my SL was hit: inside the OnTrade() function I compare the Low of the current bar iLow(symbol_,PERIOD_CURRENT,0) with my SL level. For Example if I was long and Low<= SL,  I would know the SL was triggered.

It turns out that rarely works.... when SL is triggered, the Low of the current bar is often higher (in this example- Long) than the SL level when I make this control at the moment the SL is triggered (inside the OnTrade() function).

Could it be that OHLC prices of the current bar are updated with delay, or am I missing something?


Does anyone suggest an easy and straightforward way to detect whether a SL is triggered?


Thank you.

Mark from what you've said, you are performing your market logic in the OnTrade() function, but that function is only called once, when you place your trades. This may explain why you experienced it "rarely works", because that function is rarely called.

Have you considered placing your market logic in the OnTick() function instead? Or that didn't work for you?

 
Gamuchirai Zororo Ndawana #:

Mark from what you've said, you are performing your market logic in the OnTrade() function, but that function is only called once, when you place your trades. This may explain why you experienced it "rarely works", because that function is rarely called.

Have you considered placing your market logic in the OnTick() function instead? Or that didn't work for you?


Yes, I'm performing this only in OnTrade() because my aim is to optimize and lower the resources consumed by the EA. I carry out the check only when a trade related to my EA is detected (or a change of its position - by means of magic n.) and check whether a SL was triggered.

My idea was that, when SL is triggered, MT calls for OnTrade() function, and there I compare the minimum of the current bar: it should be lower or equal the SL level (in case I had long position) but I realized this kind of logic rarely works, I mean, even if SL is triggered and OnTrade() is called, at that moment the condition ( iLow(current bar) <= SL level  ) is not true because the low is higher than SL level, and I don't understand the reason......