I’m developing a Pine Script strategy on TradingView with scaling entries positions.
While strategy.order should ideally scale into an existing position, the backtester seems to interpret each strategy.order call as a separate trade, leading to inaccurate backtesting results.
According to the pine script manual strategy.order does have the ability to scale into open orders.
I have tried using strategy.entry (which does not have this ability) with pyramiding enabled, but got the same problem with the backtester recognizing them as separate trades.
Expected Behavior:
I expect the backtester to recognize the strategy.order calls as increasing the size of the initial position, not creating separate trades.
Question:
How can I modify my code to ensure the backtester correctly interprets the scaling behavior of strategy.order ?
The code is as follows:
if (shortCounter == 1) //initial order
strategy.order("Short", strategy.short, qty=position_size1, comment="Short 1")
else if (shortCounter == 2) // subsequent scaling in points
strategy.order("Short", strategy.short, qty=position_size2, comment="Scaled in Short 2")
else if (shortCounter == 3)
strategy.order("Short", strategy.short, qty=position_size3, comment="Scaled in Short 3")
1
With strategy.entry & pyramiding you can have multiple entries
With switch you can have multiple positionSize
Try this:
float positionSize = na
switch
shortCounter == 1 ? positionSize := position_size1
shortCounter == 2 ? positionSize := position_size2
shortCounter == 3 ? positionSize := position_size3
shortCondition = shortCounter != shortCounter[1]
if shortCondition
strategy.entry(
'Short',
strategy.short,
qty = positionSize,
comment = "Short")
1