Only shorts are not working when using the following code. It works for LONG & SHORT, only LONGs but not for ONLY shorts. Shorts are disabled when using longs and so on.
Please can someone help.
// === LOGIC === with time filter added
crsOvr = pr1 > 0.01 // go long when condition is met
crsEql = pr1 <= 0.0 // close positions long or short
crsUnd = pr1 < -0.01 // go short when condition is met
// === EXECUTION LONG ===
if date() and crsOvr // if "within window of time" AND crossover
strategy.entry("Buy", strategy.long) // enter long
if date() and crsEql // if "within window of time" AND crossunder
strategy.close("Buy") // close long
// === EXECUTION SHORT ===
if date() and crsUnd // if "within window of time" AND crossover
strategy.entry("Sell", strategy.short) // enter short
if date() and crsEql // if "within window of time" AND crossunder
strategy.close("Buy")
New contributor
user26741901 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.