Something I came up with yesterday while I was mad after taking a couple ugly trades. Indicator just shows green/yellow/red if 3 moving averages (default to 8/13/21) are stacked. Green if stacked trending bullish. Red if stacked trending bearish. Yellow if they aren't stacked/no trend. Perfect for someone trading on a low time frame while wanting to keep an eye on the overall trend. The pictures are this week's /ES chart 5 minute with the 10 minute trend. I put pictures up for both on the chart and as a lower indicator. Edited to clean up the code a bit.
Code:
# Multi-Timeframe ElvisTrend
# Copyright (C) 2023 darkelvis twitter.com/TheOGdarkelvis
# Indicator uses a set of stacked moving averages to identify trend. Stacked low to high *should* indicate an uptrend, stacked high to low *should* indicate a downtrend, when moving averages are not stacked there is no trend. Green indicates bullish, red for bearish, and yellow for no trend.
declare lower;
##Settings
input AvgType = averageType.EXPONENTIAL;
input Fast_MA = 8;
input Mid_MA = 13;
input Slow_MA = 21;
input Show_Labels = yes;
input Timeframe = aggregationPeriod.HOUR;
##Calculations
def price = close;
def FastValue = MovingAverage(AvgType, close(period=Timeframe),Fast_MA);
def MidValue = MovingAverage(AvgType, close(period=Timeframe), Mid_MA);
def SlowValue = MovingAverage(AvgType, close(period=Timeframe), Slow_MA);
def bullish = FastValue >= MidValue AND MidValue >= SlowValue;
def bearish = FastValue <= MidValue AND MidValue <= SlowValue;
def no_trend = FastValue >= MidValue and MidValue <= SlowValue or FastValue <= MidValue and MidValue >= SlowValue;
##Label
AddLabel(Show_Labels, If bullish then "LONG ONLY" else "", if bullish then color.green else color.black);
AddLabel(Show_Labels, If bearish then "SHORT ONLY" else "", if bearish then color.red else color.black);
AddLabel(Show_Labels, If no_trend then "SIT ON YOUR HANDS" else "", if no_trend then color.yellow else color.black);
##Background cloud
AddCloud(if bullish then Double.POSITIVE_INFINITY else Double.NaN,if bullish then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN);
AddCloud(if bearish then Double.POSITIVE_INFINITY else Double.NaN,if bearish then Double.NEGATIVE_INFINITY else Double.NaN, Color.PINK);
AddCloud(if no_trend then Double.POSITIVE_INFINITY else Double.NaN,if no_trend then Double.NEGATIVE_INFINITY else Double.NaN, Color.YELLOW);
Last edited: