The issue is as follows:
When we choose calc_on_order_fills=true, I received multiple order entry alerts even though pyramiding is set to 0. I have tried using a statement to open a position only if there are currently no position opened such as:
shortCondition = close < ta.sma(close,50)
if strategy.position_size == 0 strategy.entry(id="SHORT2",long=false, qty = positionSize, when = shortCondition)
But it seems the statement strategy.position_size doesn't update until the candle has closed. If the trade is opened and closed within the same candle, it appears as if there has been no changes to strategy.position_size. The same happens with other statement such as strategy.closedtrades whereas the count doesn't update within the candle but after candle is closed.
Is there any other function that provides a mechanism within a candle (before it closes) to determine whether a position is or has been opened ?