Help color coding different time frames EMA's on watchlist tab.

DGreenleaf17

New member
VIP
Sorry for the confusing title, but essentially, I'm curious, i have a script for color coded stacked EMA's, 8 though 135 and if its positively stacked it goes green, negative is red and black is neutral. I was curious if anyone knows how if per example, the 5m, 15m, 30m, 1hr, 2hr, 4hr are all stacked positively, it would be green and so on, so that way i can only have 1 tab for all time frames under the watchlist, instead of 1 per time frame. I tried finding how to code it myself, i just don't know how to add time frames within the code itself.

This is the code i have at the moment.


Code:
def EMA8 = ExpAverage(close, 8);
def EMA13 = ExpAverage(close, 13);
def EMA21 = ExpAverage(close, 21);
def EMA34 = ExpAverage(close, 34);
def EMA45 = ExpAverage(close, 45);
def EMA90 = ExpAverage(close, 90);
def EMA135 = ExpAverage(close, 135);


def bullish = EMA8 > EMA13 and EMA13 > EMA21 and EMA21 > EMA34 and EMA34 > EMA45 and EMA45 > EMA90 and EMA90 > EMA135;
def bearish = EMA8 < EMA13 and EMA13 < EMA21 and EMA21 < EMA34 and EMA34 < EMA45 and EMA45 < EMA90 and EMA90 < EMA135;

AddLabel(bullish, "Bullish Stacked MAs", color.black);
AddLabel(bearish, "Bearish Stacked MAs", color.black);
AddLabel(!bullish and !bearish, " ", color.black);

AssignBackgroundColor(if bullish then color.green else if bearish then color.red else color.black);
 

_Merch_Man_

Member
Hey @DGreenleaf17 - What timeframes are you looking to use? It is a limitation of ToS that you cannot have data from a faster timeframe shown on a slower timeframe, meaning that you can't show a 15 min EMA on a 1-hour chart.

Anyway, you can get the ema from e.g. the hourly chart with the code:

DEF ema8Hourly = MovingAverage(averageType.EXPONENTIAL, close( period = aggregationPeriod.HOUR), 8);

This should give you the direction you need to accomplish your desired result as I understand it.

-- Matt.
 

Similar threads

Top