#trading #strategy #technicalanalysis #investing
![[Pasted image 20230328185431.png]]
# Rules
Basic idea taken from: <https://www.quantifiedstrategies.com/alexander-elder-triple-screen-strategy/>
1. The close must be higher than the close 250 days ago (the long-term trend filter).
2. The close must be higher than the close 22 days ago (the intermediate trend filter).
3. The close today must be a three-day low (of the close).
4. If 1-3 are true, then go long at the close.
5. We sell at the close when the close is higher than yesterday’s close.
```js
//@version=5
strategy("Trend Filter Strategy", overlay=true)
// Calculate the required indicators
tide = ta.sma(close, 250)
long_term_filter = close > tide
wave = ta.sma(close, 22)
intermediate_filter = close > wave
ripple = ta.lowest(low, 3)
three_day_low = low == ripple
// Define the entry and exit conditions
enter_long = long_term_filter and intermediate_filter and three_day_low
exit_long = close > close[1]
plot(tide, title="tide", color=color.olive, linewidth=2)
plot(wave, title="wave", color=color.green, linewidth=2)
plot(ripple, title="ripple", color=color.purple, linewidth=2)
// Submit the long order if the entry condition is true
if enter_long
strategy.entry("Long", strategy.long, comment="buy")
// Exit the long position if the exit condition is true
if strategy.position_size > 0 and exit_long
strategy.close("Long", comment = "sell")
```