PRI param

51
code
//version=5
strategy("CDC Action Zone V.2 Strategy", overlay=true)

src = input(title="Data Array", type=input.source, defval=ohlc4)
prd1 = input(title="Short MA period", type=input.integer, defval=12)
prd2 = input(title="Long MA period", type=input.integer, defval=26)

AP = ema(src, 2)
Fast = ema(AP, prd1)
Slow = ema(AP, prd2)

Bullish = Fast > Slow
Bearish = Fast < Slow

Green = Bullish and AP > Fast
Red = Bearish and AP < Fast
Yellow = Bullish and AP < Fast
Blue = Bearish and AP > Fast

Buy = Bullish and Bearish[1]
Sell = Bearish and Bullish[1]

// Enter long when Buy condition is met
strategy.entry("Long", strategy.long, when = Buy)

// Enter short when Sell condition is met
strategy.entry("Short", strategy.short, when = Sell)

// Close the long when the short condition is met
strategy.close("Long", when = Sell)

// Close the short when the long condition is met
strategy.close("Short", when = Buy)

// Plot
plot(Fast, "Fast", linewidth=1, color=color.red)
plot(Slow, "Slow", linewidth=2, color=color.blue)

// Color bars based on conditions
bcolor = Green ? color.lime : Red ? color.red : Yellow ? color.yellow : Blue ? color.blue : color.white
barcolor(color=bcolor)
fill(plot1, plot2, bcolor)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.