setting pending order automatically

 

hello every one.

I wanna to write an expert adviser which can set a buy limit automatically under a special condition. the idea is very simple and easy as below:

in every time, consider the last candle[1] and one candle before it[2].

if [1] is bullish and [2] is bearish, set a buy limit on the open of [1]. I test the expert on daily time frame. but it didn't work !

the main problem is that, it should open only one pending order per daily candle.

could you please help me and guide me what is the problem?

thanks a lot

Files:
test.mq5  2 kb