# Multiple Time Frame Trend Indicator for ThinkorSwim

#### iifbh

##### New member
How it works:

Calculations are done using the 5 and 21 period Exponential Moving Averages. (you can tweak this in settings). The indicator displays labels for different time frames. A green label means the 5 EMA is above the 21 EMA, a red label means the opposite. A white label means that the two are crossing over, implying a trend change. Crossovers / changes in trend at the smallest time frames would, in theory, spread "upwards" to longer time frames.

For example, let's say you're seeing red candles everywhere, but at some point in the day, you notice the 1-minute label turns white and then green. Then the 2 minute, and so on. Ideally, you would be able to open a bullish position during one of the shorter time frames, and ride the momentum up as the other time frames turn greener than a closeup of Shrek's face. Once you start seeing the lower time frames turn red again, you would get out for a profit… well, in theory. Some issues/bugs/drawbacks with this indicator:

Due to TOS quirks, you can only see labels for whatever time-frame you're on, plus for time frames that are longer. So if you're looking at the daily chart, you won't see any information for, say, the 15 minute time-frame. To get the most out of this indicator, you'll have to look at the 1-minute chart.

This indicator doesn't work on mobile. Since I do most of my trades from my phone, this makes me shed a little tear. :'(. It sometimes stops displaying certain time-frames if you're not looking at something that trades around the clock (like futures).

### thinkScript Code

Rich (BB code):
``````input MAtype = AverageType.EXPONENTIAL;
input ShortAverage = 5;
input LongAverage = 21;

def MA_month_close;
def MA_month_shortAvg;
def MA_month_longAvg;
def MA_month_higher;
def MA_month_lower;
def MA_month_same;
def MA_month_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.MONTH {
MA_month_close = close(period="Month");
MA_month_shortAvg = MovingAverage(MAtype, MA_month_close, ShortAverage);
MA_month_longAvg = MovingAverage(MAtype,MA_month_close, LongAverage);
MA_month_nowcrossing = if Crosses(MA_month_shortAvg, MA_month_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_month_same = if MA_month_nowcrossing == 1 then 1 else Double.NaN;
if MA_month_same == 1 {
MA_month_higher = Double.NaN;
MA_month_lower = Double.NaN;
} else {
MA_month_higher = if MA_month_shortAvg >= MA_month_longAvg then 1 else Double.NaN;
MA_month_lower = if MA_month_shortAvg < MA_month_longAvg then 1 else Double.NaN;
}
} else {
MA_month_close = 0;
MA_month_shortAvg = 0;
MA_month_longAvg = 0;
MA_month_higher = Double.NaN;
MA_month_lower = Double.NaN;
MA_month_same = Double.NaN;
MA_month_nowcrossing = 0;
}

def MA_week_close;
def MA_week_shortAvg;
def MA_week_longAvg;
def MA_week_higher;
def MA_week_lower;
def MA_week_same;
def MA_week_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.WEEK {
MA_week_close = close(period="Week");
MA_week_shortAvg = MovingAverage(MAtype, MA_week_close, ShortAverage);
MA_week_longAvg = MovingAverage(MAtype,MA_week_close, LongAverage);
MA_week_nowcrossing = if Crosses(MA_week_shortAvg, MA_week_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_week_same = if MA_week_nowcrossing == 1 then 1 else Double.NaN;
if MA_week_same == 1 {
MA_week_higher = Double.NaN;
MA_week_lower = Double.NaN;
} else {
MA_week_higher = if MA_week_shortAvg >= MA_week_longAvg then 1 else Double.NaN;
MA_week_lower = if MA_week_shortAvg < MA_week_longAvg then 1 else Double.NaN;
}
} else {
MA_week_close = 0;
MA_week_shortAvg = 0;
MA_week_longAvg = 0;
MA_week_higher = Double.NaN;
MA_week_lower = Double.NaN;
MA_week_same = Double.NaN;
MA_week_nowcrossing = 0;
}

def MA_4day_close;
def MA_4day_shortAvg;
def MA_4day_longAvg;
def MA_4day_higher;
def MA_4day_lower;
def MA_4day_same;
def MA_4day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_DAYS {
MA_4day_close = close(period="4 days");
MA_4day_shortAvg = MovingAverage(MAtype, MA_4day_close, ShortAverage);
MA_4day_longAvg = MovingAverage(MAtype,MA_4day_close, LongAverage);
MA_4day_nowcrossing = if Crosses(MA_4day_shortAvg, MA_4day_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_4day_same = if MA_4day_nowcrossing == 1 then 1 else Double.NaN;
if MA_4day_same == 1 {
MA_4day_higher = Double.NaN;
MA_4day_lower = Double.NaN;
} else {
MA_4day_higher = if MA_4day_shortAvg >= MA_4day_longAvg then 1 else Double.NaN;
MA_4day_lower = if MA_4day_shortAvg < MA_4day_longAvg then 1 else Double.NaN;
}
} else {
MA_4day_close = 0;
MA_4day_shortAvg = 0;
MA_4day_longAvg = 0;
MA_4day_higher = Double.NaN;
MA_4day_lower = Double.NaN;
MA_4day_same = Double.NaN;
MA_4day_nowcrossing = 0;
}

def MA_3day_close;
def MA_3day_shortAvg;
def MA_3day_longAvg;
def MA_3day_higher;
def MA_3day_lower;
def MA_3day_same;
def MA_3day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.THREE_DAYS {
MA_3day_close = close(period="3 days");
MA_3day_shortAvg = MovingAverage(MAtype, MA_3day_close, ShortAverage);
MA_3day_longAvg = MovingAverage(MAtype,MA_3day_close, LongAverage);
MA_3day_nowcrossing = if Crosses(MA_3day_shortAvg, MA_3day_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_3day_same = if MA_3day_nowcrossing == 1 then 1 else Double.NaN;
if MA_3day_same == 1 {
MA_3day_higher = Double.NaN;
MA_3day_lower = Double.NaN;
} else {
MA_3day_higher = if MA_3day_shortAvg >= MA_3day_longAvg then 1 else Double.NaN;
MA_3day_lower = if MA_3day_shortAvg < MA_3day_longAvg then 1 else Double.NaN;
}
} else {
MA_3day_close = 0;
MA_3day_shortAvg = 0;
MA_3day_longAvg = 0;
MA_3day_higher = Double.NaN;
MA_3day_lower = Double.NaN;
MA_3day_same = Double.NaN;
MA_3day_nowcrossing = 0;
}

def MA_2day_close;
def MA_2day_shortAvg;
def MA_2day_longAvg;
def MA_2day_higher;
def MA_2day_lower;
def MA_2day_same;
def MA_2day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TWO_DAYS {
MA_2day_close = close(period="2 days");
MA_2day_shortAvg = MovingAverage(MAtype, MA_2day_close, ShortAverage);
MA_2day_longAvg = MovingAverage(MAtype,MA_2day_close, LongAverage);
MA_2day_nowcrossing = if Crosses(MA_2day_shortAvg, MA_2day_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_2day_same = if MA_2day_nowcrossing == 1 then 1 else Double.NaN;
if MA_2day_same == 1 {
MA_2day_higher = Double.NaN;
MA_2day_lower = Double.NaN;
} else {
MA_2day_higher = if MA_2day_shortAvg >= MA_2day_longAvg then 1 else Double.NaN;
MA_2day_lower = if MA_2day_shortAvg < MA_2day_longAvg then 1 else Double.NaN;
}
} else {
MA_2day_close = 0;
MA_2day_shortAvg = 0;
MA_2day_longAvg = 0;
MA_2day_higher = Double.NaN;
MA_2day_lower = Double.NaN;
MA_2day_same = Double.NaN;
MA_2day_nowcrossing = 0;
}

def MA_1day_close;
def MA_1day_shortAvg;
def MA_1day_longAvg;
def MA_1day_higher;
def MA_1day_lower;
def MA_1day_same;
def MA_1day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.DAY {
MA_1day_close = close(period="Day");
MA_1day_shortAvg = MovingAverage(MAtype, MA_1day_close, ShortAverage);
MA_1day_longAvg = MovingAverage(MAtype,MA_1day_close, LongAverage);
MA_1day_nowcrossing = if Crosses(MA_1day_shortAvg, MA_1day_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_1day_same = if MA_1day_nowcrossing == 1 then 1 else Double.NaN;
if MA_1day_same == 1 {
MA_1day_higher = Double.NaN;
MA_1day_lower = Double.NaN;
} else {
MA_1day_higher = if MA_1day_shortAvg >= MA_1day_longAvg then 1 else Double.NaN;
MA_1day_lower = if MA_1day_shortAvg < MA_1day_longAvg then 1 else Double.NaN;
}
} else {
MA_1day_close = 0;
MA_1day_shortAvg = 0;
MA_1day_longAvg = 0;
MA_1day_higher = Double.NaN;
MA_1day_lower = Double.NaN;
MA_1day_same = Double.NaN;
MA_1day_nowcrossing = 0;
}

def MA_4hour_close;
def MA_4hour_shortAvg;
def MA_4hour_longAvg;
def MA_4hour_higher;
def MA_4hour_lower;
def MA_4hour_same;
def MA_4hour_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
MA_4hour_close = close(period="4 hours");
MA_4hour_shortAvg = MovingAverage(MAtype, MA_4hour_close, ShortAverage);
MA_4hour_longAvg = MovingAverage(MAtype,MA_4hour_close, LongAverage);
MA_4hour_nowcrossing = if Crosses(MA_4hour_shortAvg, MA_4hour_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_4hour_same = if MA_4hour_nowcrossing == 1 then 1 else Double.NaN;
if MA_4hour_same == 1 {
MA_4hour_higher = Double.NaN;
MA_4hour_lower = Double.NaN;
} else {
MA_4hour_higher = if MA_4hour_shortAvg >= MA_4hour_longAvg then 1 else Double.NaN;
MA_4hour_lower = if MA_4hour_shortAvg < MA_4hour_longAvg then 1 else Double.NaN;
}
} else {
MA_4hour_close = 0;
MA_4hour_shortAvg = 0;
MA_4hour_longAvg = 0;
MA_4hour_higher = Double.NaN;
MA_4hour_lower = Double.NaN;
MA_4hour_same = Double.NaN;
MA_4hour_nowcrossing = 0;
}

def MA_2hour_close;
def MA_2hour_shortAvg;
def MA_2hour_longAvg;
def MA_2hour_higher;
def MA_2hour_lower;
def MA_2hour_same;
def MA_2hour_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS {
MA_2hour_close = close(period="2 hours");
MA_2hour_shortAvg = MovingAverage(MAtype, MA_2hour_close, ShortAverage);
MA_2hour_longAvg = MovingAverage(MAtype,MA_2hour_close, LongAverage);
MA_2hour_nowcrossing = if Crosses(MA_2hour_shortAvg, MA_2hour_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_2hour_same = if MA_2hour_nowcrossing == 1 then 1 else Double.NaN;
if MA_2hour_same == 1 {
MA_2hour_higher = Double.NaN;
MA_2hour_lower = Double.NaN;
} else {
MA_2hour_higher = if MA_2hour_shortAvg >= MA_2hour_longAvg then 1 else Double.NaN;
MA_2hour_lower = if MA_2hour_shortAvg < MA_2hour_longAvg then 1 else Double.NaN;
}
} else {
MA_2hour_close = 0;
MA_2hour_shortAvg = 0;
MA_2hour_longAvg = 0;
MA_2hour_higher = Double.NaN;
MA_2hour_lower = Double.NaN;
MA_2hour_same = Double.NaN;
MA_2hour_nowcrossing = 0;
}

def MA_1hour_close;
def MA_1hour_shortAvg;
def MA_1hour_longAvg;
def MA_1hour_higher;
def MA_1hour_lower;
def MA_1hour_same;
def MA_1hour_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.HOUR {
MA_1hour_close = close(period="1 hour");
MA_1hour_shortAvg = MovingAverage(MAtype, MA_1hour_close, ShortAverage);
MA_1hour_longAvg = MovingAverage(MAtype,MA_1hour_close, LongAverage);
MA_1hour_nowcrossing = if Crosses(MA_1hour_shortAvg, MA_1hour_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_1hour_same = if MA_1hour_nowcrossing == 1 then 1 else Double.NaN;
if MA_1hour_same == 1 {
MA_1hour_higher = Double.NaN;
MA_1hour_lower = Double.NaN;
} else {
MA_1hour_higher = if MA_1hour_shortAvg >= MA_1hour_longAvg then 1 else Double.NaN;
MA_1hour_lower = if MA_1hour_shortAvg < MA_1hour_longAvg then 1 else Double.NaN;
}
} else {
MA_1hour_close = 0;
MA_1hour_shortAvg = 0;
MA_1hour_longAvg = 0;
MA_1hour_higher = Double.NaN;
MA_1hour_lower = Double.NaN;
MA_1hour_same = Double.NaN;
MA_1hour_nowcrossing = 0;
}

def MA_30min_close;
def MA_30min_shortAvg;
def MA_30min_longAvg;
def MA_30min_higher;
def MA_30min_lower;
def MA_30min_same;
def MA_30min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN {
MA_30min_close = close(period="30 min");
MA_30min_shortAvg = MovingAverage(MAtype, MA_30min_close, ShortAverage);
MA_30min_longAvg = MovingAverage(MAtype,MA_30min_close, LongAverage);
MA_30min_nowcrossing = if Crosses(MA_30min_shortAvg, MA_30min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_30min_same = if MA_30min_nowcrossing == 1 then 1 else Double.NaN;
if MA_30min_same == 1 {
MA_30min_higher = Double.NaN;
MA_30min_lower = Double.NaN;
} else {
MA_30min_higher = if MA_30min_shortAvg >= MA_30min_longAvg then 1 else Double.NaN;
MA_30min_lower = if MA_30min_shortAvg < MA_30min_longAvg then 1 else Double.NaN;
}
} else {
MA_30min_close = 0;
MA_30min_shortAvg = 0;
MA_30min_longAvg = 0;
MA_30min_higher = Double.NaN;
MA_30min_lower = Double.NaN;
MA_30min_same = Double.NaN;
MA_30min_nowcrossing = 0;
}

def MA_15min_close;
def MA_15min_shortAvg;
def MA_15min_longAvg;
def MA_15min_higher;
def MA_15min_lower;
def MA_15min_same;
def MA_15min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
MA_15min_close = close(period="15 min");
MA_15min_shortAvg = MovingAverage(MAtype, MA_15min_close, ShortAverage);
MA_15min_longAvg = MovingAverage(MAtype,MA_15min_close, LongAverage);
MA_15min_nowcrossing = if Crosses(MA_15min_shortAvg, MA_15min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_15min_same = if MA_15min_nowcrossing == 1 then 1 else Double.NaN;
if MA_15min_same == 1 {
MA_15min_higher = Double.NaN;
MA_15min_lower = Double.NaN;
} else {
MA_15min_higher = if MA_15min_shortAvg >= MA_15min_longAvg then 1 else Double.NaN;
MA_15min_lower = if MA_15min_shortAvg < MA_15min_longAvg then 1 else Double.NaN;
}
} else {
MA_15min_close = 0;
MA_15min_shortAvg = 0;
MA_15min_longAvg = 0;
MA_15min_higher = Double.NaN;
MA_15min_lower = Double.NaN;
MA_15min_same = Double.NaN;
MA_15min_nowcrossing = 0;
}

def MA_10min_close;
def MA_10min_shortAvg;
def MA_10min_longAvg;
def MA_10min_higher;
def MA_10min_lower;
def MA_10min_same;
def MA_10min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TEN_MIN {
MA_10min_close = close(period="10 min");
MA_10min_shortAvg = MovingAverage(MAtype, MA_10min_close, ShortAverage);
MA_10min_longAvg = MovingAverage(MAtype,MA_10min_close, LongAverage);
MA_10min_nowcrossing = if Crosses(MA_10min_shortAvg, MA_10min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_10min_same = if MA_10min_nowcrossing == 1 then 1 else Double.NaN;
if MA_10min_same == 1 {
MA_10min_higher = Double.NaN;
MA_10min_lower = Double.NaN;
} else {
MA_10min_higher = if MA_10min_shortAvg >= MA_10min_longAvg then 1 else Double.NaN;
MA_10min_lower = if MA_10min_shortAvg < MA_10min_longAvg then 1 else Double.NaN;
}
} else {
MA_10min_close = 0;
MA_10min_shortAvg = 0;
MA_10min_longAvg = 0;
MA_10min_higher = Double.NaN;
MA_10min_lower = Double.NaN;
MA_10min_same = Double.NaN;
MA_10min_nowcrossing = 0;
}

def MA_shortAvgmin_close;
def MA_shortAvgmin_shortAvg;
def MA_shortAvgmin_longAvg;
def MA_shortAvgmin_higher;
def MA_shortAvgmin_lower;
def MA_shortAvgmin_same;
def MA_shortAvgmin_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {
MA_shortAvgmin_close = close(period="5 min");
MA_shortAvgmin_shortAvg = MovingAverage(MAtype, MA_shortAvgmin_close, ShortAverage);
MA_shortAvgmin_longAvg = MovingAverage(MAtype,MA_shortAvgmin_close, LongAverage);
MA_shortAvgmin_nowcrossing = if Crosses(MA_shortAvgmin_shortAvg, MA_shortAvgmin_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_shortAvgmin_same = if MA_shortAvgmin_nowcrossing == 1 then 1 else Double.NaN;
if MA_shortAvgmin_same == 1 {
MA_shortAvgmin_higher = Double.NaN;
MA_shortAvgmin_lower = Double.NaN;
} else {
MA_shortAvgmin_higher = if MA_shortAvgmin_shortAvg >= MA_shortAvgmin_longAvg then 1 else Double.NaN;
MA_shortAvgmin_lower = if MA_shortAvgmin_shortAvg < MA_shortAvgmin_longAvg then 1 else Double.NaN;
}
} else {
MA_shortAvgmin_close = 0;
MA_shortAvgmin_shortAvg = 0;
MA_shortAvgmin_longAvg = 0;
MA_shortAvgmin_higher = Double.NaN;
MA_shortAvgmin_lower = Double.NaN;
MA_shortAvgmin_same = Double.NaN;
MA_shortAvgmin_nowcrossing = 0;
}

def MA_4min_close;
def MA_4min_shortAvg;
def MA_4min_longAvg;
def MA_4min_higher;
def MA_4min_lower;
def MA_4min_same;
def MA_4min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_MIN {
MA_4min_close = close(period="4 min");
MA_4min_shortAvg = MovingAverage(MAtype, MA_4min_close, ShortAverage);
MA_4min_longAvg = MovingAverage(MAtype,MA_4min_close, LongAverage);
MA_4min_nowcrossing = if Crosses(MA_4min_shortAvg, MA_4min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_4min_same = if MA_4min_nowcrossing == 1 then 1 else Double.NaN;
if MA_4min_same == 1 {
MA_4min_higher = Double.NaN;
MA_4min_lower = Double.NaN;
} else {
MA_4min_higher = if MA_4min_shortAvg >= MA_4min_longAvg then 1 else Double.NaN;
MA_4min_lower = if MA_4min_shortAvg < MA_4min_longAvg then 1 else Double.NaN;
}
} else {
MA_4min_close = 0;
MA_4min_shortAvg = 0;
MA_4min_longAvg = 0;
MA_4min_higher = Double.NaN;
MA_4min_lower = Double.NaN;
MA_4min_same = Double.NaN;
MA_4min_nowcrossing = 0;
}

def MA_3min_close;
def MA_3min_shortAvg;
def MA_3min_longAvg;
def MA_3min_higher;
def MA_3min_lower;
def MA_3min_same;
def MA_3min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.THREE_MIN {
MA_3min_close = close(period="3 min");
MA_3min_shortAvg = MovingAverage(MAtype, MA_3min_close, ShortAverage);
MA_3min_longAvg = MovingAverage(MAtype,MA_3min_close, LongAverage);
MA_3min_nowcrossing = if Crosses(MA_3min_shortAvg, MA_3min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_3min_same = if MA_3min_nowcrossing == 1 then 1 else Double.NaN;
if MA_3min_same == 1 {
MA_3min_higher = Double.NaN;
MA_3min_lower = Double.NaN;
} else {
MA_3min_higher = if MA_3min_shortAvg >= MA_3min_longAvg then 1 else Double.NaN;
MA_3min_lower = if MA_3min_shortAvg < MA_3min_longAvg then 1 else Double.NaN;
}
} else {
MA_3min_close = 0;
MA_3min_shortAvg = 0;
MA_3min_longAvg = 0;
MA_3min_higher = Double.NaN;
MA_3min_lower = Double.NaN;
MA_3min_same = Double.NaN;
MA_3min_nowcrossing = 0;
}

def MA_2min_close;
def MA_2min_shortAvg;
def MA_2min_longAvg;
def MA_2min_higher;
def MA_2min_lower;
def MA_2min_same;
def MA_2min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TWO_MIN {
MA_2min_close = close(period="2 min");
MA_2min_shortAvg = MovingAverage(MAtype, MA_2min_close, ShortAverage);
MA_2min_longAvg = MovingAverage(MAtype,MA_2min_close, LongAverage);
MA_2min_nowcrossing = if Crosses(MA_2min_shortAvg, MA_2min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_2min_same = if MA_2min_nowcrossing == 1 then 1 else Double.NaN;
if MA_2min_same == 1 {
MA_2min_higher = Double.NaN;
MA_2min_lower = Double.NaN;
} else {
MA_2min_higher = if MA_2min_shortAvg >= MA_2min_longAvg then 1 else Double.NaN;
MA_2min_lower = if MA_2min_shortAvg < MA_2min_longAvg then 1 else Double.NaN;
}
} else {
MA_2min_close = 0;
MA_2min_shortAvg = 0;
MA_2min_longAvg = 0;
MA_2min_higher = Double.NaN;
MA_2min_lower = Double.NaN;
MA_2min_same = Double.NaN;
MA_2min_nowcrossing = 0;
}

def MA_1min_close;
def MA_1min_shortAvg;
def MA_1min_longAvg;
def MA_1min_higher;
def MA_1min_lower;
def MA_1min_same;
def MA_1min_nowcrossing;
if GetAggregationPeriod() == AggregationPeriod.MIN {
MA_1min_close = close(period="1 min");
MA_1min_shortAvg = MovingAverage(MAtype, MA_1min_close, ShortAverage);
MA_1min_longAvg = MovingAverage(MAtype,MA_1min_close, LongAverage);
MA_1min_nowcrossing = if Crosses(MA_1min_shortAvg, MA_1min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_1min_same = if MA_1min_nowcrossing == 1 then 1 else Double.NaN;
if MA_1min_same == 1 {
MA_1min_higher = Double.NaN;
MA_1min_lower = Double.NaN;
} else {
MA_1min_higher = if MA_1min_shortAvg >= MA_1min_longAvg then 1 else Double.NaN;
MA_1min_lower = if MA_1min_shortAvg < MA_1min_longAvg then 1 else Double.NaN;
}
} else {
MA_1min_close = 0;
MA_1min_shortAvg = 0;
MA_1min_longAvg = 0;
MA_1min_higher = Double.NaN;
MA_1min_lower = Double.NaN;
MA_1min_same = Double.NaN;
MA_1min_nowcrossing = 0;
}

https://tos.mx/K2Y7vT

Last edited by a moderator:
I liked this MTF MA cross indicator. Do we have a working MTF TTM squeeze indicator? That reddit link has a version of MTF squeeze indicator but it did not work correctly.

anyone have the code or a shared link to a MTF TTM squeeze indicator? Id be interested in that as well.

I love the Multiple Time Frame Trend Indicator. Is there a scan available to search for stocks that ended the day green on all time frames?
Thanks

Thanks @iifbh .. this is very useful script, and we can apply this MTF to any indicator with slight modifications

Hi, Im trying to add the following code instead of the crossover but i cant seem to figure it out. Can anyone help me out? I would like the same functionality as this code except instead of the MA crossover i would like Positive = green and negative = red else white. All i need is one section of the code and i can copy and paste the other time periods. Let me know if i need to explain further but see the below code.

Code:
``````Def positive =MACD()."avg" is less than or equal to MACD()."ZeroLine" within 1 bars and close is greater than MovAvgExponential("length" = 200)."AvgExp" within 1 bars and MACD()."Diff" is greater than MACD()."Diff" from 1 bars ago;

Def negative =MACD()."avg" is greater than or equal to MACD()."ZeroLine" within 1 bars and close is less than MovAvgExponential("length" = 200)."AvgExp" within 1 bars and MACD()."Diff" is less than MACD()."Diff" from 1 bars ago;``````

Any help would be greatly appreciated, I made a few color edits on this code, thats about all i can doo , oh and label manipulation ...LOL

Code:
``````input MAtype = AverageType.EXPONENTIAL;
input ShortAverage = 8;
input LongAverage = 20;

def MA_month_close;
def MA_month_shortAvg;
def MA_month_longAvg;
def MA_month_higher;
def MA_month_lower;
def MA_month_same;
def MA_month_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.MONTH {
MA_month_close = close(period="Month");
MA_month_shortAvg = MovingAverage(MAtype, MA_month_close, ShortAverage);
MA_month_longAvg = MovingAverage(MAtype,MA_month_close, LongAverage);
MA_month_nowcrossing = if Crosses(MA_month_shortAvg, MA_month_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_month_same = if MA_month_nowcrossing == 1 then 1 else Double.NaN;
if MA_month_same == 1 {
MA_month_higher = Double.NaN;
MA_month_lower = Double.NaN;
} else {
MA_month_higher = if MA_month_shortAvg >= MA_month_longAvg then 1 else Double.NaN;
MA_month_lower = if MA_month_shortAvg < MA_month_longAvg then 1 else Double.NaN;
}
} else {
MA_month_close = 0;
MA_month_shortAvg = 0;
MA_month_longAvg = 0;
MA_month_higher = Double.NaN;
MA_month_lower = Double.NaN;
MA_month_same = Double.NaN;
MA_month_nowcrossing = 0;
}

def MA_week_close;
def MA_week_shortAvg;
def MA_week_longAvg;
def MA_week_higher;
def MA_week_lower;
def MA_week_same;
def MA_week_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.WEEK {
MA_week_close = close(period="Week");
MA_week_shortAvg = MovingAverage(MAtype, MA_week_close, ShortAverage);
MA_week_longAvg = MovingAverage(MAtype,MA_week_close, LongAverage);
MA_week_nowcrossing = if Crosses(MA_week_shortAvg, MA_week_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_week_same = if MA_week_nowcrossing == 1 then 1 else Double.NaN;
if MA_week_same == 1 {
MA_week_higher = Double.NaN;
MA_week_lower = Double.NaN;
} else {
MA_week_higher = if MA_week_shortAvg >= MA_week_longAvg then 1 else Double.NaN;
MA_week_lower = if MA_week_shortAvg < MA_week_longAvg then 1 else Double.NaN;
}
} else {
MA_week_close = 0;
MA_week_shortAvg = 0;
MA_week_longAvg = 0;
MA_week_higher = Double.NaN;
MA_week_lower = Double.NaN;
MA_week_same = Double.NaN;
MA_week_nowcrossing = 0;
}

def MA_4day_close;
def MA_4day_shortAvg;
def MA_4day_longAvg;
def MA_4day_higher;
def MA_4day_lower;
def MA_4day_same;
def MA_4day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_DAYS {
MA_4day_close = close(period="4 days");
MA_4day_shortAvg = MovingAverage(MAtype, MA_4day_close, ShortAverage);
MA_4day_longAvg = MovingAverage(MAtype,MA_4day_close, LongAverage);
MA_4day_nowcrossing = if Crosses(MA_4day_shortAvg, MA_4day_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_4day_same = if MA_4day_nowcrossing == 1 then 1 else Double.NaN;
if MA_4day_same == 1 {
MA_4day_higher = Double.NaN;
MA_4day_lower = Double.NaN;
} else {
MA_4day_higher = if MA_4day_shortAvg >= MA_4day_longAvg then 1 else Double.NaN;
MA_4day_lower = if MA_4day_shortAvg < MA_4day_longAvg then 1 else Double.NaN;
}
} else {
MA_4day_close = 0;
MA_4day_shortAvg = 0;
MA_4day_longAvg = 0;
MA_4day_higher = Double.NaN;
MA_4day_lower = Double.NaN;
MA_4day_same = Double.NaN;
MA_4day_nowcrossing = 0;
}

def MA_3day_close;
def MA_3day_shortAvg;
def MA_3day_longAvg;
def MA_3day_higher;
def MA_3day_lower;
def MA_3day_same;
def MA_3day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.THREE_DAYS {
MA_3day_close = close(period="3 days");
MA_3day_shortAvg = MovingAverage(MAtype, MA_3day_close, ShortAverage);
MA_3day_longAvg = MovingAverage(MAtype,MA_3day_close, LongAverage);
MA_3day_nowcrossing = if Crosses(MA_3day_shortAvg, MA_3day_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_3day_same = if MA_3day_nowcrossing == 1 then 1 else Double.NaN;
if MA_3day_same == 1 {
MA_3day_higher = Double.NaN;
MA_3day_lower = Double.NaN;
} else {
MA_3day_higher = if MA_3day_shortAvg >= MA_3day_longAvg then 1 else Double.NaN;
MA_3day_lower = if MA_3day_shortAvg < MA_3day_longAvg then 1 else Double.NaN;
}
} else {
MA_3day_close = 0;
MA_3day_shortAvg = 0;
MA_3day_longAvg = 0;
MA_3day_higher = Double.NaN;
MA_3day_lower = Double.NaN;
MA_3day_same = Double.NaN;
MA_3day_nowcrossing = 0;
}

def MA_2day_close;
def MA_2day_shortAvg;
def MA_2day_longAvg;
def MA_2day_higher;
def MA_2day_lower;
def MA_2day_same;
def MA_2day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TWO_DAYS {
MA_2day_close = close(period="2 days");
MA_2day_shortAvg = MovingAverage(MAtype, MA_2day_close, ShortAverage);
MA_2day_longAvg = MovingAverage(MAtype,MA_2day_close, LongAverage);
MA_2day_nowcrossing = if Crosses(MA_2day_shortAvg, MA_2day_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_2day_same = if MA_2day_nowcrossing == 1 then 1 else Double.NaN;
if MA_2day_same == 1 {
MA_2day_higher = Double.NaN;
MA_2day_lower = Double.NaN;
} else {
MA_2day_higher = if MA_2day_shortAvg >= MA_2day_longAvg then 1 else Double.NaN;
MA_2day_lower = if MA_2day_shortAvg < MA_2day_longAvg then 1 else Double.NaN;
}
} else {
MA_2day_close = 0;
MA_2day_shortAvg = 0;
MA_2day_longAvg = 0;
MA_2day_higher = Double.NaN;
MA_2day_lower = Double.NaN;
MA_2day_same = Double.NaN;
MA_2day_nowcrossing = 0;
}

def MA_1day_close;
def MA_1day_shortAvg;
def MA_1day_longAvg;
def MA_1day_higher;
def MA_1day_lower;
def MA_1day_same;
def MA_1day_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.DAY {
MA_1day_close = close(period="Day");
MA_1day_shortAvg = MovingAverage(MAtype, MA_1day_close, ShortAverage);
MA_1day_longAvg = MovingAverage(MAtype,MA_1day_close, LongAverage);
MA_1day_nowcrossing = if Crosses(MA_1day_shortAvg, MA_1day_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_1day_same = if MA_1day_nowcrossing == 1 then 1 else Double.NaN;
if MA_1day_same == 1 {
MA_1day_higher = Double.NaN;
MA_1day_lower = Double.NaN;
} else {
MA_1day_higher = if MA_1day_shortAvg >= MA_1day_longAvg then 1 else Double.NaN;
MA_1day_lower = if MA_1day_shortAvg < MA_1day_longAvg then 1 else Double.NaN;
}
} else {
MA_1day_close = 0;
MA_1day_shortAvg = 0;
MA_1day_longAvg = 0;
MA_1day_higher = Double.NaN;
MA_1day_lower = Double.NaN;
MA_1day_same = Double.NaN;
MA_1day_nowcrossing = 0;
}

def MA_4hour_close;
def MA_4hour_shortAvg;
def MA_4hour_longAvg;
def MA_4hour_higher;
def MA_4hour_lower;
def MA_4hour_same;
def MA_4hour_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
MA_4hour_close = close(period="4 hours");
MA_4hour_shortAvg = MovingAverage(MAtype, MA_4hour_close, ShortAverage);
MA_4hour_longAvg = MovingAverage(MAtype,MA_4hour_close, LongAverage);
MA_4hour_nowcrossing = if Crosses(MA_4hour_shortAvg, MA_4hour_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_4hour_same = if MA_4hour_nowcrossing == 1 then 1 else Double.NaN;
if MA_4hour_same == 1 {
MA_4hour_higher = Double.NaN;
MA_4hour_lower = Double.NaN;
} else {
MA_4hour_higher = if MA_4hour_shortAvg >= MA_4hour_longAvg then 1 else Double.NaN;
MA_4hour_lower = if MA_4hour_shortAvg < MA_4hour_longAvg then 1 else Double.NaN;
}
} else {
MA_4hour_close = 0;
MA_4hour_shortAvg = 0;
MA_4hour_longAvg = 0;
MA_4hour_higher = Double.NaN;
MA_4hour_lower = Double.NaN;
MA_4hour_same = Double.NaN;
MA_4hour_nowcrossing = 0;
}

def MA_2hour_close;
def MA_2hour_shortAvg;
def MA_2hour_longAvg;
def MA_2hour_higher;
def MA_2hour_lower;
def MA_2hour_same;
def MA_2hour_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS {
MA_2hour_close = close(period="2 hours");
MA_2hour_shortAvg = MovingAverage(MAtype, MA_2hour_close, ShortAverage);
MA_2hour_longAvg = MovingAverage(MAtype,MA_2hour_close, LongAverage);
MA_2hour_nowcrossing = if Crosses(MA_2hour_shortAvg, MA_2hour_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_2hour_same = if MA_2hour_nowcrossing == 1 then 1 else Double.NaN;
if MA_2hour_same == 1 {
MA_2hour_higher = Double.NaN;
MA_2hour_lower = Double.NaN;
} else {
MA_2hour_higher = if MA_2hour_shortAvg >= MA_2hour_longAvg then 1 else Double.NaN;
MA_2hour_lower = if MA_2hour_shortAvg < MA_2hour_longAvg then 1 else Double.NaN;
}
} else {
MA_2hour_close = 0;
MA_2hour_shortAvg = 0;
MA_2hour_longAvg = 0;
MA_2hour_higher = Double.NaN;
MA_2hour_lower = Double.NaN;
MA_2hour_same = Double.NaN;
MA_2hour_nowcrossing = 0;
}

def MA_1hour_close;
def MA_1hour_shortAvg;
def MA_1hour_longAvg;
def MA_1hour_higher;
def MA_1hour_lower;
def MA_1hour_same;
def MA_1hour_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.HOUR {
MA_1hour_close = close(period="1 hour");
MA_1hour_shortAvg = MovingAverage(MAtype, MA_1hour_close, ShortAverage);
MA_1hour_longAvg = MovingAverage(MAtype,MA_1hour_close, LongAverage);
MA_1hour_nowcrossing = if Crosses(MA_1hour_shortAvg, MA_1hour_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_1hour_same = if MA_1hour_nowcrossing == 1 then 1 else Double.NaN;
if MA_1hour_same == 1 {
MA_1hour_higher = Double.NaN;
MA_1hour_lower = Double.NaN;
} else {
MA_1hour_higher = if MA_1hour_shortAvg >= MA_1hour_longAvg then 1 else Double.NaN;
MA_1hour_lower = if MA_1hour_shortAvg < MA_1hour_longAvg then 1 else Double.NaN;
}
} else {
MA_1hour_close = 0;
MA_1hour_shortAvg = 0;
MA_1hour_longAvg = 0;
MA_1hour_higher = Double.NaN;
MA_1hour_lower = Double.NaN;
MA_1hour_same = Double.NaN;
MA_1hour_nowcrossing = 0;
}

def MA_30min_close;
def MA_30min_shortAvg;
def MA_30min_longAvg;
def MA_30min_higher;
def MA_30min_lower;
def MA_30min_same;
def MA_30min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN {
MA_30min_close = close(period="30 min");
MA_30min_shortAvg = MovingAverage(MAtype, MA_30min_close, ShortAverage);
MA_30min_longAvg = MovingAverage(MAtype,MA_30min_close, LongAverage);
MA_30min_nowcrossing = if Crosses(MA_30min_shortAvg, MA_30min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_30min_same = if MA_30min_nowcrossing == 1 then 1 else Double.NaN;
if MA_30min_same == 1 {
MA_30min_higher = Double.NaN;
MA_30min_lower = Double.NaN;
} else {
MA_30min_higher = if MA_30min_shortAvg >= MA_30min_longAvg then 1 else Double.NaN;
MA_30min_lower = if MA_30min_shortAvg < MA_30min_longAvg then 1 else Double.NaN;
}
} else {
MA_30min_close = 0;
MA_30min_shortAvg = 0;
MA_30min_longAvg = 0;
MA_30min_higher = Double.NaN;
MA_30min_lower = Double.NaN;
MA_30min_same = Double.NaN;
MA_30min_nowcrossing = 0;
}

def MA_15min_close;
def MA_15min_shortAvg;
def MA_15min_longAvg;
def MA_15min_higher;
def MA_15min_lower;
def MA_15min_same;
def MA_15min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
MA_15min_close = close(period="15 min");
MA_15min_shortAvg = MovingAverage(MAtype, MA_15min_close, ShortAverage);
MA_15min_longAvg = MovingAverage(MAtype,MA_15min_close, LongAverage);
MA_15min_nowcrossing = if Crosses(MA_15min_shortAvg, MA_15min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_15min_same = if MA_15min_nowcrossing == 1 then 1 else Double.NaN;
if MA_15min_same == 1 {
MA_15min_higher = Double.NaN;
MA_15min_lower = Double.NaN;
} else {
MA_15min_higher = if MA_15min_shortAvg >= MA_15min_longAvg then 1 else Double.NaN;
MA_15min_lower = if MA_15min_shortAvg < MA_15min_longAvg then 1 else Double.NaN;
}
} else {
MA_15min_close = 0;
MA_15min_shortAvg = 0;
MA_15min_longAvg = 0;
MA_15min_higher = Double.NaN;
MA_15min_lower = Double.NaN;
MA_15min_same = Double.NaN;
MA_15min_nowcrossing = 0;
}

def MA_10min_close;
def MA_10min_shortAvg;
def MA_10min_longAvg;
def MA_10min_higher;
def MA_10min_lower;
def MA_10min_same;
def MA_10min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TEN_MIN {
MA_10min_close = close(period="10 min");
MA_10min_shortAvg = MovingAverage(MAtype, MA_10min_close, ShortAverage);
MA_10min_longAvg = MovingAverage(MAtype,MA_10min_close, LongAverage);
MA_10min_nowcrossing = if Crosses(MA_10min_shortAvg, MA_10min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_10min_same = if MA_10min_nowcrossing == 1 then 1 else Double.NaN;
if MA_10min_same == 1 {
MA_10min_higher = Double.NaN;
MA_10min_lower = Double.NaN;
} else {
MA_10min_higher = if MA_10min_shortAvg >= MA_10min_longAvg then 1 else Double.NaN;
MA_10min_lower = if MA_10min_shortAvg < MA_10min_longAvg then 1 else Double.NaN;
}
} else {
MA_10min_close = 0;
MA_10min_shortAvg = 0;
MA_10min_longAvg = 0;
MA_10min_higher = Double.NaN;
MA_10min_lower = Double.NaN;
MA_10min_same = Double.NaN;
MA_10min_nowcrossing = 0;
}

def MA_shortAvgmin_close;
def MA_shortAvgmin_shortAvg;
def MA_shortAvgmin_longAvg;
def MA_shortAvgmin_higher;
def MA_shortAvgmin_lower;
def MA_shortAvgmin_same;
def MA_shortAvgmin_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {
MA_shortAvgmin_close = close(period="5 min");
MA_shortAvgmin_shortAvg = MovingAverage(MAtype, MA_shortAvgmin_close, ShortAverage);
MA_shortAvgmin_longAvg = MovingAverage(MAtype,MA_shortAvgmin_close, LongAverage);
MA_shortAvgmin_nowcrossing = if Crosses(MA_shortAvgmin_shortAvg, MA_shortAvgmin_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_shortAvgmin_same = if MA_shortAvgmin_nowcrossing == 1 then 1 else Double.NaN;
if MA_shortAvgmin_same == 1 {
MA_shortAvgmin_higher = Double.NaN;
MA_shortAvgmin_lower = Double.NaN;
} else {
MA_shortAvgmin_higher = if MA_shortAvgmin_shortAvg >= MA_shortAvgmin_longAvg then 1 else Double.NaN;
MA_shortAvgmin_lower = if MA_shortAvgmin_shortAvg < MA_shortAvgmin_longAvg then 1 else Double.NaN;
}
} else {
MA_shortAvgmin_close = 0;
MA_shortAvgmin_shortAvg = 0;
MA_shortAvgmin_longAvg = 0;
MA_shortAvgmin_higher = Double.NaN;
MA_shortAvgmin_lower = Double.NaN;
MA_shortAvgmin_same = Double.NaN;
MA_shortAvgmin_nowcrossing = 0;
}

def MA_4min_close;
def MA_4min_shortAvg;
def MA_4min_longAvg;
def MA_4min_higher;
def MA_4min_lower;
def MA_4min_same;
def MA_4min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.FOUR_MIN {
MA_4min_close = close(period="4 min");
MA_4min_shortAvg = MovingAverage(MAtype, MA_4min_close, ShortAverage);
MA_4min_longAvg = MovingAverage(MAtype,MA_4min_close, LongAverage);
MA_4min_nowcrossing = if Crosses(MA_4min_shortAvg, MA_4min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_4min_same = if MA_4min_nowcrossing == 1 then 1 else Double.NaN;
if MA_4min_same == 1 {
MA_4min_higher = Double.NaN;
MA_4min_lower = Double.NaN;
} else {
MA_4min_higher = if MA_4min_shortAvg >= MA_4min_longAvg then 1 else Double.NaN;
MA_4min_lower = if MA_4min_shortAvg < MA_4min_longAvg then 1 else Double.NaN;
}
} else {
MA_4min_close = 0;
MA_4min_shortAvg = 0;
MA_4min_longAvg = 0;
MA_4min_higher = Double.NaN;
MA_4min_lower = Double.NaN;
MA_4min_same = Double.NaN;
MA_4min_nowcrossing = 0;
}

def MA_3min_close;
def MA_3min_shortAvg;
def MA_3min_longAvg;
def MA_3min_higher;
def MA_3min_lower;
def MA_3min_same;
def MA_3min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.THREE_MIN {
MA_3min_close = close(period="3 min");
MA_3min_shortAvg = MovingAverage(MAtype, MA_3min_close, ShortAverage);
MA_3min_longAvg = MovingAverage(MAtype,MA_3min_close, LongAverage);
MA_3min_nowcrossing = if Crosses(MA_3min_shortAvg, MA_3min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_3min_same = if MA_3min_nowcrossing == 1 then 1 else Double.NaN;
if MA_3min_same == 1 {
MA_3min_higher = Double.NaN;
MA_3min_lower = Double.NaN;
} else {
MA_3min_higher = if MA_3min_shortAvg >= MA_3min_longAvg then 1 else Double.NaN;
MA_3min_lower = if MA_3min_shortAvg < MA_3min_longAvg then 1 else Double.NaN;
}
} else {
MA_3min_close = 0;
MA_3min_shortAvg = 0;
MA_3min_longAvg = 0;
MA_3min_higher = Double.NaN;
MA_3min_lower = Double.NaN;
MA_3min_same = Double.NaN;
MA_3min_nowcrossing = 0;
}

def MA_2min_close;
def MA_2min_shortAvg;
def MA_2min_longAvg;
def MA_2min_higher;
def MA_2min_lower;
def MA_2min_same;
def MA_2min_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.TWO_MIN {
MA_2min_close = close(period="2 min");
MA_2min_shortAvg = MovingAverage(MAtype, MA_2min_close, ShortAverage);
MA_2min_longAvg = MovingAverage(MAtype,MA_2min_close, LongAverage);
MA_2min_nowcrossing = if Crosses(MA_2min_shortAvg, MA_2min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_2min_same = if MA_2min_nowcrossing == 1 then 1 else Double.NaN;
if MA_2min_same == 1 {
MA_2min_higher = Double.NaN;
MA_2min_lower = Double.NaN;
} else {
MA_2min_higher = if MA_2min_shortAvg >= MA_2min_longAvg then 1 else Double.NaN;
MA_2min_lower = if MA_2min_shortAvg < MA_2min_longAvg then 1 else Double.NaN;
}
} else {
MA_2min_close = 0;
MA_2min_shortAvg = 0;
MA_2min_longAvg = 0;
MA_2min_higher = Double.NaN;
MA_2min_lower = Double.NaN;
MA_2min_same = Double.NaN;
MA_2min_nowcrossing = 0;
}

def MA_1min_close;
def MA_1min_shortAvg;
def MA_1min_longAvg;
def MA_1min_higher;
def MA_1min_lower;
def MA_1min_same;
def MA_1min_nowcrossing;
if GetAggregationPeriod() == AggregationPeriod.MIN {
MA_1min_close = close(period="1 min");
MA_1min_shortAvg = MovingAverage(MAtype, MA_1min_close, ShortAverage);
MA_1min_longAvg = MovingAverage(MAtype,MA_1min_close, LongAverage);
MA_1min_nowcrossing = if Crosses(MA_1min_shortAvg, MA_1min_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_1min_same = if MA_1min_nowcrossing == 1 then 1 else Double.NaN;
if MA_1min_same == 1 {
MA_1min_higher = Double.NaN;
MA_1min_lower = Double.NaN;
} else {
MA_1min_higher = if MA_1min_shortAvg >= MA_1min_longAvg then 1 else Double.NaN;
MA_1min_lower = if MA_1min_shortAvg < MA_1min_longAvg then 1 else Double.NaN;
}
} else {
MA_1min_close = 0;
MA_1min_shortAvg = 0;
MA_1min_longAvg = 0;
MA_1min_higher = Double.NaN;
MA_1min_lower = Double.NaN;
MA_1min_same = Double.NaN;
MA_1min_nowcrossing = 0;
}

Last edited by a moderator:
No worries. Here is an example you can use for the rest of it:

input MAtype = AverageType.EXPONENTIAL;
input MAType2 = AverageType.Simple;
input ShortAverage = 8;
input LongAverage = 20;

def MA_month_close;
def MA_month_shortAvg;
def MA_month_longAvg;
def MA_month_higher;
def MA_month_lower;
def MA_month_same;
def MA_month_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.MONTH {
MA_month_close = close(period="Month");
MA_month_shortAvg = MovingAverage(MAtype, MA_month_close, ShortAverage);
MA_month_longAvg = MovingAverage(MAtype2,MA_month_close, LongAverage);

See the changes in bold. basically just switch out MAType with MAType2 when you want to mix up the moving averages.

• BenTen
I was able to modify the script so i could use it in a watchlist to monitor sever stack at once. I want to assign the background color to match the condition set forth in the script. here is what i have so far. Can someone help modify the add label section to AssignBackGroundColor, that would be extremely helpful. Thanks

Code:
``````input MAtype = AverageType.EXPONENTIAL;
input ShortAverage = 8;
input LongAverage = 21;

def MA_month_close;
def MA_month_shortAvg;
def MA_month_longAvg;
def MA_month_higher;
def MA_month_lower;
def MA_month_same;
def MA_month_nowcrossing;
if GetAggregationPeriod() <= AggregationPeriod.MONTH {
MA_month_close = close(period="Month");
MA_month_shortAvg = MovingAverage(MAtype, MA_month_close, ShortAverage);
MA_month_longAvg = MovingAverage(MAtype,MA_month_close, LongAverage);
MA_month_nowcrossing = if Crosses(MA_month_shortAvg, MA_month_longAvg, CrossingDirection.ANY) then 1 else 0;
MA_month_same = if MA_month_nowcrossing == 1 then 1 else Double.NaN;
if MA_month_same == 1 {
MA_month_higher = Double.NaN;
MA_month_lower = Double.NaN;
} else {
MA_month_higher = if MA_month_shortAvg >= MA_month_longAvg then 1 else Double.NaN;
MA_month_lower = if MA_month_shortAvg < MA_month_longAvg then 1 else Double.NaN;
}
} else {
MA_month_close = 0;
MA_month_shortAvg = 0;
MA_month_longAvg = 0;
MA_month_higher = Double.NaN;
MA_month_lower = Double.NaN;
MA_month_same = Double.NaN;
MA_month_nowcrossing = 0;
}

### Not the exact question you're looking for?

87k+ Posts
230 Online ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?