fxbaba108
fxbaba108

Reputation: 19

PINESCRIPT : How to avoid Multiple order fills alerts when calc_on_order_fills = true

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 ?

Upvotes: 0

Views: 938

Answers (1)

Starr Lucky
Starr Lucky

Reputation: 1961

That's not true. strategy.closedtrades updates its value. See examples. Apply this on RT-chart:

//@version=5
strategy("My strategy", overlay=true, calc_on_order_fills = true)

if barstate.isrealtime
    strategy.entry("Long", strategy.long)
    strategy.entry("Short", strategy.short)

plot(strategy.closedtrades)

This, for example will stop opening new positions if strategy position is changed in the current bar:

//@version=5
strategy("My strategy", overlay=true, calc_on_order_fills = true)

if barstate.isrealtime and strategy.closedtrades == strategy.closedtrades[1]
    strategy.entry("Long", strategy.long)
    strategy.entry("Short", strategy.short)

plot(strategy.closedtrades)

what exactly your case and why do you want recalculate on order fills?

Upvotes: 0

Related Questions