How to prevent from opening new order in same candle

Hi fellow traders.
I am trying to write an Expert and saying under specific circumstances, place an order and take profit or stop loss.
But sometimes it opens and closes under the same candle.
And because in this candle the situations are still valid, it opens a new trade.
How can I say if it already opened an order in this candle, don't open a new one again after closing the previous one?

if (PositionsTotal()-1==0) // we have no open positions.

1、only one order in one candle.:  set a global variable to record the time of every candle, open orders only when the value of the vairable changes.

2、Buy only at a close price:buying at a close price would be the same with buying at the next open price, the method mentioned  above could solve this as well.

3、How to prevent my expert to open new order if other order was already closed on the same candle

you need to build a function that returns the close time of the last closed order. then check if  TimeCurrent() > last_close_time + periodseconds();

Buy only at a close price
Buy only at a close price
  • 2010.01.30
Hi, I want to write an EA which only opens an new order at the close price of the candle. How can I do it...