i want to make an 1 hour delay after my strategy hit stop loss or take profit. Here is an example that is not working, would you explain me why or figure it out? PineScript v5 on tradingview
xSMA = ta.sma(close, Length)
xHighBand = xSMA + (xSMA * PercentShift / 100)
xLowBand = xSMA - (xSMA * PercentShift / 100)
entershort = close > xHighBand
enterlong = close < xLowBand
//reopenPositionAfter(timeSec) =>
// if strategy.closedtrades > 0
//if time - strategy.closedtrades.exit_time(strategy.closedtrades - 1) >= timeSec * 100000
// strategy.entry("Long", strategy.long)
conditionFilter = not ta.barssince(ta.change(strategy.closedtrades)) == 5
//barsSinceClosed = strategy.closedtrades > 0 ? bar_index - strategy.closedtrades.exit_bar_index(strategy.closedtrades - 1) : na
//barsSinceClosed = bar_index - strategy.closedtrades.exit_bar_index(strategy.closedtrades - 1)
isFlat = (strategy.position_size == 0)
if ( isFlat and enterlong and inDateRange and conditionFilter )
strategy.entry("Long", strategy.long)
if ( isFlat and entershort and inDateRange and conditionFilter)
strategy.entry("Short", strategy.short)
strategy.exit("Long Exit", "Long", profit = close * 0.01 / syminfo.mintick, loss = close * 0.005 / syminfo.mintick)
strategy.exit("Short Exit", "Short", profit = close * 0.01 / syminfo.mintick, loss = close * 0.005 / syminfo.mintick)
plot(xSMA, color=color.green, title="SMA")
plot(xHighBand, color=color.blue, title="High Band")
plot(xLowBand, color=color.blue, title="Low Band")
if (not inDateRange)
strategy.close_all()
I tried function barssince or strategy.closedtrades