8 Day Extended Runs 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Marcuscor

//@version=4

// Inpsired by Linda Bradford Raschke: a strategy  for the T-note futures (ZN1!) that finds 8 day extended runs above/ below the 5sma and buys/ sells the first pullback below/ above the 5sma
// as of 01/10/2021 the t-test score is 4.06

strategy("8DayRun", overlay=true)


SMA = sma(close,5)

TrendUp = close > SMA

TrendDown = close < SMA

//logic to long

TriggerBuy = barssince(close < SMA) > 8

Buy = TriggerBuy[1] and TrendDown

strategy.entry("EL", strategy.long, when = Buy)
strategy.close(id = "EL", when = barssince(Buy) >10)

bgcolor(TriggerBuy ? color.red : na)
bgcolor(Buy ? color.blue : na)

// logic to short 

TriggerSell = barssince(close > SMA) > 8

Sell = TriggerSell[1] and TrendUp

strategy.entry("ES", strategy.short, when = Sell)
strategy.close(id = "ES", when = barssince(Sell) > 10)

bgcolor(TriggerSell ? color.white : na)
bgcolor(Sell ? color.fuchsia : na)



