TRA
TRA

Reputation: 1

Pinescript cooldown period after condition is met until another condition is met

I am new here and with programing in general. I recently started to program a RSI based strategy in pinescript for tradingview.

The script has a trailing stop loss and I am trying to make it not enter any trades if the following condition is met: 2 consecutive short positions stopped out by trailing stop loss

until another condition is met: the RSI value crosses the RSI value 40 again.

basically if it got stopped out 2 times entering a short position based on my defined conditions in a row, it should stop entering positions until the RSI crosses the value 40 again.

Is that possible and how would it work? thank you a lot for your help, as I am fairly new to this

I have tried this, but it is not complete and I am not sure about the variables and how to define the conditions properly

// Track consecutive stopped out short positions
var consecutive_stopped_out_shorts = na

// Update consecutive stopped out shorts count
if (strategy.position_size < 0 and strategy.opentrades == 0)
    consecutive_stopped_out_shorts := consecutive_stopped_out_shorts + 1
else
    consecutive_stopped_out_shorts := 0

if (should_enter_short and consecutive_stopped_out_shorts < 2)
    strategy.entry("Short", strategy.short)

Upvotes: 0

Views: 43

Answers (0)

Related Questions