'Producing a buy or sell only starting on the 3rd signal in the same direction from the algo, and then exiting on the 1st signal in opposite direction
I'd like my strategy function to enter a buy or sell only starting from the 3rd signal of my trading algo and all subsequent signals in the same direction, and then I'd like the strategy to exit on the 1st signal in the opposite direction.
For reference here is my current strategy:
strat_dir_value = strat_dir_input == "Long" ? strategy.direction.long : strat_dir_input == "Short" ? strategy.direction.short : strategy.direction.all
strategy.risk.allow_entry_in(strat_dir_value)
start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window
finish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish window
window() => // create function "within window of time"
time >= start and time <= finish ? true : false
if window()
strategy.entry('buy', strategy.long, when=buysignal)
strategy.entry('sell', strategy.short, when=sellsignal)
Cheers
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
