//version=4
strategy("Golden Cross, SMA 200 Long/Short, Moving Average Strategy (by ChartArt)", shorttitle="CA_-_Golden_Cross_Strat", overlay=true)

// Input
switch1=input(true, title="Enable Bar Color?")
switch2=input(false, title="Show Fast Moving Average")
switch3=input(true, title="Show Slow Moving Average")
movingaverage_fast = sma(close, input(50))
movingaverage_slow = sma(close, input(200))

// Calculation
bullish_cross = crossover(movingaverage_fast, movingaverage_slow)
bearish_cross = crossunder(movingaverage_fast, movingaverage_slow)

// Strategy
if bullish_cross
strategy.entry("long", strategy.long)

if bearish_cross
strategy.entry("short", strategy.short)

strategy.close("long", when = bearish_cross or bullish_cross)
strategy.close("short", when = bullish_cross)

// Colors
bartrendcolor = close > movingaverage_fast and close > movingaverage_slow and change(movingaverage_slow) > 0 ? color.green : close < movingaverage_fast and close < movingaverage_slow and change(movingaverage_slow) < 0 ? color.red : color.blue
barcolor(switch1 ? bartrendcolor : na)

// Output
plot(switch2 ? movingaverage_fast : na, color = change(movingaverage_fast) > 0 ? color.green : color.red, linewidth=3)
plot(switch3 ? movingaverage_slow : na, color = change(movingaverage_slow) > 0 ? color.green : color.red, linewidth=3)

// Alerts
alertcondition(bullish_cross, title='Golden Cross (bullish)', message='Bullish')
alertcondition(bearish_cross, title='Death Cross (bearish)', message='Bearish')
Harmonic Patterns

Feragatname