MTF / EMA what did i do wrong?

bigguns

New member
can someone look at this and tell me what i did wrong.


## min aggregationPeriod variables
input oneaggregationPeriod = AggregationPeriod.MIN;
def minprice = close(period = AggregationPeriod.MIN);

def minEMA89 = ExpAverage(close, 89);
def minEMA55 = ExpAverage(close, 55);
def minEMA34 = ExpAverage(close, 34);
def minEMA21 = ExpAverage(close, 21);
def minEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def minSP = minEMA8 > minEMA21 and minEMA21 > minEMA34 and minEMA34 > minEMA55 and minEMA55 > minEMA89;
def minSN = minEMA8 < minEMA21 and minEMA21 < minEMA34 and minEMA34 < minEMA55 and minEMA55 < minEMA89;
def minSPW = minEMA8 < minEMA21 and minEMA34 > minEMA55 and minEMA55 > minEMA89;
def minSNW = minEMA8 > minEMA21 and minEMA34 < minEMA55 and minEMA55 < minEMA89;

AddLabel(yes, "1M", if minSP then GlobalColor("StackedPositive") else if minSN then GlobalColor("StackedNegative") else if (minSPW or minSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## two aggregationPeriod variables

input twoaggregationPeriod = AggregationPeriod.TWO_MIN;
def twoprice = close(period = AggregationPeriod.TWO_MIN);

def twoEMA89 = ExpAverage(close, 89);
def twoEMA55 = ExpAverage(close, 55);
def twoEMA34 = ExpAverage(close, 34);
def twoEMA21 = ExpAverage(close, 21);
def twoEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def twoSP = twoEMA8 > twoEMA21 and twoEMA21 > twoEMA34 and twoEMA34 > twoEMA55 and twoEMA55 > twoEMA89;
def twoSN = twoEMA8 < twoEMA21 and twoEMA21 < twoEMA34 and twoEMA34 < twoEMA55 and twoEMA55 < twoEMA89;
def twoSPW = twoEMA8 < twoEMA21 and twoEMA34 > twoEMA55 and twoEMA55 > twoEMA89;
def twoSNW = twoEMA8 > twoEMA21 and twoEMA34 < twoEMA55 and twoEMA55 < twoEMA89;

AddLabel(yes, "2M", if twoSP then GlobalColor("StackedPositive") else if twoSN then GlobalColor("StackedNegative") else if (twoSPW or twoSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## three aggregationPeriod variables

input threeaggregationPeriod = AggregationPeriod.THREE_MIN;
def threeprice = close(period = AggregationPeriod.THREE_MIN);

def threeEMA89 = ExpAverage(close, 89);
def threeEMA55 = ExpAverage(close, 55);
def threeEMA34 = ExpAverage(close, 34);
def threeEMA21 = ExpAverage(close, 21);
def threeEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def threeSP = threeEMA8 > threeEMA21 and threeEMA21 > threeEMA34 and threeEMA34 > threeEMA55 and threeEMA55 > threeEMA89;
def threeSN = threeEMA8 < threeEMA21 and threeEMA21 < threeEMA34 and threeEMA34 < threeEMA55 and threeEMA55 < threeEMA89;
def threeSPW = threeEMA8 < threeEMA21 and threeEMA34 > threeEMA55 and threeEMA55 > threeEMA89;
def threeSNW = threeEMA8 > threeEMA21 and threeEMA34 < threeEMA55 and threeEMA55 < threeEMA89;

AddLabel(yes, "3M", if threeSP then GlobalColor("StackedPositive") else if threeSN then GlobalColor("StackedNegative") else if (threeSPW or threeSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));


## five aggregationPeriod variables
input fiveaggregationPeriod = AggregationPeriod.FIVE_MIN;
def fiveprice = close(period = AggregationPeriod.FIVE_MIN);

def fiveEMA89 = ExpAverage(close, 89);
def fiveEMA55 = ExpAverage(close, 55);
def fiveEMA34 = ExpAverage(close, 34);
def fiveEMA21 = ExpAverage(close, 21);
def fiveEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def fivesP = fiveEMA8 > fiveEMA21 and fiveEMA21 > fiveEMA34 and fiveEMA34 > fiveEMA55 and fiveEMA55 > fiveEMA89;
def fiveSN = fiveEMA8 < fiveEMA21 and fiveEMA21 < fiveEMA34 and fiveEMA34 < fiveEMA55 and fiveEMA55 < fiveEMA89;
def fiveSPW = fiveEMA8 < fiveEMA21 and fiveEMA34 > fiveEMA55 and fiveEMA55 > fiveEMA89;
def fiveSNW = fiveEMA8 > threeEMA21 and threeEMA34 < threeEMA55 and fiveEMA55 < fiveEMA89;

AddLabel(yes, "5M", if fiveSP then GlobalColor("StackedPositive") else if fiveSN then GlobalColor("StackedNegative") else if (fiveSPW or fiveSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## ten aggregationPeriod variables

input tenaggregationPeriod = AggregationPeriod.TEN_MIN;
def tenprice = close(period = AggregationPeriod.TEN_MIN);

def tenEMA89 = ExpAverage(close, 89);
def tenEMA55 = ExpAverage(close, 55);
def tenEMA34 = ExpAverage(close, 34);
def tenEMA21 = ExpAverage(close, 21);
def tenEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def tenSP = tenEMA8 > tenEMA21 and tenEMA21 > tenEMA34 and tenEMA34 > tenEMA55 and tenEMA55 > tenEMA89;
def tenSN = tenEMA8 < tenEMA21 and tenEMA21 < tenEMA34 and tenEMA34 < tenEMA55 and tenEMA55 < tenEMA89;
def tenSPW = tenEMA8 < tenEMA21 and tenEMA34 > tenEMA55 and tenEMA55 > tenEMA89;
def tenSNW = tenEMA8 > tenEMA21 and tenEMA34 < tenEMA55 and tenEMA55 < tenEMA89;

AddLabel(yes, "10M", if tenSP then GlobalColor("StackedPositive") else if tenSN then GlobalColor("StackedNegative") else if (tenSPW or tenSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## fifteen aggregationPeriod variables

input fifteenaggregationPeriod = AggregationPeriod.FIFTEEN_MIN;
def fifteenprice = close(period = AggregationPeriod.fifteen_MIN);

def fifteenEMA89 = ExpAverage(close, 89);
def fifteenEMA55 = ExpAverage(close, 55);
def fifteenEMA34 = ExpAverage(close, 34);
def fifteenEMA21 = ExpAverage(close, 21);
def fifteenEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def fifteenSP = fifteenEMA8 > fifteenEMA21 and fifteenEMA21 > fifteenEMA34 and fifteenEMA34 > fifteenEMA55 and fifteenEMA55 > fifteenEMA89;
def fifteenSN = fifteenEMA8 < fifteenEMA21 and fifteenEMA21 < fifteenEMA34 and fifteenEMA34 < fifteenEMA55 and fifteenEMA55 < fifteenEMA89;
def fifteenSPW = fifteenEMA8 < fifteenEMA21 and fifteenEMA34 > fifteenEMA55 and fifteenEMA55 > fifteenEMA89;
def fifteenSNW = fifteenEMA8 > fifteenEMA21 and fifteenEMA34 < fifteenEMA55 and fifteenEMA55 < fifteenEMA89;

AddLabel(yes, "15M", if fifteenSP then GlobalColor("StackedPositive") else if fifteenSN then GlobalColor("StackedNegative") else if (fifteenSPW or fifteenSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## thirty aggregationPeriod variables

input thirtyaggregationPeriod = AggregationPeriod.THIRTY_MIN;
def thirtyprice = close(period = AggregationPeriod.THIRTY_MIN);

def thirtyEMA89 = ExpAverage(close, 89);
def thirtyEMA55 = ExpAverage(close, 55);
def thirtyEMA34 = ExpAverage(close, 34);
def thirtyEMA21 = ExpAverage(close, 21);
def thirtyEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def thirtySP = thirtyEMA8 > thirtyEMA21 and thirtyEMA21 > thirtyEMA34 and thirtyEMA34 > thirtyEMA55 and thirtyEMA55 > thirtyEMA89;
def thirtySN = thirtyEMA8 < thirtyEMA21 and thirtyEMA21 < thirtyEMA34 and thirtyEMA34 < thirtyEMA55 and thirtyEMA55 < thirtyEMA89;
def thirtySPW = thirtyEMA8 < thirtyEMA21 and thirtyEMA34 > thirtyEMA55 and thirtyEMA55 > thirtyEMA89;
def thirtySNW = thirtyEMA8 > thirtyEMA21 and thirtyEMA34 < thirtyEMA55 and thirtyEMA55 < thirtyEMA89;

AddLabel(yes, "30M", if thirtySP then GlobalColor("StackedPositive") else if thirtySN then GlobalColor("StackedNegative") else if (thirtySPW or thirtySNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## hr aggregationPeriod variables
input hraggregationPeriod = AggregationPeriod.HOUR;
def hrprice = close(period = AggregationPeriod.HOur);

def hrEMA89 = ExpAverage(close, 89);
def hrEMA55 = ExpAverage(close, 55);
def hrEMA34 = ExpAverage(close, 34);
def hrEMA21 = ExpAverage(close, 21);
def hrEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def hrSP = hrEMA8 > hrEMA21 and hrEMA21 > hrEMA34 and hrEMA34 > hrEMA55 and hrEMA55 > hrEMA89;
def hrSN = hrEMA8 < hrEMA21 and hrEMA21 < hrEMA34 and hrEMA34 < hrEMA55 and hrEMA55 < hrEMA89;
def hrSPW = hrEMA8 < hrEMA21 and hrEMA34 > hrEMA55 and hrEMA55 > hrEMA89;
def hrSNW = hrEMA8 > hrEMA21 and hrEMA34 < hrEMA55 and hrEMA55 < hrEMA89;

AddLabel(yes, "1HR", if hrSP then GlobalColor("StackedPositive") else if hrSN then GlobalColor("StackedNegative") else if (hrSPW or hrSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## twoHR aggregationPeriod variables

input twohraggregationPeriod = AggregationPeriod.TWO_HOURS;
def twohrprice = close(period = AggregationPeriod.TWO_HOURS);

def twohrEMA89 = ExpAverage(close, 89);
def twohrEMA55 = ExpAverage(close, 55);
def twohrEMA34 = ExpAverage(close, 34);
def twohrEMA21 = ExpAverage(close, 21);
def twohrEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def twohrSP = twohrEMA8 > twohrEMA21 and twohrEMA21 > twohrEMA34 and twohrEMA34 > twohrEMA55 and twohrEMA55 > twohrEMA89;
def twohrSN = twohrEMA8 < twohrEMA21 and twohrEMA21 < twohrEMA34 and twohrEMA34 < twohrEMA55 and twohrEMA55 < twohrEMA89;
def twohrSPW = twohrEMA8 < twohrEMA21 and twohrEMA34 > twohrEMA55 and twohrEMA55 > twohrEMA89;
def twohrSNW = twohrEMA8 > twohrEMA21 and twohrEMA34 < twohrEMA55 and twohrEMA55 < twohrEMA89;

AddLabel(yes, "2HR", if twohrSP then GlobalColor("StackedPositive") else if twohrSN then GlobalColor("StackedNegative") else if (twohrSPW or twohrSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## fourhr aggregationPeriod variables

input fourhrggregationPeriod = AggregationPeriod.FOUR_HOURS;
def fourhrprice = close(period = AggregationPeriod.FOUR_HOURS);

def fourhrEMA89 = ExpAverage(close, 89);
def fourhrEMA55 = ExpAverage(close, 55);
def fourhrEMA34 = ExpAverage(close, 34);
def fourhrEMA21 = ExpAverage(close, 21);
def fourhrEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def fourhrSP = fourhrEMA8 > fourhrEMA21 and fourhrEMA21 > fourhrEMA34 and fourhrEMA34 > fourhrEMA55 and fourhrEMA55 > fourhrEMA89;
def fourhrSN = fourhrEMA8 < fourhrEMA21 and fourhrEMA21 < fourhrEMA34 and fourhrEMA34 < fourhrEMA55 and fourhrEMA55 < fourhrEMA89;
def fourhrSPW = fourhrEMA8 < fourhrEMA21 and fourhrEMA34 > fourhrEMA55 and fourhrEMA55 > fourhrEMA89;
def fourhrSNW = fourhrEMA8 > fourhrEMA21 and fourhrEMA34 < fourhrEMA55 and fourhrEMA55 < fourhrEMA89;

AddLabel(yes, "4HR", if fourhrSP then GlobalColor("StackedPositive") else if fourhrSN then GlobalColor("StackedNegative") else if (fourhrSPW or fourhrSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));


## day aggregationPeriod variables
input dayaggregationPeriod = AggregationPeriod.DAY;
def dayprice = close(period = AggregationPeriod.DAY);

def dayEMA89 = ExpAverage(close, 89);
def dayEMA55 = ExpAverage(close, 55);
def dayEMA34 = ExpAverage(close, 34);
def dayEMA21 = ExpAverage(close, 21);
def dayEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def daySP = dayEMA8 > dayEMA21 and dayEMA21 > dayEMA34 and dayEMA34 > dayEMA55 and dayEMA55 > dayEMA89;
def daySN = dayEMA8 < dayEMA21 and dayEMA21 < dayEMA34 and dayEMA34 < dayEMA55 and dayEMA55 < dayEMA89;
def daySPW = dayEMA8 < dayEMA21 and dayEMA34 > dayEMA55 and dayEMA55 > dayEMA89;
def daySNW = dayEMA8 > dayEMA21 and dayEMA21 < dayEMA55 and dayEMA55 < dayEMA89;

AddLabel(yes, "DAY", if daySP then GlobalColor("StackedPositive") else if daySN then GlobalColor("StackedNegative") else if (daySPW or daySNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## week aggregationPeriod variables

input weekaggregationPeriod = AggregationPeriod.WEEK;
def weekprice = close(period = AggregationPeriod.WEEK);

def weekEMA89 = ExpAverage(close, 89);
def weekEMA55 = ExpAverage(close, 55);
def weekEMA34 = ExpAverage(close, 34);
def weekEMA21 = ExpAverage(close, 21);
def weekEMA8 = ExpAverage(close, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def weekSP = weekEMA8 > weekEMA21 and weekEMA21 > weekEMA34 and weekEMA34 > weekEMA55 and weekEMA55 > weekEMA89;
def weekSN = weekEMA8 < weekEMA21 and weekEMA21 < weekEMA34 and weekEMA34 < weekEMA55 and weekEMA55 < weekEMA89;
def weekSPW = weekEMA8 < weekEMA21 and weekEMA34 > weekEMA55 and weekEMA55 > weekEMA89;
def weekSNW = weekEMA8 > weekEMA21 and weekEMA34 < weekEMA55 and weekEMA55 < weekEMA89;

AddLabel(yes, "WK", if WEEKSP then GlobalColor("StackedPositive") else if weekSN then GlobalColor("StackedNegative") else if (weekSPW or weekSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));
 
Solution
I got it to work on the one min chart but if i put it on a higher chart it will not work is there something else i can add to the code?

EDIT 10/27.....

studies can't use a 2nd aggregation time less than the chart time.

if the chart time is set to 1 hour, then every bar on the chart will span 1 hour.
there will be only 1 of each of these price functions per each bar, open high, low, close.
TOS doesn't collect and hold price data every minute, only in intervals of the chart time. 5 minute data doesn't exist on a 1 hour chart, so trying to read that data causes errors.


-------------

short answer, set chart time, then set your input times to be the same or bigger. ( if chart = 15min, change 1,2,3,5,10 to be 15)

long...
in each of your definitions for moving averages, you use "CLOSE" rather than the price you've just defined:
Code:
def weekprice = close(period = AggregationPeriod.WEEK);

def weekEMA89 = ExpAverage(close, 89);

if you change that around to this:
Code:
def weekprice = close(period = AggregationPeriod.WEEK);

def weekEMA89 = ExpAverage(weekprice, 89);

it may work more like you thought it should have

-mashume

This was typed here in the text editor. typos are possible.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

in each of your definitions for moving averages, you use "CLOSE" rather than the price you've just defined:
Code:
def weekprice = close(period = AggregationPeriod.WEEK);

def weekEMA89 = ExpAverage(close, 89);

if you change that around to this:
Code:
def weekprice = close(period = AggregationPeriod.WEEK);

def weekEMA89 = ExpAverage(weekprice, 89);

it may work more like you thought it should have

-mashume

This was typed here in the text editor. typos are possible.
tried what you suggested and still is not working I'm getting the bubbles at the top of the screen it is just reading from the timeframe that the chart is in not getting the info from the other timeframe... anymore ideas that i can try?
 
tried what you suggested and still is not working I'm getting the bubbles at the top of the screen it is just reading from the timeframe that the chart is in not getting the info from the other timeframe... anymore ideas that i can try?
Can you repost your current code?
 
## min aggregationPeriod variables
input oneaggregationPeriod = AggregationPeriod.MIN;
def minprice = close(period = AggregationPeriod.MIN);

def minEMA89 = ExpAverage(minprice, 89);
def minEMA55 = ExpAverage(minprice, 55);
def minEMA34 = ExpAverage(minprice, 34);
def minEMA21 = ExpAverage(minprice, 21);
def minEMA8 = ExpAverage(minprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def minSP = minEMA8 > minEMA21 and minEMA21 > minEMA34 and minEMA34 > minEMA55 and minEMA55 > minEMA89;
def minSN = minEMA8 < minEMA21 and minEMA21 < minEMA34 and minEMA34 < minEMA55 and minEMA55 < minEMA89;
def minSPW = minEMA8 < minEMA21 and minEMA34 > minEMA55 and minEMA55 > minEMA89;
def minSNW = minEMA8 > minEMA21 and minEMA34 < minEMA55 and minEMA55 < minEMA89;

AddLabel(yes, "1M", if minSP then GlobalColor("StackedPositive") else if minSN then GlobalColor("StackedNegative") else if (minSPW or minSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## two aggregationPeriod variables

input twoaggregationPeriod = AggregationPeriod.TWO_MIN;
def twoprice = close(period = AggregationPeriod.TWO_MIN);

def twoEMA89 = ExpAverage(twoprice, 89);
def twoEMA55 = ExpAverage(twoprice, 55);
def twoEMA34 = ExpAverage(twoprice, 34);
def twoEMA21 = ExpAverage(twoprice, 21);
def twoEMA8 = ExpAverage(twoprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def twoSP = twoEMA8 > twoEMA21 and twoEMA21 > twoEMA34 and twoEMA34 > twoEMA55 and twoEMA55 > twoEMA89;
def twoSN = twoEMA8 < twoEMA21 and twoEMA21 < twoEMA34 and twoEMA34 < twoEMA55 and twoEMA55 < twoEMA89;
def twoSPW = twoEMA8 < twoEMA21 and twoEMA34 > twoEMA55 and twoEMA55 > twoEMA89;
def twoSNW = twoEMA8 > twoEMA21 and twoEMA34 < twoEMA55 and twoEMA55 < twoEMA89;

AddLabel(yes, "2M", if twoSP then GlobalColor("StackedPositive") else if twoSN then GlobalColor("StackedNegative") else if (twoSPW or twoSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## three aggregationPeriod variables

input threeaggregationPeriod = AggregationPeriod.THREE_MIN;
def threeprice = close(period = AggregationPeriod.THREE_MIN);

def threeEMA89 = ExpAverage(threeprice, 89);
def threeEMA55 = ExpAverage(threeprice, 55);
def threeEMA34 = ExpAverage(threeprice, 34);
def threeEMA21 = ExpAverage(threeprice, 21);
def threeEMA8 = ExpAverage(threeprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def threeSP = threeEMA8 > threeEMA21 and threeEMA21 > threeEMA34 and threeEMA34 > threeEMA55 and threeEMA55 > threeEMA89;
def threeSN = threeEMA8 < threeEMA21 and threeEMA21 < threeEMA34 and threeEMA34 < threeEMA55 and threeEMA55 < threeEMA89;
def threeSPW = threeEMA8 < threeEMA21 and threeEMA34 > threeEMA55 and threeEMA55 > threeEMA89;
def threeSNW = threeEMA8 > threeEMA21 and threeEMA34 < threeEMA55 and threeEMA55 < threeEMA89;

AddLabel(yes, "3M", if threeSP then GlobalColor("StackedPositive") else if threeSN then GlobalColor("StackedNegative") else if (threeSPW or threeSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));


## five aggregationPeriod variables
input fiveaggregationPeriod = AggregationPeriod.FIVE_MIN;
def fiveprice = close(period = AggregationPeriod.FIVE_MIN);

def fiveEMA89 = ExpAverage(fiveprice, 89);
def fiveEMA55 = ExpAverage(fiveprice, 55);
def fiveEMA34 = ExpAverage(fiveprice, 34);
def fiveEMA21 = ExpAverage(fiveprice, 21);
def fiveEMA8 = ExpAverage(fiveprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def fivesP = fiveEMA8 > fiveEMA21 and fiveEMA21 > fiveEMA34 and fiveEMA34 > fiveEMA55 and fiveEMA55 > fiveEMA89;
def fiveSN = fiveEMA8 < fiveEMA21 and fiveEMA21 < fiveEMA34 and fiveEMA34 < fiveEMA55 and fiveEMA55 < fiveEMA89;
def fiveSPW = fiveEMA8 < fiveEMA21 and fiveEMA34 > fiveEMA55 and fiveEMA55 > fiveEMA89;
def fiveSNW = fiveEMA8 > threeEMA21 and threeEMA34 < threeEMA55 and fiveEMA55 < fiveEMA89;

AddLabel(yes, "5M", if fiveSP then GlobalColor("StackedPositive") else if fiveSN then GlobalColor("StackedNegative") else if (fiveSPW or fiveSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## ten aggregationPeriod variables

input tenaggregationPeriod = AggregationPeriod.TEN_MIN;
def tenprice = close(period = AggregationPeriod.TEN_MIN);

def tenEMA89 = ExpAverage(tenprice, 89);
def tenEMA55 = ExpAverage(tenprice, 55);
def tenEMA34 = ExpAverage(tenprice, 34);
def tenEMA21 = ExpAverage(tenprice, 21);
def tenEMA8 = ExpAverage(tenprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def tenSP = tenEMA8 > tenEMA21 and tenEMA21 > tenEMA34 and tenEMA34 > tenEMA55 and tenEMA55 > tenEMA89;
def tenSN = tenEMA8 < tenEMA21 and tenEMA21 < tenEMA34 and tenEMA34 < tenEMA55 and tenEMA55 < tenEMA89;
def tenSPW = tenEMA8 < tenEMA21 and tenEMA34 > tenEMA55 and tenEMA55 > tenEMA89;
def tenSNW = tenEMA8 > tenEMA21 and tenEMA34 < tenEMA55 and tenEMA55 < tenEMA89;

AddLabel(yes, "10M", if tenSP then GlobalColor("StackedPositive") else if tenSN then GlobalColor("StackedNegative") else if (tenSPW or tenSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## fifteen aggregationPeriod variables

input fifteenaggregationPeriod = AggregationPeriod.FIFTEEN_MIN;
def fifteenprice = close(period = AggregationPeriod.fifteen_MIN);

def fifteenEMA89 = ExpAverage(fifteenprice, 89);
def fifteenEMA55 = ExpAverage(fifteenprice, 55);
def fifteenEMA34 = ExpAverage(fifteenprice, 34);
def fifteenEMA21 = ExpAverage(fifteenprice, 21);
def fifteenEMA8 = ExpAverage(fifteenprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def fifteenSP = fifteenEMA8 > fifteenEMA21 and fifteenEMA21 > fifteenEMA34 and fifteenEMA34 > fifteenEMA55 and fifteenEMA55 > fifteenEMA89;
def fifteenSN = fifteenEMA8 < fifteenEMA21 and fifteenEMA21 < fifteenEMA34 and fifteenEMA34 < fifteenEMA55 and fifteenEMA55 < fifteenEMA89;
def fifteenSPW = fifteenEMA8 < fifteenEMA21 and fifteenEMA34 > fifteenEMA55 and fifteenEMA55 > fifteenEMA89;
def fifteenSNW = fifteenEMA8 > fifteenEMA21 and fifteenEMA34 < fifteenEMA55 and fifteenEMA55 < fifteenEMA89;

AddLabel(yes, "15M", if fifteenSP then GlobalColor("StackedPositive") else if fifteenSN then GlobalColor("StackedNegative") else if (fifteenSPW or fifteenSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## thirty aggregationPeriod variables

input thirtyaggregationPeriod = AggregationPeriod.THIRTY_MIN;
def thirtyprice = close(period = AggregationPeriod.THIRTY_MIN);

def thirtyEMA89 = ExpAverage(thirtyprice, 89);
def thirtyEMA55 = ExpAverage(thirtyprice, 55);
def thirtyEMA34 = ExpAverage(thirtyprice, 34);
def thirtyEMA21 = ExpAverage(thirtyprice, 21);
def thirtyEMA8 = ExpAverage(thirtyprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def thirtySP = thirtyEMA8 > thirtyEMA21 and thirtyEMA21 > thirtyEMA34 and thirtyEMA34 > thirtyEMA55 and thirtyEMA55 > thirtyEMA89;
def thirtySN = thirtyEMA8 < thirtyEMA21 and thirtyEMA21 < thirtyEMA34 and thirtyEMA34 < thirtyEMA55 and thirtyEMA55 < thirtyEMA89;
def thirtySPW = thirtyEMA8 < thirtyEMA21 and thirtyEMA34 > thirtyEMA55 and thirtyEMA55 > thirtyEMA89;
def thirtySNW = thirtyEMA8 > thirtyEMA21 and thirtyEMA34 < thirtyEMA55 and thirtyEMA55 < thirtyEMA89;

AddLabel(yes, "30M", if thirtySP then GlobalColor("StackedPositive") else if thirtySN then GlobalColor("StackedNegative") else if (thirtySPW or thirtySNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## hr aggregationPeriod variables
input hraggregationPeriod = AggregationPeriod.HOUR;
def hrprice = close(period = AggregationPeriod.HOur);

def hrEMA89 = ExpAverage(hrprice, 89);
def hrEMA55 = ExpAverage(hrprice, 55);
def hrEMA34 = ExpAverage(hrprice, 34);
def hrEMA21 = ExpAverage(hrprice, 21);
def hrEMA8 = ExpAverage(hrprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def hrSP = hrEMA8 > hrEMA21 and hrEMA21 > hrEMA34 and hrEMA34 > hrEMA55 and hrEMA55 > hrEMA89;
def hrSN = hrEMA8 < hrEMA21 and hrEMA21 < hrEMA34 and hrEMA34 < hrEMA55 and hrEMA55 < hrEMA89;
def hrSPW = hrEMA8 < hrEMA21 and hrEMA34 > hrEMA55 and hrEMA55 > hrEMA89;
def hrSNW = hrEMA8 > hrEMA21 and hrEMA34 < hrEMA55 and hrEMA55 < hrEMA89;

AddLabel(yes, "1HR", if hrSP then GlobalColor("StackedPositive") else if hrSN then GlobalColor("StackedNegative") else if (hrSPW or hrSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## twoHR aggregationPeriod variables

input twohraggregationPeriod = AggregationPeriod.TWO_HOURS;
def twohrprice = close(period = AggregationPeriod.TWO_HOURS);

def twohrEMA89 = ExpAverage(twohrprice, 89);
def twohrEMA55 = ExpAverage(twohrprice, 55);
def twohrEMA34 = ExpAverage(twohrprice, 34);
def twohrEMA21 = ExpAverage(twohrprice, 21);
def twohrEMA8 = ExpAverage(twohrprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def twohrSP = twohrEMA8 > twohrEMA21 and twohrEMA21 > twohrEMA34 and twohrEMA34 > twohrEMA55 and twohrEMA55 > twohrEMA89;
def twohrSN = twohrEMA8 < twohrEMA21 and twohrEMA21 < twohrEMA34 and twohrEMA34 < twohrEMA55 and twohrEMA55 < twohrEMA89;
def twohrSPW = twohrEMA8 < twohrEMA21 and twohrEMA34 > twohrEMA55 and twohrEMA55 > twohrEMA89;
def twohrSNW = twohrEMA8 > twohrEMA21 and twohrEMA34 < twohrEMA55 and twohrEMA55 < twohrEMA89;

AddLabel(yes, "2HR", if twohrSP then GlobalColor("StackedPositive") else if twohrSN then GlobalColor("StackedNegative") else if (twohrSPW or twohrSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## fourhr aggregationPeriod variables

input fourhrggregationPeriod = AggregationPeriod.FOUR_HOURS;
def fourhrprice = close(period = AggregationPeriod.FOUR_HOURS);

def fourhrEMA89 = ExpAverage(fourhrprice, 89);
def fourhrEMA55 = ExpAverage(fourhrprice, 55);
def fourhrEMA34 = ExpAverage(fourhrprice, 34);
def fourhrEMA21 = ExpAverage(fourhrprice, 21);
def fourhrEMA8 = ExpAverage(fourhrprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def fourhrSP = fourhrEMA8 > fourhrEMA21 and fourhrEMA21 > fourhrEMA34 and fourhrEMA34 > fourhrEMA55 and fourhrEMA55 > fourhrEMA89;
def fourhrSN = fourhrEMA8 < fourhrEMA21 and fourhrEMA21 < fourhrEMA34 and fourhrEMA34 < fourhrEMA55 and fourhrEMA55 < fourhrEMA89;
def fourhrSPW = fourhrEMA8 < fourhrEMA21 and fourhrEMA34 > fourhrEMA55 and fourhrEMA55 > fourhrEMA89;
def fourhrSNW = fourhrEMA8 > fourhrEMA21 and fourhrEMA34 < fourhrEMA55 and fourhrEMA55 < fourhrEMA89;

AddLabel(yes, "4HR", if fourhrSP then GlobalColor("StackedPositive") else if fourhrSN then GlobalColor("StackedNegative") else if (fourhrSPW or fourhrSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));


## day aggregationPeriod variables
input dayaggregationPeriod = AggregationPeriod.DAY;
def dayprice = close(period = AggregationPeriod.DAY);

def dayEMA89 = ExpAverage(dayprice, 89);
def dayEMA55 = ExpAverage(dayprice, 55);
def dayEMA34 = ExpAverage(dayprice, 34);
def dayEMA21 = ExpAverage(dayprice, 21);
def dayEMA8 = ExpAverage(dayprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def daySP = dayEMA8 > dayEMA21 and dayEMA21 > dayEMA34 and dayEMA34 > dayEMA55 and dayEMA55 > dayEMA89;
def daySN = dayEMA8 < dayEMA21 and dayEMA21 < dayEMA34 and dayEMA34 < dayEMA55 and dayEMA55 < dayEMA89;
def daySPW = dayEMA8 < dayEMA21 and dayEMA34 > dayEMA55 and dayEMA55 > dayEMA89;
def daySNW = dayEMA8 > dayEMA21 and dayEMA21 < dayEMA55 and dayEMA55 < dayEMA89;

AddLabel(yes, "DAY", if daySP then GlobalColor("StackedPositive") else if daySN then GlobalColor("StackedNegative") else if (daySPW or daySNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## week aggregationPeriod variables

input weekaggregationPeriod = AggregationPeriod.WEEK;
def weekprice = close(period = AggregationPeriod.WEEK);

def weekEMA89 = ExpAverage(weekprice, 89);
def weekEMA55 = ExpAverage(weekprice, 55);
def weekEMA34 = ExpAverage(weekprice, 34);
def weekEMA21 = ExpAverage(weekprice, 21);
def weekEMA8 = ExpAverage(weekprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def weekSP = weekEMA8 > weekEMA21 and weekEMA21 > weekEMA34 and weekEMA34 > weekEMA55 and weekEMA55 > weekEMA89;
def weekSN = weekEMA8 < weekEMA21 and weekEMA21 < weekEMA34 and weekEMA34 < weekEMA55 and weekEMA55 < weekEMA89;
def weekSPW = weekEMA8 < weekEMA21 and weekEMA34 > weekEMA55 and weekEMA55 > weekEMA89;
def weekSNW = weekEMA8 > weekEMA21 and weekEMA34 < weekEMA55 and weekEMA55 < weekEMA89;

AddLabel(yes, "WK", if WEEKSP then GlobalColor("StackedPositive") else if weekSN then GlobalColor("StackedNegative") else if (weekSPW or weekSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));
 
I got it to work on the one min chart but if i put it on a higher chart it will not work is there something else i can add to the code?

EDIT 10/27.....

studies can't use a 2nd aggregation time less than the chart time.

if the chart time is set to 1 hour, then every bar on the chart will span 1 hour.
there will be only 1 of each of these price functions per each bar, open high, low, close.
TOS doesn't collect and hold price data every minute, only in intervals of the chart time. 5 minute data doesn't exist on a 1 hour chart, so trying to read that data causes errors.


-------------

short answer, set chart time, then set your input times to be the same or bigger. ( if chart = 15min, change 1,2,3,5,10 to be 15)

long answer, add if then for each agg time, to compare chart agg to input agg and set a valid agg price or nan.

--------
 
Last edited:
Solution
studies can't use a 2nd aggregation time less than the chart time.

short answer, set chart time, then set your input times to be the same or bigger. ( if chart = 15min, change 1,2,3,5,10 to be 15)

long answer, add if then for each agg time, to compare chart agg to input agg and set a valid agg price or nan.
to be honest i don't understand first time writing code for here could you post an example for me please
 
to be honest i don't understand first time writing code for here could you post an example for me please

This is one way to have your code work for all chart timeframes. I have made adjustments through the 30min agg. I have left the rest for you to try to fix.

Here is what your code looked like for 'min'. Delete this code for aggs that I have not fixed
Code:
def minEMA89 = ExpAverage(minprice, 89);
def minEMA55 = ExpAverage(minprice, 55);
def minEMA34 = ExpAverage(minprice, 34);
def minEMA21 = ExpAverage(minprice, 21);
def minEMA8 = ExpAverage(minprice, 8);

Here is the adjustment needed: Replace it with this code for those aggs that I have not fixed
Code:
def minema89;
def minema55;
def minema34;
def minema21;
def minema8;
if GetAggregationPeriod() <= AggregationPeriod.MIN {
    minema89 = ExpAverage(minprice, 89);
    minema55 = ExpAverage(minprice, 55);
    minema34 = ExpAverage(minprice, 34);
    minema21 = ExpAverage(minprice, 21);
    minema8  = ExpAverage(minprice, 8);
} else {
    minema89 = Double.NaN;
    minema55 = Double.NaN;
    minema34 = Double.NaN;
    minema21 = Double.NaN;
    minema8  = Double.NaN;
}

Here is the code that needs fixed that have done through 30min agg
Screenshot-2022-10-27-082338.png

Ruby:
## min aggregationPeriod variables
input oneaggregationPeriod = AggregationPeriod.MIN;
def minprice = close(period = AggregationPeriod.MIN);

def minema89;
def minema55;
def minema34;
def minema21;
def minema8;
if GetAggregationPeriod() <= AggregationPeriod.MIN {
    minema89 = ExpAverage(minprice, 89);
    minema55 = ExpAverage(minprice, 55);
    minema34 = ExpAverage(minprice, 34);
    minema21 = ExpAverage(minprice, 21);
    minema8  = ExpAverage(minprice, 8);
} else {
    minema89 = Double.NaN;
    minema55 = Double.NaN;
    minema34 = Double.NaN;
    minema21 = Double.NaN;
    minema8  = Double.NaN;
}


DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def minSP = minEMA8 > minEMA21 and minEMA21 > minEMA34 and minEMA34 > minEMA55 and minEMA55 > minEMA89;
def minSN = minEMA8 < minEMA21 and minEMA21 < minEMA34 and minEMA34 < minEMA55 and minEMA55 < minEMA89;
def minSPW = minEMA8 < minEMA21 and minEMA34 > minEMA55 and minEMA55 > minEMA89;
def minSNW = minEMA8 > minEMA21 and minEMA34 < minEMA55 and minEMA55 < minEMA89;

AddLabel(yes, "1M", if minSP then GlobalColor("StackedPositive") else if minSN then GlobalColor("StackedNegative") else if (minSPW or minSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## two aggregationPeriod variables

input twoaggregationPeriod = AggregationPeriod.TWO_MIN;
def twoprice = close(period = AggregationPeriod.TWO_MIN);
def twoema89;
def twoema55;
def twoema34;
def twoema21;
def twoema8;
if GetAggregationPeriod() <= AggregationPeriod.two_MIN {
    twoema89 = ExpAverage(twoprice, 89);
    twoema55 = ExpAverage(twoprice, 55);
    twoema34 = ExpAverage(twoprice, 34);
    twoema21 = ExpAverage(twoprice, 21);
    twoema8  = ExpAverage(twoprice, 8);
} else {
    twoema89 = Double.NaN;
    twoema55 = Double.NaN;
    twoema34 = Double.NaN;
    twoema21 = Double.NaN;
    twoema8  = Double.NaN;
}

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def twoSP = twoEMA8 > twoEMA21 and twoEMA21 > twoEMA34 and twoEMA34 > twoEMA55 and twoEMA55 > twoEMA89;
def twoSN = twoEMA8 < twoEMA21 and twoEMA21 < twoEMA34 and twoEMA34 < twoEMA55 and twoEMA55 < twoEMA89;
def twoSPW = twoEMA8 < twoEMA21 and twoEMA34 > twoEMA55 and twoEMA55 > twoEMA89;
def twoSNW = twoEMA8 > twoEMA21 and twoEMA34 < twoEMA55 and twoEMA55 < twoEMA89;

AddLabel(yes, "2M", if twoSP then GlobalColor("StackedPositive") else if twoSN then GlobalColor("StackedNegative") else if (twoSPW or twoSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## three aggregationPeriod variables

input threeaggregationPeriod = AggregationPeriod.THREE_MIN;
def threeprice = close(period = AggregationPeriod.THREE_MIN);

def threeema89;
def threeema55;
def threeema34;
def threeema21;
def threeema8;
if GetAggregationPeriod() <= AggregationPeriod.three_MIN {
    threeema89 = ExpAverage(threeprice, 89);
    threeema55 = ExpAverage(threeprice, 55);
    threeema34 = ExpAverage(threeprice, 34);
    threeema21 = ExpAverage(threeprice, 21);
    threeema8  = ExpAverage(threeprice, 8);
} else {
    threeema89 = Double.NaN;
    threeema55 = Double.NaN;
    threeema34 = Double.NaN;
    threeema21 = Double.NaN;
    threeema8  = Double.NaN;
}


DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def threeSP = threeEMA8 > threeEMA21 and threeEMA21 > threeEMA34 and threeEMA34 > threeEMA55 and threeEMA55 > threeEMA89;
def threeSN = threeEMA8 < threeEMA21 and threeEMA21 < threeEMA34 and threeEMA34 < threeEMA55 and threeEMA55 < threeEMA89;
def threeSPW = threeEMA8 < threeEMA21 and threeEMA34 > threeEMA55 and threeEMA55 > threeEMA89;
def threeSNW = threeEMA8 > threeEMA21 and threeEMA34 < threeEMA55 and threeEMA55 < threeEMA89;

AddLabel(yes, "3M", if threeSP then GlobalColor("StackedPositive") else if threeSN then GlobalColor("StackedNegative") else if (threeSPW or threeSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));


## five aggregationPeriod variables
input fiveaggregationPeriod = AggregationPeriod.FIVE_MIN;
def fiveprice = close(period = AggregationPeriod.FIVE_MIN);

def fiveema89;
def fiveema55;
def fiveema34;
def fiveema21;
def fiveema8;
if GetAggregationPeriod() <= AggregationPeriod.five_MIN {
    fiveema89 = ExpAverage(fiveprice, 89);
    fiveema55 = ExpAverage(fiveprice, 55);
    fiveema34 = ExpAverage(fiveprice, 34);
    fiveema21 = ExpAverage(fiveprice, 21);
    fiveema8  = ExpAverage(fiveprice, 8);
} else {
    fiveema89 = Double.NaN;
    fiveema55 = Double.NaN;
    fiveema34 = Double.NaN;
    fiveema21 = Double.NaN;
    fiveema8  = Double.NaN;
}


DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def fivesP = fiveEMA8 > fiveEMA21 and fiveEMA21 > fiveEMA34 and fiveEMA34 > fiveEMA55 and fiveEMA55 > fiveEMA89;
def fiveSN = fiveEMA8 < fiveEMA21 and fiveEMA21 < fiveEMA34 and fiveEMA34 < fiveEMA55 and fiveEMA55 < fiveEMA89;
def fiveSPW = fiveEMA8 < fiveEMA21 and fiveEMA34 > fiveEMA55 and fiveEMA55 > fiveEMA89;
def fiveSNW = fiveEMA8 > threeEMA21 and threeEMA34 < threeEMA55 and fiveEMA55 < fiveEMA89;

AddLabel(yes, "5M", if fiveSP then GlobalColor("StackedPositive") else if fiveSN then GlobalColor("StackedNegative") else if (fiveSPW or fiveSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## ten aggregationPeriod variables

input tenaggregationPeriod = AggregationPeriod.TEN_MIN;
def tenprice = close(period = AggregationPeriod.TEN_MIN);

def tenema89;
def tenema55;
def tenema34;
def tenema21;
def tenema8;
if GetAggregationPeriod() <= AggregationPeriod.ten_MIN {
    tenema89 = ExpAverage(tenprice, 89);
    tenema55 = ExpAverage(tenprice, 55);
    tenema34 = ExpAverage(tenprice, 34);
    tenema21 = ExpAverage(tenprice, 21);
    tenema8  = ExpAverage(tenprice, 8);
} else {
    tenema89 = Double.NaN;
    tenema55 = Double.NaN;
    tenema34 = Double.NaN;
    tenema21 = Double.NaN;
    tenema8  = Double.NaN;
}


DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def tenSP = tenEMA8 > tenEMA21 and tenEMA21 > tenEMA34 and tenEMA34 > tenEMA55 and tenEMA55 > tenEMA89;
def tenSN = tenEMA8 < tenEMA21 and tenEMA21 < tenEMA34 and tenEMA34 < tenEMA55 and tenEMA55 < tenEMA89;
def tenSPW = tenEMA8 < tenEMA21 and tenEMA34 > tenEMA55 and tenEMA55 > tenEMA89;
def tenSNW = tenEMA8 > tenEMA21 and tenEMA34 < tenEMA55 and tenEMA55 < tenEMA89;

AddLabel(yes, "10M", if tenSP then GlobalColor("StackedPositive") else if tenSN then GlobalColor("StackedNegative") else if (tenSPW or tenSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## fifteen aggregationPeriod variables

input fifteenaggregationPeriod = AggregationPeriod.FIFTEEN_MIN;
def fifteenprice = close(period = AggregationPeriod.fifteen_MIN);

def fifteenema89;
def fifteenema55;
def fifteenema34;
def fifteenema21;
def fifteenema8;
if GetAggregationPeriod() <= AggregationPeriod.fifteen_MIN {
    fifteenema89 = ExpAverage(fifteenprice, 89);
    fifteenema55 = ExpAverage(fifteenprice, 55);
    fifteenema34 = ExpAverage(fifteenprice, 34);
    fifteenema21 = ExpAverage(fifteenprice, 21);
    fifteenema8  = ExpAverage(fifteenprice, 8);
} else {
    fifteenema89 = Double.NaN;
    fifteenema55 = Double.NaN;
    fifteenema34 = Double.NaN;
    fifteenema21 = Double.NaN;
    fifteenema8  = Double.NaN;
}

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def fifteenSP = fifteenEMA8 > fifteenEMA21 and fifteenEMA21 > fifteenEMA34 and fifteenEMA34 > fifteenEMA55 and fifteenEMA55 > fifteenEMA89;
def fifteenSN = fifteenEMA8 < fifteenEMA21 and fifteenEMA21 < fifteenEMA34 and fifteenEMA34 < fifteenEMA55 and fifteenEMA55 < fifteenEMA89;
def fifteenSPW = fifteenEMA8 < fifteenEMA21 and fifteenEMA34 > fifteenEMA55 and fifteenEMA55 > fifteenEMA89;
def fifteenSNW = fifteenEMA8 > fifteenEMA21 and fifteenEMA34 < fifteenEMA55 and fifteenEMA55 < fifteenEMA89;

AddLabel(yes, "15M", if fifteenSP then GlobalColor("StackedPositive") else if fifteenSN then GlobalColor("StackedNegative") else if (fifteenSPW or fifteenSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## thirty aggregationPeriod variables

input thirtyaggregationPeriod = AggregationPeriod.THIRTY_MIN;
def thirtyprice = close(period = AggregationPeriod.THIRTY_MIN);

def thirtyema89;
def thirtyema55;
def thirtyema34;
def thirtyema21;
def thirtyema8;
if GetAggregationPeriod() <= AggregationPeriod.thirty_MIN {
    thirtyema89 = ExpAverage(thirtyprice, 89);
    thirtyema55 = ExpAverage(thirtyprice, 55);
    thirtyema34 = ExpAverage(thirtyprice, 34);
    thirtyema21 = ExpAverage(thirtyprice, 21);
    thirtyema8  = ExpAverage(thirtyprice, 8);
} else {
    thirtyema89 = Double.NaN;
    thirtyema55 = Double.NaN;
    thirtyema34 = Double.NaN;
    thirtyema21 = Double.NaN;
    thirtyema8  = Double.NaN;
}

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def thirtySP = thirtyEMA8 > thirtyEMA21 and thirtyEMA21 > thirtyEMA34 and thirtyEMA34 > thirtyEMA55 and thirtyEMA55 > thirtyEMA89;
def thirtySN = thirtyEMA8 < thirtyEMA21 and thirtyEMA21 < thirtyEMA34 and thirtyEMA34 < thirtyEMA55 and thirtyEMA55 < thirtyEMA89;
def thirtySPW = thirtyEMA8 < thirtyEMA21 and thirtyEMA34 > thirtyEMA55 and thirtyEMA55 > thirtyEMA89;
def thirtySNW = thirtyEMA8 > thirtyEMA21 and thirtyEMA34 < thirtyEMA55 and thirtyEMA55 < thirtyEMA89;

AddLabel(yes, "30M", if thirtySP then GlobalColor("StackedPositive") else if thirtySN then GlobalColor("StackedNegative") else if (thirtySPW or thirtySNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## hr aggregationPeriod variables
input hraggregationPeriod = AggregationPeriod.HOUR;
def hrprice = close(period = AggregationPeriod.HOur);

def hrEMA89 = ExpAverage(hrprice, 89);
def hrEMA55 = ExpAverage(hrprice, 55);
def hrEMA34 = ExpAverage(hrprice, 34);
def hrEMA21 = ExpAverage(hrprice, 21);
def hrEMA8 = ExpAverage(hrprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def hrSP = hrEMA8 > hrEMA21 and hrEMA21 > hrEMA34 and hrEMA34 > hrEMA55 and hrEMA55 > hrEMA89;
def hrSN = hrEMA8 < hrEMA21 and hrEMA21 < hrEMA34 and hrEMA34 < hrEMA55 and hrEMA55 < hrEMA89;
def hrSPW = hrEMA8 < hrEMA21 and hrEMA34 > hrEMA55 and hrEMA55 > hrEMA89;
def hrSNW = hrEMA8 > hrEMA21 and hrEMA34 < hrEMA55 and hrEMA55 < hrEMA89;

AddLabel(yes, "1HR", if hrSP then GlobalColor("StackedPositive") else if hrSN then GlobalColor("StackedNegative") else if (hrSPW or hrSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## twoHR aggregationPeriod variables

input twohraggregationPeriod = AggregationPeriod.TWO_HOURS;
def twohrprice = close(period = AggregationPeriod.TWO_HOURS);

def twohrEMA89 = ExpAverage(twohrprice, 89);
def twohrEMA55 = ExpAverage(twohrprice, 55);
def twohrEMA34 = ExpAverage(twohrprice, 34);
def twohrEMA21 = ExpAverage(twohrprice, 21);
def twohrEMA8 = ExpAverage(twohrprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def twohrSP = twohrEMA8 > twohrEMA21 and twohrEMA21 > twohrEMA34 and twohrEMA34 > twohrEMA55 and twohrEMA55 > twohrEMA89;
def twohrSN = twohrEMA8 < twohrEMA21 and twohrEMA21 < twohrEMA34 and twohrEMA34 < twohrEMA55 and twohrEMA55 < twohrEMA89;
def twohrSPW = twohrEMA8 < twohrEMA21 and twohrEMA34 > twohrEMA55 and twohrEMA55 > twohrEMA89;
def twohrSNW = twohrEMA8 > twohrEMA21 and twohrEMA34 < twohrEMA55 and twohrEMA55 < twohrEMA89;

AddLabel(yes, "2HR", if twohrSP then GlobalColor("StackedPositive") else if twohrSN then GlobalColor("StackedNegative") else if (twohrSPW or twohrSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## fourhr aggregationPeriod variables

input fourhrggregationPeriod = AggregationPeriod.FOUR_HOURS;
def fourhrprice = close(period = AggregationPeriod.FOUR_HOURS);

def fourhrEMA89 = ExpAverage(fourhrprice, 89);
def fourhrEMA55 = ExpAverage(fourhrprice, 55);
def fourhrEMA34 = ExpAverage(fourhrprice, 34);
def fourhrEMA21 = ExpAverage(fourhrprice, 21);
def fourhrEMA8 = ExpAverage(fourhrprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def fourhrSP = fourhrEMA8 > fourhrEMA21 and fourhrEMA21 > fourhrEMA34 and fourhrEMA34 > fourhrEMA55 and fourhrEMA55 > fourhrEMA89;
def fourhrSN = fourhrEMA8 < fourhrEMA21 and fourhrEMA21 < fourhrEMA34 and fourhrEMA34 < fourhrEMA55 and fourhrEMA55 < fourhrEMA89;
def fourhrSPW = fourhrEMA8 < fourhrEMA21 and fourhrEMA34 > fourhrEMA55 and fourhrEMA55 > fourhrEMA89;
def fourhrSNW = fourhrEMA8 > fourhrEMA21 and fourhrEMA34 < fourhrEMA55 and fourhrEMA55 < fourhrEMA89;

AddLabel(yes, "4HR", if fourhrSP then GlobalColor("StackedPositive") else if fourhrSN then GlobalColor("StackedNegative") else if (fourhrSPW or fourhrSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));


## day aggregationPeriod variables
input dayaggregationPeriod = AggregationPeriod.DAY;
def dayprice = close(period = AggregationPeriod.DAY);

def dayEMA89 = ExpAverage(dayprice, 89);
def dayEMA55 = ExpAverage(dayprice, 55);
def dayEMA34 = ExpAverage(dayprice, 34);
def dayEMA21 = ExpAverage(dayprice, 21);
def dayEMA8 = ExpAverage(dayprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def daySP = dayEMA8 > dayEMA21 and dayEMA21 > dayEMA34 and dayEMA34 > dayEMA55 and dayEMA55 > dayEMA89;
def daySN = dayEMA8 < dayEMA21 and dayEMA21 < dayEMA34 and dayEMA34 < dayEMA55 and dayEMA55 < dayEMA89;
def daySPW = dayEMA8 < dayEMA21 and dayEMA34 > dayEMA55 and dayEMA55 > dayEMA89;
def daySNW = dayEMA8 > dayEMA21 and dayEMA21 < dayEMA55 and dayEMA55 < dayEMA89;

AddLabel(yes, "DAY", if daySP then GlobalColor("StackedPositive") else if daySN then GlobalColor("StackedNegative") else if (daySPW or daySNW) then GlobalColor("Warning") else GlobalColor("Neutral"));

## week aggregationPeriod variables

input weekaggregationPeriod = AggregationPeriod.WEEK;
def weekprice = close(period = AggregationPeriod.WEEK);

def weekEMA89 = ExpAverage(weekprice, 89);
def weekEMA55 = ExpAverage(weekprice, 55);
def weekEMA34 = ExpAverage(weekprice, 34);
def weekEMA21 = ExpAverage(weekprice, 21);
def weekEMA8 = ExpAverage(weekprice, 8);

DefineGlobalColor("StackedPositive", Color.GREEN);
DefineGlobalColor("StackedNegative", Color.RED);
DefineGlobalColor("Warning", Color.YELLOW);
DefineGlobalColor("Neutral", Color.GRAY);

def weekSP = weekEMA8 > weekEMA21 and weekEMA21 > weekEMA34 and weekEMA34 > weekEMA55 and weekEMA55 > weekEMA89;
def weekSN = weekEMA8 < weekEMA21 and weekEMA21 < weekEMA34 and weekEMA34 < weekEMA55 and weekEMA55 < weekEMA89;
def weekSPW = weekEMA8 < weekEMA21 and weekEMA34 > weekEMA55 and weekEMA55 > weekEMA89;
def weekSNW = weekEMA8 > weekEMA21 and weekEMA34 < weekEMA55 and weekEMA55 < weekEMA89;

AddLabel(yes, "WK", if WEEKSP then GlobalColor("StackedPositive") else if weekSN then GlobalColor("StackedNegative") else if (weekSPW or weekSNW) then GlobalColor("Warning") else GlobalColor("Neutral"));
 
Thread starter Similar threads Forum Replies Date
S MTF Shaded EMA Questions 4
T Repaints MTF EMA Scalper For ThinkOrSwim Questions 1
C MTF EMA cloud Questions 1
V MTF EMA touch alert Questions 4
I MTF Average Daily Close Line Questions 2

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
287 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top