## Golden and Death Cross indicator
## Coded by Chemmy at usethinkscript.com
#input src = close;
input fast = 50;
input slow = 200;
input avgtype = AverageType.SIMPLE;
input color_bars = yes;
input show_bubbles = yes;
input show_arrows = yes;
input one_minute_label = yes;
input two_minute_label = yes;
input five_minute_label = yes;
input ten_minute_label = yes;
input fifteen_minute_label = yes;
input thirty_minute_label = yes;
input one_hour_label = yes;
input two_hour_label = yes;
input four_hour_label = yes;
input one_day_label = yes;
input five_day_label = yes;
input one_month_label = yes;
input one_year_label = yes;
def Ag_1_min = AggregationPeriod.MIN;
def Ag_1_min_close = close(period = Ag_1_min);
def Ag_2_min = AggregationPeriod.two_MIN;
def Ag_2_min_close = close(period = Ag_2_min);
def Ag_5_min = AggregationPeriod.FIVE_MIN;
def Ag_5_min_close = close(period = Ag_5_min);
def Ag_10_min = AggregationPeriod.ten_MIN;
def Ag_10_min_close = close(period = Ag_10_min);
def Ag_15_min = AggregationPeriod.FIFTEEN_MIN;
def Ag_15_min_close = close(period = Ag_15_min);
def Ag_30_min = AggregationPeriod.THIRTY_MIN;
def Ag_30_min_close = close(period = Ag_30_min);
def Ag_1hr = AggregationPeriod.HOUR;
def Ag_1hr_close = close(period = Ag_1hr);
def Ag_2_hr = AggregationPeriod.TWO_HOURS;
def Ag_2_hr_close = close(period = Ag_2_hr);
def Ag_4_hr = AggregationPeriod.four_HOURS;
def Ag_4_hr_close = close(period = Ag_4_hr);
def Ag_day = AggregationPeriod.day;
def Ag_day_close = close(period = Ag_day);
def Ag_week = AggregationPeriod.week;
def Ag_week_close = close(period = ag_week);
def Ag_month = AggregationPeriod.month;
def Ag_month_close = close(period = Ag_month);
def Ag_year = AggregationPeriod.year;
def Ag_year_close = close(period = Ag_year);
def bn = barnumber();
script barssince {
input Condition = 0;
def barssince = if Condition then 1 else barssince[1] + 1;
plot return = barssince;
}
###################################################################################################
###################################################################################################
plot fast_Plot_1_minute = MovingAverage(avgtype, Ag_1_min_close, fast);
fast_Plot_1_minute.Hide();
plot slow_Plot_1_minute = MovingAverage(avgtype, Ag_1_min_close, slow);
slow_Plot_1_minute.Hide();
plot fast_Plot_2_minute = MovingAverage(avgtype, Ag_2_min_close, fast);
fast_Plot_2_minute.Hide();
plot slow_Plot_2_minute = MovingAverage(avgtype, Ag_2_min_close, slow);
slow_Plot_2_minute.Hide();
plot fast_Plot_5_minute = MovingAverage(avgtype, Ag_5_min_close, fast);
fast_Plot_5_minute.Hide();
plot slow_Plot_5_minute = MovingAverage(avgtype, Ag_5_min_close, slow);
slow_Plot_5_minute.Hide();
plot fast_Plot_10_minute = MovingAverage(avgtype, Ag_10_min_close, fast);
fast_Plot_10_minute.Hide();
plot slow_Plot_10_minute = MovingAverage(avgtype, Ag_10_min_close, slow);
slow_Plot_10_minute.Hide();
plot fast_Plot_15_minute = MovingAverage(avgtype, Ag_15_min_close, fast);
fast_Plot_15_minute.Hide();
plot slow_Plot_15_minute = MovingAverage(avgtype, Ag_15_min_close, slow);
slow_Plot_15_minute.Hide();
plot fast_Plot_30_minute = MovingAverage(avgtype, Ag_30_min_close, fast);
fast_Plot_30_minute.Hide();
plot slow_Plot_30_minute = MovingAverage(avgtype, Ag_30_min_close, slow);
slow_Plot_30_minute.Hide();
plot fast_Plot_1_hr = MovingAverage(avgtype, Ag_1hr_close, fast);
fast_Plot_1_hr.Hide();
plot slow_Plot_1_hr = MovingAverage(avgtype, Ag_1hr_close, slow);
slow_Plot_1_hr.Hide();
plot fast_Plot_2_hr = MovingAverage(avgtype, Ag_2_hr_close, fast);
fast_Plot_2_hr.Hide();
plot slow_Plot_2_hr = MovingAverage(avgtype, Ag_2_hr_close, slow);
slow_Plot_2_hr.Hide();
plot fast_Plot_4_hr = MovingAverage(avgtype, Ag_4_hr_close, fast);
fast_Plot_4_hr.Hide();
plot slow_Plot_4_hr = MovingAverage(avgtype, Ag_4_hr_close, slow);
slow_Plot_4_hr.Hide();
plot fast_Plot_day = MovingAverage(avgtype, Ag_day, fast);
fast_Plot_day.Hide();
plot slow_Plot_day = MovingAverage(avgtype, Ag_day, slow);
slow_Plot_day.Hide();
plot fast_Plot_week = MovingAverage(avgtype, ag_week, fast);
fast_Plot_week .Hide();
plot slow_Plot_week = MovingAverage(avgtype, ag_week, slow);
slow_Plot_week.Hide();
plot fast_Plot_month = MovingAverage(avgtype, Ag_month, fast);
fast_Plot_month.Hide();
plot slow_Plot_month = MovingAverage(avgtype, Ag_month, slow);
slow_Plot_month.Hide();
plot fast_Plot_year = MovingAverage(avgtype, Ag_year, fast);
fast_Plot_year.Hide();
plot slow_Plot_year = MovingAverage(avgtype, Ag_year, slow);
slow_Plot_year.Hide();
#fast_Plot_1_minute.setdefaultcolor(color.light_green);
#slow_Plot_1_minute.setdefaultcolor(color.red);
assignpricecolor(if color_bars then (if fast_Plot_1_minute>=slow_Plot_1_minute then color.green else color.red) else color.current);
def crossup_1m = fast_Plot_1_minute crosses above slow_Plot_1_minute;
def crossdn_1m = fast_Plot_1_minute crosses below slow_Plot_1_minute;
def crossup_2m = fast_Plot_2_minute crosses above slow_Plot_2_minute;
def crossdn_2m = fast_Plot_2_minute crosses below slow_Plot_2_minute;
def crossup_5m = fast_Plot_5_minute crosses above slow_Plot_5_minute;
def crossdn_5m = fast_Plot_5_minute crosses below slow_Plot_5_minute;
def crossup_10m = fast_Plot_10_minute crosses above slow_Plot_10_minute;
def crossdn_10m = fast_Plot_10_minute crosses below slow_Plot_10_minute;
def crossup_15m = fast_Plot_15_minute crosses above slow_Plot_15_minute;
def crossdn_15m = fast_Plot_15_minute crosses below slow_Plot_15_minute;
def crossup_30m = fast_Plot_30_minute crosses above slow_Plot_30_minute;
def crossdn_30m = fast_Plot_30_minute crosses below slow_Plot_30_minute;
def crossup_1hr = fast_Plot_1_hr crosses above slow_Plot_1_hr;
def crossdn_1hr = fast_Plot_1_hr crosses below slow_Plot_1_hr;
def crossup_2hr = fast_Plot_2_hr crosses above slow_Plot_2_hr;
def crossdn_2hr = fast_Plot_2_hr crosses below slow_Plot_2_hr;
def crossup_4hr = fast_Plot_4_hr crosses above slow_Plot_4_hr;
def crossdn_4hr = fast_Plot_4_hr crosses below slow_Plot_4_hr;
def crossup_1day = fast_Plot_day crosses above slow_Plot_day;
def crossdn_1day = fast_Plot_day crosses below slow_Plot_day;
def crossup_1week = fast_Plot_week crosses above slow_Plot_week;
def crossdn_1week = fast_Plot_week crosses below slow_Plot_week;
def crossup_1month = fast_Plot_month crosses above slow_Plot_month;
def crossdn_1month = fast_Plot_month crosses below slow_Plot_month;
def crossup_1year = fast_Plot_year crosses above slow_Plot_year;
def crossdn_1year = fast_Plot_year crosses below slow_Plot_1_minute;
#def uplabel= if show_bubbles and crossup then slow_Plot_1_minute else double.nan;
#def dnlabel = if show_bubbles and crossdn then slow_Plot_1_minute else double.nan;
#plot up = show_arrows and crossup;
#plot dn = show_arrows and crossdn;
#up.Hide();
#dn.Hide();
#up.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
#dn.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
#up.setdefaultcolor(color.light_green);
#dn.setdefaultcolor(color.white);
AddLabel(one_minute_label, "1 minute", Color.orange);
addlabel(one_minute_label, if fast_Plot_1_minute>=slow_Plot_1_minute then "Golden Cross " + barssince(crossup_1m) + " bars ago" else if fast_Plot_1_minute<slow_Plot_1_minute then "Death Cross " + barssince(crossdn_1m) + " bars ago" else "", if fast_Plot_1_minute>=slow_Plot_1_minute then color.green else if fast_Plot_1_minute<slow_Plot_1_minute then color.white else color.gray);
AddLabel(two_minute_label, "2 minute", Color.orange);
addlabel(two_minute_label , if fast_Plot_2_minute>=slow_Plot_2_minute then "Golden Cross " + barssince(crossup_2m) + " bars ago" else if fast_Plot_2_minute<slow_Plot_2_minute then "Death Cross " + barssince(crossdn_2m) + " bars ago" else "", if fast_Plot_2_minute>=slow_Plot_2_minute then color.green else if fast_Plot_2_minute<slow_Plot_2_minute then color.white else color.gray);
AddLabel(five_minute_label, "5 minute", Color.orange);
addlabel(five_minute_label, if fast_Plot_5_minute>=slow_Plot_5_minute then "Golden Cross " + barssince(crossup_5m) + " bars ago" else if fast_Plot_5_minute<slow_Plot_5_minute then "Death Cross " + barssince(crossdn_5m) + " bars ago" else "", if fast_Plot_5_minute>=slow_Plot_5_minute then color.green else if fast_Plot_5_minute<slow_Plot_5_minute then color.white else color.gray);
AddLabel(ten_minute_label, "10 minute", Color.orange);
addlabel(ten_minute_label, if fast_Plot_10_minute>=slow_Plot_10_minute then "Golden Cross " + barssince(crossup_10m) + " bars ago" else if fast_Plot_10_minute<slow_Plot_10_minute then "Death Cross " + barssince(crossdn_10m) + " bars ago" else "", if fast_Plot_10_minute>=slow_Plot_10_minute then color.green else if fast_Plot_10_minute<slow_Plot_10_minute then color.white else color.gray);
AddLabel(fifteen_minute_label, "15 minute", Color.orange);
addlabel(fifteen_minute_label, if fast_Plot_15_minute>=slow_Plot_15_minute then "Golden Cross " + barssince(crossup_15m) + " bars ago" else if fast_Plot_15_minute<slow_Plot_15_minute then "Death Cross " + barssince(crossdn_15m) + " bars ago" else "", if fast_Plot_15_minute>=slow_Plot_15_minute then color.green else if fast_Plot_15_minute<slow_Plot_15_minute then color.white else color.gray);
AddLabel(thirty_minute_label, "30 minute", Color.orange);
addlabel(thirty_minute_label, if fast_Plot_30_minute>=slow_Plot_30_minute then "Golden Cross " + barssince(crossup_30m) + " bars ago" else if fast_Plot_30_minute<slow_Plot_30_minute then "Death Cross " + barssince(crossdn_30m) + " bars ago" else "", if fast_Plot_30_minute>=slow_Plot_30_minute then color.green else if fast_Plot_30_minute<slow_Plot_30_minute then color.white else color.gray);
AddLabel(one_hour_label, "1 hour", Color.orange);
addlabel(one_hour_label, if fast_Plot_1_hr>=slow_Plot_1_hr then "Golden Cross " + barssince(crossup_1hr) + " bars ago" else if fast_Plot_1_hr<slow_Plot_1_hr then "Death Cross " + barssince(crossdn_1hr) + " bars ago" else "", if fast_Plot_1_hr>=slow_Plot_1_hr then color.green else if fast_Plot_1_hr<slow_Plot_1_hr then color.white else color.gray);
AddLabel(two_hour_label, "2 hour", Color.orange);
addlabel(two_hour_label, if fast_Plot_2_hr>=slow_Plot_2_hr then "Golden Cross " + barssince(crossup_2hr) + " bars ago" else if fast_Plot_2_hr<slow_Plot_2_hr then "Death Cross " + barssince(crossdn_2hr) + " bars ago" else "", if fast_Plot_2_hr>=slow_Plot_2_hr then color.green else if fast_Plot_2_hr<slow_Plot_2_hr then color.white else color.gray);
AddLabel(four_hour_label, "4 hour", Color.orange);
addlabel(four_hour_label, if fast_Plot_4_hr>=slow_Plot_4_hr then "Golden Cross " + barssince(crossup_4hr) + " bars ago" else if fast_Plot_4_hr<slow_Plot_4_hr then "Death Cross " + barssince(crossdn_4hr) + " bars ago" else "", if fast_Plot_4_hr>=slow_Plot_4_hr then color.green else if fast_Plot_4_hr<slow_Plot_4_hr then color.white else color.gray);
AddLabel(one_day_label, "1 day", Color.orange);
addlabel(one_day_label, if fast_Plot_day>=slow_Plot_day then "Golden Cross " + barssince(crossup_1day) + " bars ago" else if fast_Plot_day<slow_Plot_day then "Death Cross " + barssince(crossdn_1day) + " bars ago" else "", if fast_Plot_day>=slow_Plot_day then color.green else if fast_Plot_day<slow_Plot_day then color.white else color.gray);
AddLabel(five_day_label, "1 week", Color.orange);
addlabel(five_day_label, if fast_Plot_week>=slow_Plot_week then "Golden Cross " + barssince(crossup_1week) + " bars ago" else if fast_Plot_week<slow_Plot_week then "Death Cross " + barssince(crossdn_1week) + " bars ago" else "", if fast_Plot_week>=slow_Plot_week then color.green else if fast_Plot_week<slow_Plot_week then color.white else color.gray);
AddLabel(one_month_label, "1 month", Color.orange);
addlabel(one_month_label, if fast_Plot_month>=slow_Plot_month then "Golden Cross " + barssince(crossup_1month) + " bars ago" else if fast_Plot_month<slow_Plot_month then "Death Cross " + barssince(crossdn_1month) + " bars ago" else "", if fast_Plot_month>=slow_Plot_month then color.green else if fast_Plot_month<slow_Plot_month then color.white else color.gray);
AddLabel(one_year_label, "1 year", Color.orange);
addlabel(one_year_label, if fast_Plot_year>=slow_Plot_year then "Golden Cross " + barssince(crossup_1year) + " bars ago" else if fast_Plot_year<slow_Plot_year then "Death Cross " + barssince(crossdn_1year) + " bars ago" else "", if fast_Plot_year>=slow_Plot_year then color.green else if fast_Plot_year<slow_Plot_year then color.white else color.gray);