Using the pine script editor in TradingView, I’ve noticed a strange occurrence. When there are triggers to exit a long trade and a trigger to enter a short trade on the same bar, the position has 2x the position size than I would expect. It does not have effect on the Profit/loss calculations but send webhook request to my broker with 2x the intended quantity. Any strategy using strategy.entry(“ID1”,streategy.long) then strategy.entry(“ID2”,streategy.short) produces these results. So the question I have is how do I prevent strategy for displaying this behavior and sending 2x the intended quantity to the broker. Here is an example:
I tried following strategy and expected the quantity of the trade to be 1.
/@version=5
strategy(“BarUpDn Strategy”, overlay=true, default_qty_type = strategy.fixed, default_qty_value = 1)
maxIdLossPcnt = input.float(1, “Max Intraday Loss(%)”)
strategy.risk.max_intraday_loss(maxIdLossPcnt, strategy.percent_of_equity)
if (close > open and open > close[1])
strategy.entry(“BarUp”, strategy.long)
if (close < open and open < close[1])
strategy.entry(“BarDn”, strategy.short)
But the resulting chart and quantity send to the broker using webhook was 2
enter image description here
Any recommendation on avoiding webhook sending 2x the ordered quantity would be appreciated. Thank you
Adek is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.