Repaints Multi Time Frame MTF Squeeze HISTOGRAM Colored Labels for ThinkOrSwim

Repaints

caseyjbrett

Member
Multi Time Frame MTF Squeeze HISTOGRAM Colored Labels for ThinkOrSwim

For anybody interested, here is the script for the MTF Squeeze Histogram Colored Labels I wrote. It's identical to the new "Simpler Trading" indicator. This is the bottom row of labels in the picture. It's based on momentum and does not show you if there's a squeeze, but rather the momentum of the trend during each time period. I'm not sure if there are any parts of the script that aren't necessary. Regardless, it functions as it should. Any comments, corrections, and/or constructive criticism are welcomed. I hope somebody else finds this script helpful!

UPDATE: In case anybody else wants the MTF Squeeze PRO Labels script as well, here is the link for it.

1/5/2022 EDIT: Revised script and removed GlobalColor redundancies. Users can now select which time frames they want to be displayed on their chart(s). If you do not want any given timeframe displayed on your chart, simply go into the script settings and select "No" under the drop-down for that timeframe!

https://usethinkscript.com/threads/multi-time-fram-mtf-squeeze-pro-labels-for-thinkorswim.9282/

Code:
##MTF Squeeze Histogram Labels
##Created By: Casey Brett
##Global Variables

input price = close;
input length = 20;
input averageType = AverageType.EXPONENTIAL;
input displace = 0;

def K = (Highest(high, length) + Lowest(low, length)) /2 + ExpAverage(close, length);
def momo = Inertia(price - K / 2, length);

def pos         = momo >= 0;
def neg         = momo < 0;
def up         = momo >= momo[1];
def dn         = momo < momo[1];

def PosUp = pos and up;
def PosDn = pos and dn;
def NegDn = neg and dn;
def NegUp = neg and up;

input MonthLabel = yes;
input WeekLabel = yes;
input FourDayLabel = yes;
input ThreeDayLabel = yes;
input TwoDayLabel = yes;
input DayLabel = yes;
input FourHourLabel = yes;
input TwoHourLabel = yes;
input OneHourLabel = yes;
input ThirtyMinLabel = yes;
input TwentyMinLabel = yes;
input FifteenMinLabel = yes;
input TenMinLabel = yes;
input FiveMinLabel = yes;
input FourMinLabel = yes;
input ThreeMinLabel = yes;
input TwoMinLabel = yes;
input OneMinLabel = yes;


defineGlobalColor("PosUp", color.cyan);
defineGlobalColor("PosDn", color.blue);
defineGlobalColor("NegDn", color.red);
defineGlobalColor("NegUp", color.yellow);
defineGlobalColor("Neutral", color.gray);

def monthprice;
def Kmonth;
def monthmomo;
Def Month_ExpAverage;
Def monthpos;
Def monthneg;
Def monthup;
Def monthdn;
Def monthPosUp;
Def monthPosDn;
Def monthNegDn;
Def monthNegUp;
Def monthAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Month {
    monthprice = close(period="Month");
    Kmonth = (Highest(high(period="Month"), length) + Lowest(low(period="Month"), length)) /2 + ExpAverage(close(period="Month"), length);
    monthmomo = Inertia(monthprice- kmonth / 2, length);
    Month_ExpAverage = ExpAverage(close(period="Month"), Length);
    monthpos = monthmomo >= 0;
    monthneg = monthmomo < 0;
    monthup  = monthmomo >= monthmomo[1];
    monthdn  = monthmomo < monthmomo[1];

    monthPosUp = monthpos and monthup;
    monthPosDn = monthpos and monthdn;
    monthNegDn = monthneg and monthdn;
    monthNegUp = monthneg and monthup;
    monthAggregationPeriod = 1;
}
Else {
    monthprice = 0;
    Kmonth = 0;
    monthmomo = 0;
    Month_ExpAverage = 0;
    monthpos = 0;
    monthneg = 0;
    monthup = 0;
    monthdn = 0;
    monthPosUp = 0;
    monthPosDn = 0;
    monthNegDn = 0;
    monthNegUp = 0;
    monthAggregationPeriod = 0;
}
AddLabel(monthLabel and monthAggregationPeriod, "M", if monthPosUp then globalColor("PosUp") else if monthPosDn then globalColor("PosDn") else if monthNegDn then globalColor("NegDn") else if monthNegUp then globalColor("NegUp") else globalColor("Neutral"));

def Weekprice;
def KWeek;
def Weekmomo;
Def Week_ExpAverage;
Def Weekpos;
Def Weekneg;
Def Weekup;
Def Weekdn;
Def WeekPosUp;
Def WeekPosDn;
Def WeekNegDn;
Def WeekNegUp;
Def WeekAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Week {
    Weekprice = close(period="Week");
    KWeek = (Highest(high(period="Week"), length) + Lowest(low(period="Week"), length)) /2 + ExpAverage(close(period="week"), length);
    Weekmomo = Inertia(Weekprice- kWeek / 2, length);
    Week_ExpAverage = ExpAverage(close(period="Week"), Length);
    Weekpos = Weekmomo >= 0;
    Weekneg = Weekmomo < 0;
    Weekup  = Weekmomo >= Weekmomo[1];
    Weekdn  = Weekmomo < Weekmomo[1];

    WeekPosUp = Weekpos and Weekup;
    WeekPosDn = Weekpos and Weekdn;
    WeekNegDn = Weekneg and Weekdn;
    WeekNegUp = Weekneg and Weekup;
    WeekAggregationPeriod = 1;
}
Else {
    Weekprice = 0;
    KWeek = 0;
    Weekmomo = 0;
    Week_ExpAverage = 0;
    Weekpos = 0;
    Weekneg = 0;
    Weekup = 0;
    Weekdn = 0;
    WeekPosUp = 0;
    WeekPosDn = 0;
    WeekNegDn = 0;
    WeekNegUp = 0;
    WeekAggregationPeriod = 0;
}
AddLabel(WeekLabel and WeekAggregationPeriod, "W", if WeekPosUp then globalColor("PosUp") else if WeekPosDn then globalColor("PosDn") else if WeekNegDn then globalColor("NegDn") else if WeekNegUp then globalColor("NegUp") else globalColor("Neutral"));


def four_daysprice;
def Kfour_days;
def four_daysmomo;
Def four_days_ExpAverage;
Def four_dayspos;
Def four_daysneg;
Def four_daysup;
Def four_daysdn;
Def four_daysPosUp;
Def four_daysPosDn;
Def four_daysNegDn;
Def four_daysNegUp;
Def four_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_days {
    four_daysprice = close(period="4 Days");
    Kfour_days = (Highest(high(period="4 Days"), length) + Lowest(low(period="4 Days"), length)) /2 + ExpAverage(close(period="4 Days"), length);
    four_daysmomo = Inertia(four_daysprice- kfour_days / 2, length);
    four_days_ExpAverage = ExpAverage(close(period="4 Days"), Length);
    four_dayspos = four_daysmomo >= 0;
    four_daysneg = four_daysmomo < 0;
    four_daysup  = four_daysmomo >= four_daysmomo[1];
    four_daysdn  = four_daysmomo < four_daysmomo[1];

    four_daysPosUp = four_dayspos and four_daysup;
    four_daysPosDn = four_dayspos and four_daysdn;
    four_daysNegDn = four_daysneg and four_daysdn;
    four_daysNegUp = four_daysneg and four_daysup;
    four_daysAggregationPeriod = 1;
}
Else {
    four_daysprice = 0;
    Kfour_days = 0;
    four_daysmomo = 0;
    four_days_ExpAverage = 0;
    four_dayspos = 0;
    four_daysneg = 0;
    four_daysup = 0;
    four_daysdn = 0;
    four_daysPosUp = 0;
    four_daysPosDn = 0;
    four_daysNegDn = 0;
    four_daysNegUp = 0;
    four_daysAggregationPeriod = 0;
}
AddLabel(FourDayLabel and four_daysAggregationPeriod, "4D", if four_daysPosUp then globalColor("PosUp") else if four_daysPosDn then globalColor("PosDn") else if four_daysNegDn then globalColor("NegDn") else if four_daysNegUp then globalColor("NegUp") else globalColor("Neutral"));

def three_daysprice;
def Kthree_days;
def three_daysmomo;
Def three_days_ExpAverage;
Def three_dayspos;
Def three_daysneg;
Def three_daysup;
Def three_daysdn;
Def three_daysPosUp;
Def three_daysPosDn;
Def three_daysNegDn;
Def three_daysNegUp;
Def three_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.three_days {
    three_daysprice = close(period="3 Days");
    Kthree_days = (Highest(high(period="3 Days"), length) + Lowest(low(period="3 Days"), length)) /2 + ExpAverage(close(period="3 Days"), length);
    three_daysmomo = Inertia(three_daysprice- kthree_days / 2, length);
    three_days_ExpAverage = ExpAverage(close(period="3 Days"), Length);
    three_dayspos = three_daysmomo >= 0;
    three_daysneg = three_daysmomo < 0;
    three_daysup  = three_daysmomo >= three_daysmomo[1];
    three_daysdn  = three_daysmomo < three_daysmomo[1];

    three_daysPosUp = three_dayspos and three_daysup;
    three_daysPosDn = three_dayspos and three_daysdn;
    three_daysNegDn = three_daysneg and three_daysdn;
    three_daysNegUp = three_daysneg and three_daysup;
    three_daysAggregationPeriod = 1;
}
Else {
    three_daysprice = 0;
    Kthree_days = 0;
    three_daysmomo = 0;
    three_days_ExpAverage = 0;
    three_dayspos = 0;
    three_daysneg = 0;
    three_daysup = 0;
    three_daysdn = 0;
    three_daysPosUp = 0;
    three_daysPosDn = 0;
    three_daysNegDn = 0;
    three_daysNegUp = 0;
    three_daysAggregationPeriod = 0;
}
AddLabel(ThreeDayLabel and three_daysAggregationPeriod, "3D", if three_daysPosUp then globalColor("PosUp") else if three_daysPosDn then globalColor("PosDn") else if three_daysNegDn then globalColor("NegDn") else if three_daysNegUp then globalColor("NegUp") else globalColor("Neutral"));




def two_daysprice;
def Ktwo_days;
def two_daysmomo;
Def two_days_ExpAverage;
Def two_dayspos;
Def two_daysneg;
Def two_daysup;
Def two_daysdn;
Def two_daysPosUp;
Def two_daysPosDn;
Def two_daysNegDn;
Def two_daysNegUp;
Def two_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_days {
    two_daysprice = close(period="2 Days");
    Ktwo_days = (Highest(high(period="2 Days"), length) + Lowest(low(period="2 Days"), length)) /2 + ExpAverage(close(period="2 Days"), length);
    two_daysmomo = Inertia(two_daysprice- ktwo_days / 2, length);
    two_days_ExpAverage = ExpAverage(close(period="2 Days"), Length);
    two_dayspos = two_daysmomo >= 0;
    two_daysneg = two_daysmomo < 0;
    two_daysup  = two_daysmomo >= two_daysmomo[1];
    two_daysdn  = two_daysmomo < two_daysmomo[1];

    two_daysPosUp = two_dayspos and two_daysup;
    two_daysPosDn = two_dayspos and two_daysdn;
    two_daysNegDn = two_daysneg and two_daysdn;
    two_daysNegUp = two_daysneg and two_daysup;
    two_daysAggregationPeriod = 1;
}
Else {
    two_daysprice = 0;
    Ktwo_days = 0;
    two_daysmomo = 0;
    two_days_ExpAverage = 0;
    two_dayspos = 0;
    two_daysneg = 0;
    two_daysup = 0;
    two_daysdn = 0;
    two_daysPosUp = 0;
    two_daysPosDn = 0;
    two_daysNegDn = 0;
    two_daysNegUp = 0;
    two_daysAggregationPeriod = 0;
}
AddLabel(TwoDayLabel and two_daysAggregationPeriod, "2D", if two_daysPosUp then globalColor("PosUp") else if two_daysPosDn then globalColor("PosDn") else if two_daysNegDn then globalColor("NegDn") else if two_daysNegUp then globalColor("NegUp") else globalColor("Neutral"));


def Dayprice;
def KDay;
def Daymomo;
Def Day_ExpAverage;
Def Daypos;
Def Dayneg;
Def Dayup;
Def Daydn;
Def DayPosUp;
Def DayPosDn;
Def DayNegDn;
Def DayNegUp;
Def DayAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Day {
    Dayprice = close(period="Day");
    KDay = (Highest(high(period="Day"), length) + Lowest(low(period="Day"), length)) /2 + ExpAverage(close(period="Day"), length);
    Daymomo = Inertia(Dayprice- kDay / 2, length);
    Day_ExpAverage = ExpAverage(close(period="Day"), Length);
    Daypos = Daymomo >= 0;
    Dayneg = Daymomo < 0;
    Dayup  = Daymomo >= Daymomo[1];
    Daydn  = Daymomo < Daymomo[1];

    DayPosUp = Daypos and Dayup;
    DayPosDn = Daypos and Daydn;
    DayNegDn = Dayneg and Daydn;
    DayNegUp = Dayneg and Dayup;
    DayAggregationPeriod = 1;
}
Else {
    Dayprice = 0;
    KDay = 0;
    Daymomo = 0;
    Day_ExpAverage = 0;
    Daypos = 0;
    Dayneg = 0;
    Dayup = 0;
    Daydn = 0;
    DayPosUp = 0;
    DayPosDn = 0;
    DayNegDn = 0;
    DayNegUp = 0;
    DayAggregationPeriod = 0;
}
AddLabel(DayLabel and DayAggregationPeriod, "D", if DayPosUp then globalColor("PosUp") else if DayPosDn then globalColor("PosDn") else if DayNegDn then globalColor("NegDn") else if DayNegUp then globalColor("NegUp") else globalColor("Neutral"));


def four_hoursprice;
def Kfour_hours;
def four_hoursmomo;
Def four_hours_ExpAverage;
Def four_hourspos;
Def four_hoursneg;
Def four_hoursup;
Def four_hoursdn;
Def four_hoursPosUp;
Def four_hoursPosDn;
Def four_hoursNegDn;
Def four_hoursNegUp;
Def four_hoursAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_hours {
    four_hoursprice = close(period="4 Hours");
    Kfour_hours = (Highest(high(period="4 Hours"), length) + Lowest(low(period="4 Hours"), length)) /2 + ExpAverage(close(period="4 Hours"), length);
    four_hoursmomo = Inertia(four_hoursprice- kfour_hours / 2, length);
    four_hours_ExpAverage = ExpAverage(close(period="4 Hours"), Length);
    four_hourspos = four_hoursmomo >= 0;
    four_hoursneg = four_hoursmomo < 0;
    four_hoursup  = four_hoursmomo >= four_hoursmomo[1];
    four_hoursdn  = four_hoursmomo < four_hoursmomo[1];

    four_hoursPosUp = four_hourspos and four_hoursup;
    four_hoursPosDn = four_hourspos and four_hoursdn;
    four_hoursNegDn = four_hoursneg and four_hoursdn;
    four_hoursNegUp = four_hoursneg and four_hoursup;
    four_hoursAggregationPeriod = 1;
}
Else {
    four_hoursprice = 0;
    Kfour_hours = 0;
    four_hoursmomo = 0;
    four_hours_ExpAverage = 0;
    four_hourspos = 0;
    four_hoursneg = 0;
    four_hoursup = 0;
    four_hoursdn = 0;
    four_hoursPosUp = 0;
    four_hoursPosDn = 0;
    four_hoursNegDn = 0;
    four_hoursNegUp = 0;
    four_hoursAggregationPeriod = 0;
}
AddLabel(FourHourLabel and four_hoursAggregationPeriod, "4h", if four_hoursPosUp then globalColor("PosUp") else if four_hoursPosDn then globalColor("PosDn") else if four_hoursNegDn then globalColor("NegDn") else if four_hoursNegUp then globalColor("NegUp") else globalColor("Neutral"));



def two_hoursprice;
def Ktwo_hours;
def two_hoursmomo;
Def two_hours_ExpAverage;
Def two_hourspos;
Def two_hoursneg;
Def two_hoursup;
Def two_hoursdn;
Def two_hoursPosUp;
Def two_hoursPosDn;
Def two_hoursNegDn;
Def two_hoursNegUp;
Def two_hoursAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_hours {
    two_hoursprice = close(period="2 Hours");
    Ktwo_hours = (Highest(high(period="2 Hours"), length) + Lowest(low(period="2 Hours"), length)) /2 + ExpAverage(close(period="2 Hours"), length);
    two_hoursmomo = Inertia(two_hoursprice- ktwo_hours / 2, length);
    two_hours_ExpAverage = ExpAverage(close(period="2 Hours"), Length);
    two_hourspos = two_hoursmomo >= 0;
    two_hoursneg = two_hoursmomo < 0;
    two_hoursup  = two_hoursmomo >= two_hoursmomo[1];
    two_hoursdn  = two_hoursmomo < two_hoursmomo[1];

    two_hoursPosUp = two_hourspos and two_hoursup;
    two_hoursPosDn = two_hourspos and two_hoursdn;
    two_hoursNegDn = two_hoursneg and two_hoursdn;
    two_hoursNegUp = two_hoursneg and two_hoursup;
    two_hoursAggregationPeriod = 1;
}
Else {
    two_hoursprice = 0;
    Ktwo_hours = 0;
    two_hoursmomo = 0;
    two_hours_ExpAverage = 0;
    two_hourspos = 0;
    two_hoursneg = 0;
    two_hoursup = 0;
    two_hoursdn = 0;
    two_hoursPosUp = 0;
    two_hoursPosDn = 0;
    two_hoursNegDn = 0;
    two_hoursNegUp = 0;
    two_hoursAggregationPeriod = 0;
}
AddLabel(TwoHourLabel and two_hoursAggregationPeriod, "2h", if two_hoursPosUp then globalColor("PosUp") else if two_hoursPosDn then globalColor("PosDn") else if two_hoursNegDn then globalColor("NegDn") else if two_hoursNegUp then globalColor("NegUp") else globalColor("Neutral"));



def hourprice;
def Khour;
def hourmomo;
Def hour_ExpAverage;
Def hourpos;
Def hourneg;
Def hourup;
Def hourdn;
Def hourPosUp;
Def hourPosDn;
Def hourNegDn;
Def hourNegUp;
Def hourAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.hour {
    hourprice = close(period="1 Hour");
    Khour = (Highest(high(period="1 Hour"), length) + Lowest(low(period="1 Hour"), length)) /2 + ExpAverage(close(period="1 Hour"), length);
    hourmomo = Inertia(hourprice- khour / 2, length);
    hour_ExpAverage = ExpAverage(close(period="1 Hour"), Length);
    hourpos = hourmomo >= 0;
    hourneg = hourmomo < 0;
    hourup  = hourmomo >= hourmomo[1];
    hourdn  = hourmomo < hourmomo[1];

    hourPosUp = hourpos and hourup;
    hourPosDn = hourpos and hourdn;
    hourNegDn = hourneg and hourdn;
    hourNegUp = hourneg and hourup;
    hourAggregationPeriod = 1;
}
Else {
    hourprice = 0;
    Khour = 0;
    hourmomo = 0;
    hour_ExpAverage = 0;
    hourpos = 0;
    hourneg = 0;
    hourup = 0;
    hourdn = 0;
    hourPosUp = 0;
    hourPosDn = 0;
    hourNegDn = 0;
    hourNegUp = 0;
    hourAggregationPeriod = 0;
}
AddLabel(OneHourLabel and hourAggregationPeriod, "1h", if hourPosUp then globalColor("PosUp") else if hourPosDn then globalColor("PosDn") else if hourNegDn then globalColor("NegDn") else if hourNegUp then globalColor("NegUp") else globalColor("Neutral"));



def thirty_minprice;
def Kthirty_min;
def thirty_minmomo;
Def thirty_min_ExpAverage;
Def thirty_minpos;
Def thirty_minneg;
Def thirty_minup;
Def thirty_mindn;
Def thirty_minPosUp;
Def thirty_minPosDn;
Def thirty_minNegDn;
Def thirty_minNegUp;
Def thirty_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.thirty_min {
    thirty_minprice = close(period="30 Min");
    Kthirty_min = (Highest(high(period="30 Min"), length) + Lowest(low(period="30 Min"), length)) /2 + ExpAverage(close(period="30 Min"), length);
    thirty_minmomo = Inertia(thirty_minprice- kthirty_min / 2, length);
    thirty_min_ExpAverage = ExpAverage(close(period="30 Min"), Length);
    thirty_minpos = thirty_minmomo >= 0;
    thirty_minneg = thirty_minmomo < 0;
    thirty_minup  = thirty_minmomo >= thirty_minmomo[1];
    thirty_mindn  = thirty_minmomo < thirty_minmomo[1];

    thirty_minPosUp = thirty_minpos and thirty_minup;
    thirty_minPosDn = thirty_minpos and thirty_mindn;
    thirty_minNegDn = thirty_minneg and thirty_mindn;
    thirty_minNegUp = thirty_minneg and thirty_minup;
    thirty_minAggregationPeriod = 1;
}
Else {
    thirty_minprice = 0;
    Kthirty_min = 0;
    thirty_minmomo = 0;
    thirty_min_ExpAverage = 0;
    thirty_minpos = 0;
    thirty_minneg = 0;
    thirty_minup = 0;
    thirty_mindn = 0;
    thirty_minPosUp = 0;
    thirty_minPosDn = 0;
    thirty_minNegDn = 0;
    thirty_minNegUp = 0;
    thirty_minAggregationPeriod = 0;
}
AddLabel(ThirtyMinLabel and thirty_minAggregationPeriod, "30m", if thirty_minPosUp then globalColor("PosUp") else if thirty_minPosDn then globalColor("PosDn") else if thirty_minNegDn then globalColor("NegDn") else if thirty_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def twenty_minprice;
def Ktwenty_min;
def twenty_minmomo;
Def twenty_min_ExpAverage;
Def twenty_minpos;
Def twenty_minneg;
Def twenty_minup;
Def twenty_mindn;
Def twenty_minPosUp;
Def twenty_minPosDn;
Def twenty_minNegDn;
Def twenty_minNegUp;
Def twenty_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.twenty_min {
    twenty_minprice = close(period="20 Min");
    Ktwenty_min = (Highest(high(period="20 Min"), length) + Lowest(low(period="20 Min"), length)) /2 + ExpAverage(close(period="20 Min"), length);
    twenty_minmomo = Inertia(twenty_minprice- ktwenty_min / 2, length);
    twenty_min_ExpAverage = ExpAverage(close(period="20 Min"), Length);
    twenty_minpos = twenty_minmomo >= 0;
    twenty_minneg = twenty_minmomo < 0;
    twenty_minup  = twenty_minmomo >= twenty_minmomo[1];
    twenty_mindn  = twenty_minmomo < twenty_minmomo[1];

    twenty_minPosUp = twenty_minpos and twenty_minup;
    twenty_minPosDn = twenty_minpos and twenty_mindn;
    twenty_minNegDn = twenty_minneg and twenty_mindn;
    twenty_minNegUp = twenty_minneg and twenty_minup;
    twenty_minAggregationPeriod = 1;
}
Else {
    twenty_minprice = 0;
    Ktwenty_min = 0;
    twenty_minmomo = 0;
    twenty_min_ExpAverage = 0;
    twenty_minpos = 0;
    twenty_minneg = 0;
    twenty_minup = 0;
    twenty_mindn = 0;
    twenty_minPosUp = 0;
    twenty_minPosDn = 0;
    twenty_minNegDn = 0;
    twenty_minNegUp = 0;
    twenty_minAggregationPeriod = 0;
}
AddLabel(TwentyMinLabel and twenty_minAggregationPeriod, "20m", if twenty_minPosUp then globalColor("PosUp") else if twenty_minPosDn then globalColor("PosDn") else if twenty_minNegDn then globalColor("NegDn") else if twenty_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def fifteen_minprice;
def Kfifteen_min;
def fifteen_minmomo;
Def fifteen_min_ExpAverage;
Def fifteen_minpos;
Def fifteen_minneg;
Def fifteen_minup;
Def fifteen_mindn;
Def fifteen_minPosUp;
Def fifteen_minPosDn;
Def fifteen_minNegDn;
Def fifteen_minNegUp;
Def fifteen_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.fifteen_min {
    fifteen_minprice = close(period="15 Min");
    Kfifteen_min = (Highest(high(period="15 Min"), length) + Lowest(low(period="15 Min"), length)) /2 + ExpAverage(close(period="15 Min"), length);
    fifteen_minmomo = Inertia(fifteen_minprice- kfifteen_min / 2, length);
    fifteen_min_ExpAverage = ExpAverage(close(period="15 Min"), Length);
    fifteen_minpos = fifteen_minmomo >= 0;
    fifteen_minneg = fifteen_minmomo < 0;
    fifteen_minup  = fifteen_minmomo >= fifteen_minmomo[1];
    fifteen_mindn  = fifteen_minmomo < fifteen_minmomo[1];

    fifteen_minPosUp = fifteen_minpos and fifteen_minup;
    fifteen_minPosDn = fifteen_minpos and fifteen_mindn;
    fifteen_minNegDn = fifteen_minneg and fifteen_mindn;
    fifteen_minNegUp = fifteen_minneg and fifteen_minup;
    fifteen_minAggregationPeriod = 1;
}
Else {
    fifteen_minprice = 0;
    Kfifteen_min = 0;
    fifteen_minmomo = 0;
    fifteen_min_ExpAverage = 0;
    fifteen_minpos = 0;
    fifteen_minneg = 0;
    fifteen_minup = 0;
    fifteen_mindn = 0;
    fifteen_minPosUp = 0;
    fifteen_minPosDn = 0;
    fifteen_minNegDn = 0;
    fifteen_minNegUp = 0;
    fifteen_minAggregationPeriod = 0;
}
AddLabel(FifteenMinLabel and fifteen_minAggregationPeriod, "15m", if fifteen_minPosUp then globalColor("PosUp") else if fifteen_minPosDn then globalColor("PosDn") else if fifteen_minNegDn then globalColor("NegDn") else if fifteen_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def ten_minprice;
def Kten_min;
def ten_minmomo;
Def ten_min_ExpAverage;
Def ten_minpos;
Def ten_minneg;
Def ten_minup;
Def ten_mindn;
Def ten_minPosUp;
Def ten_minPosDn;
Def ten_minNegDn;
Def ten_minNegUp;
Def ten_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.ten_min {
    ten_minprice = close(period="10 Min");
    Kten_min = (Highest(high(period="10 Min"), length) + Lowest(low(period="10 Min"), length)) /2 + ExpAverage(close(period="10 Min"), length);
    ten_minmomo = Inertia(ten_minprice- kten_min / 2, length);
    ten_min_ExpAverage = ExpAverage(close(period="10 Min"), Length);
    ten_minpos = ten_minmomo >= 0;
    ten_minneg = ten_minmomo < 0;
    ten_minup  = ten_minmomo >= ten_minmomo[1];
    ten_mindn  = ten_minmomo < ten_minmomo[1];

    ten_minPosUp = ten_minpos and ten_minup;
    ten_minPosDn = ten_minpos and ten_mindn;
    ten_minNegDn = ten_minneg and ten_mindn;
    ten_minNegUp = ten_minneg and ten_minup;
    ten_minAggregationPeriod = 1;
}
Else {
    ten_minprice = 0;
    Kten_min = 0;
    ten_minmomo = 0;
    ten_min_ExpAverage = 0;
    ten_minpos = 0;
    ten_minneg = 0;
    ten_minup = 0;
    ten_mindn = 0;
    ten_minPosUp = 0;
    ten_minPosDn = 0;
    ten_minNegDn = 0;
    ten_minNegUp = 0;
    ten_minAggregationPeriod = 0;
}
AddLabel(TenMinLabel and ten_minAggregationPeriod, "10m", if ten_minPosUp then globalColor("PosUp") else if ten_minPosDn then globalColor("PosDn") else if ten_minNegDn then globalColor("NegDn") else if ten_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def five_minprice;
def Kfive_min;
def five_minmomo;
Def five_min_ExpAverage;
Def five_minpos;
Def five_minneg;
Def five_minup;
Def five_mindn;
Def five_minPosUp;
Def five_minPosDn;
Def five_minNegDn;
Def five_minNegUp;
Def five_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.five_min {
    five_minprice = close(period="5 Min");
    Kfive_min = (Highest(high(period="5 Min"), length) + Lowest(low(period="5 Min"), length)) /2 + ExpAverage(close(period="5 Min"), length);
    five_minmomo = Inertia(five_minprice- kfive_min / 2, length);
    five_min_ExpAverage = ExpAverage(close(period="5 Min"), Length);
    five_minpos = five_minmomo >= 0;
    five_minneg = five_minmomo < 0;
    five_minup  = five_minmomo >= five_minmomo[1];
    five_mindn  = five_minmomo < five_minmomo[1];

    five_minPosUp = five_minpos and five_minup;
    five_minPosDn = five_minpos and five_mindn;
    five_minNegDn = five_minneg and five_mindn;
    five_minNegUp = five_minneg and five_minup;
    five_minAggregationPeriod = 1;
}
Else {
    five_minprice = 0;
    Kfive_min = 0;
    five_minmomo = 0;
    five_min_ExpAverage = 0;
    five_minpos = 0;
    five_minneg = 0;
    five_minup = 0;
    five_mindn = 0;
    five_minPosUp = 0;
    five_minPosDn = 0;
    five_minNegDn = 0;
    five_minNegUp = 0;
    five_minAggregationPeriod = 0;
}
AddLabel(FiveMinLabel and five_minAggregationPeriod, "5m", if five_minPosUp then globalColor("PosUp") else if five_minPosDn then globalColor("PosDn") else if five_minNegDn then globalColor("NegDn") else if five_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def four_minprice;
def Kfour_min;
def four_minmomo;
Def four_min_ExpAverage;
Def four_minpos;
Def four_minneg;
Def four_minup;
Def four_mindn;
Def four_minPosUp;
Def four_minPosDn;
Def four_minNegDn;
Def four_minNegUp;
Def four_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_min {
    four_minprice = close(period="4 Min");
    Kfour_min = (Highest(high(period="4 Min"), length) + Lowest(low(period="4 Min"), length)) /2 + ExpAverage(close(period="4 Min"), length);
    four_minmomo = Inertia(four_minprice- kfour_min / 2, length);
    four_min_ExpAverage = ExpAverage(close(period="4 Min"), Length);
    four_minpos = four_minmomo >= 0;
    four_minneg = four_minmomo < 0;
    four_minup  = four_minmomo >= four_minmomo[1];
    four_mindn  = four_minmomo < four_minmomo[1];

    four_minPosUp = four_minpos and four_minup;
    four_minPosDn = four_minpos and four_mindn;
    four_minNegDn = four_minneg and four_mindn;
    four_minNegUp = four_minneg and four_minup;
    four_minAggregationPeriod = 1;
}
Else {
    four_minprice = 0;
    Kfour_min = 0;
    four_minmomo = 0;
    four_min_ExpAverage = 0;
    four_minpos = 0;
    four_minneg = 0;
    four_minup = 0;
    four_mindn = 0;
    four_minPosUp = 0;
    four_minPosDn = 0;
    four_minNegDn = 0;
    four_minNegUp = 0;
    four_minAggregationPeriod = 0;
}
AddLabel(FourMinLabel and four_minAggregationPeriod, "4m", if four_minPosUp then globalColor("PosUp") else if four_minPosDn then globalColor("PosDn") else if four_minNegDn then globalColor("NegDn") else if four_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def three_minprice;
def Kthree_min;
def three_minmomo;
Def three_min_ExpAverage;
Def three_minpos;
Def three_minneg;
Def three_minup;
Def three_mindn;
Def three_minPosUp;
Def three_minPosDn;
Def three_minNegDn;
Def three_minNegUp;
Def three_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.three_min {
    three_minprice = close(period="3 Min");
    Kthree_min = (Highest(high(period="3 Min"), length) + Lowest(low(period="3 Min"), length)) /2 + ExpAverage(close(period="3 Min"), length);
    three_minmomo = Inertia(three_minprice- kthree_min / 2, length);
    three_min_ExpAverage = ExpAverage(close(period="3 Min"), Length);
    three_minpos = three_minmomo >= 0;
    three_minneg = three_minmomo < 0;
    three_minup  = three_minmomo >= three_minmomo[1];
    three_mindn  = three_minmomo < three_minmomo[1];

    three_minPosUp = three_minpos and three_minup;
    three_minPosDn = three_minpos and three_mindn;
    three_minNegDn = three_minneg and three_mindn;
    three_minNegUp = three_minneg and three_minup;
    three_minAggregationPeriod = 1;
}
Else {
    three_minprice = 0;
    Kthree_min = 0;
    three_minmomo = 0;
    three_min_ExpAverage = 0;
    three_minpos = 0;
    three_minneg = 0;
    three_minup = 0;
    three_mindn = 0;
    three_minPosUp = 0;
    three_minPosDn = 0;
    three_minNegDn = 0;
    three_minNegUp = 0;
    three_minAggregationPeriod = 0;
}
AddLabel(ThreeMinLabel and three_minAggregationPeriod, "3m", if three_minPosUp then globalColor("PosUp") else if three_minPosDn then globalColor("PosDn") else if three_minNegDn then globalColor("NegDn") else if three_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def two_minprice;
def Ktwo_min;
def two_minmomo;
Def two_min_ExpAverage;
Def two_minpos;
Def two_minneg;
Def two_minup;
Def two_mindn;
Def two_minPosUp;
Def two_minPosDn;
Def two_minNegDn;
Def two_minNegUp;
Def two_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_min {
    two_minprice = close(period="2 Min");
    Ktwo_min = (Highest(high(period="2 Min"), length) + Lowest(low(period="2 Min"), length)) /2 + ExpAverage(close(period="2 Min"), length);
    two_minmomo = Inertia(two_minprice- ktwo_min / 2, length);
    two_min_ExpAverage = ExpAverage(close(period="2 Min"), Length);
    two_minpos = two_minmomo >= 0;
    two_minneg = two_minmomo < 0;
    two_minup  = two_minmomo >= two_minmomo[1];
    two_mindn  = two_minmomo < two_minmomo[1];

    two_minPosUp = two_minpos and two_minup;
    two_minPosDn = two_minpos and two_mindn;
    two_minNegDn = two_minneg and two_mindn;
    two_minNegUp = two_minneg and two_minup;
    two_minAggregationPeriod = 1;
}
Else {
    two_minprice = 0;
    Ktwo_min = 0;
    two_minmomo = 0;
    two_min_ExpAverage = 0;
    two_minpos = 0;
    two_minneg = 0;
    two_minup = 0;
    two_mindn = 0;
    two_minPosUp = 0;
    two_minPosDn = 0;
    two_minNegDn = 0;
    two_minNegUp = 0;
    two_minAggregationPeriod = 0;
}
AddLabel(TwoMinLabel and two_minAggregationPeriod, "2m", if two_minPosUp then globalColor("PosUp") else if two_minPosDn then globalColor("PosDn") else if two_minNegDn then globalColor("NegDn") else if two_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def one_minprice;
def Kone_min;
def one_minmomo;
Def one_min_ExpAverage;
Def one_minpos;
Def one_minneg;
Def one_minup;
Def one_mindn;
Def one_minPosUp;
Def one_minPosDn;
Def one_minNegDn;
Def one_minNegUp;
Def one_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Min {
    one_minprice = close(period="1 Min");
    Kone_min = (Highest(high(period="1 Min"), length) + Lowest(low(period="1 Min"), length)) /2 + ExpAverage(close(period="1 Min"), length);
    one_minmomo = Inertia(one_minprice- kone_min / 2, length);
    one_min_ExpAverage = ExpAverage(close(period="1 Min"), Length);
    one_minpos = one_minmomo >= 0;
    one_minneg = one_minmomo < 0;
    one_minup  = one_minmomo >= one_minmomo[1];
    one_mindn  = one_minmomo < one_minmomo[1];

    one_minPosUp = one_minpos and one_minup;
    one_minPosDn = one_minpos and one_mindn;
    one_minNegDn = one_minneg and one_mindn;
    one_minNegUp = one_minneg and one_minup;
    one_minAggregationPeriod = 1;
}
Else {
    one_minprice = 0;
    Kone_min = 0;
    one_minmomo = 0;
    one_min_ExpAverage = 0;
    one_minpos = 0;
    one_minneg = 0;
    one_minup = 0;
    one_mindn = 0;
    one_minPosUp = 0;
    one_minPosDn = 0;
    one_minNegDn = 0;
    one_minNegUp = 0;
    one_minAggregationPeriod = 0;
}
AddLabel(OneMinLabel and one_minAggregationPeriod, "1m", if one_minPosUp then globalColor("PosUp") else if one_minPosDn then globalColor("PosDn") else if one_minNegDn then globalColor("NegDn") else if one_minNegUp then globalColor("NegUp") else globalColor("Neutral"));

2gyx1Se.png
 
Last edited:

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

For anybody interested, here is the script for the MTF Squeeze Histogram Colored Labels I wrote. It's identical to the new "Simpler Trading" indicator. I'm not sure if there are any parts of the script that aren't necessary. Regardless, it functions as it should. Any comments, corrections, and/or constructive criticism are welcomed. I hope somebody else finds this script helpful!


Code:
##MTF Squeeze Histogram Labels
##Created By: Casey Brett
##Global Variables

input price = close;
input length = 20;
input averageType = AverageType.EXPONENTIAL;
input displace = 0;

def K = (Highest(high, length) + Lowest(low, length)) /2 + ExpAverage(close, length);
def momo = Inertia(price - K / 2, length);

def pos         = momo >= 0;
def neg         = momo < 0;
def up         = momo >= momo[1];
def dn         = momo < momo[1];

def PosUp = pos and up;
def PosDn = pos and dn;
def NegDn = neg and dn;
def NegUp = neg and up;

defineGlobalColor("Month PosUp", color.cyan);
defineGlobalColor("Month PosDn", color.blue);
defineGlobalColor("Month NegDn", color.red);
defineGlobalColor("Month NegUp", color.yellow);
defineGlobalColor("Month Neutral", color.gray);
defineGlobalColor("Week PosUp", color.cyan);
defineGlobalColor("Week PosDn", color.blue);
defineGlobalColor("Week NegDn", color.red);
defineGlobalColor("Week NegUp", color.yellow);
defineGlobalColor("Week Neutral", color.gray);
defineGlobalColor("four_days PosUp", color.cyan);
defineGlobalColor("four_days PosDn", color.blue);
defineGlobalColor("four_days NegDn", color.red);
defineGlobalColor("four_days NegUp", color.yellow);
defineGlobalColor("four_days Neutral", color.gray);
defineGlobalColor("three_days PosUp", color.cyan);
defineGlobalColor("three_days PosDn", color.blue);
defineGlobalColor("three_days NegDn", color.red);
defineGlobalColor("three_days NegUp", color.yellow);
defineGlobalColor("three_days Neutral", color.gray);
defineGlobalColor("two_days PosUp", color.cyan);
defineGlobalColor("two_days PosDn", color.blue);
defineGlobalColor("two_days NegDn", color.red);
defineGlobalColor("two_days NegUp", color.yellow);
defineGlobalColor("two_days Neutral", color.gray);
defineGlobalColor("Day PosUp", color.cyan);
defineGlobalColor("Day PosDn", color.blue);
defineGlobalColor("Day NegDn", color.red);
defineGlobalColor("Day NegUp", color.yellow);
defineGlobalColor("Day Neutral", color.gray);
defineGlobalColor("four_hours PosUp", color.cyan);
defineGlobalColor("four_hours PosDn", color.blue);
defineGlobalColor("four_hours NegDn", color.red);
defineGlobalColor("four_hours NegUp", color.yellow);
defineGlobalColor("four_hours Neutral", color.gray);
defineGlobalColor("two_hours PosUp", color.cyan);
defineGlobalColor("two_hours PosDn", color.blue);
defineGlobalColor("two_hours NegDn", color.red);
defineGlobalColor("two_hours NegUp", color.yellow);
defineGlobalColor("two_hours Neutral", color.gray);
defineGlobalColor("hour PosUp", color.cyan);
defineGlobalColor("hour PosDn", color.blue);
defineGlobalColor("hour NegDn", color.red);
defineGlobalColor("hour NegUp", color.yellow);
defineGlobalColor("hour Neutral", color.gray);
defineGlobalColor("thirty_min PosUp", color.cyan);
defineGlobalColor("thirty_min PosDn", color.blue);
defineGlobalColor("thirty_min NegDn", color.red);
defineGlobalColor("thirty_min NegUp", color.yellow);
defineGlobalColor("thirty_min Neutral", color.gray);
defineGlobalColor("twenty_min PosUp", color.cyan);
defineGlobalColor("twenty_min PosDn", color.blue);
defineGlobalColor("twenty_min NegDn", color.red);
defineGlobalColor("twenty_min NegUp", color.yellow);
defineGlobalColor("twenty_min Neutral", color.gray);
defineGlobalColor("fifteen_min PosUp", color.cyan);
defineGlobalColor("fifteen_min PosDn", color.blue);
defineGlobalColor("fifteen_min NegDn", color.red);
defineGlobalColor("fifteen_min NegUp", color.yellow);
defineGlobalColor("fifteen_min Neutral", color.gray);
defineGlobalColor("ten_min PosUp", color.cyan);
defineGlobalColor("ten_min PosDn", color.blue);
defineGlobalColor("ten_min NegDn", color.red);
defineGlobalColor("ten_min NegUp", color.yellow);
defineGlobalColor("ten_min Neutral", color.gray);
defineGlobalColor("five_min PosUp", color.cyan);
defineGlobalColor("five_min PosDn", color.blue);
defineGlobalColor("five_min NegDn", color.red);
defineGlobalColor("five_min NegUp", color.yellow);
defineGlobalColor("five_min Neutral", color.gray);
defineGlobalColor("four_min PosUp", color.cyan);
defineGlobalColor("four_min PosDn", color.blue);
defineGlobalColor("four_min NegDn", color.red);
defineGlobalColor("four_min NegUp", color.yellow);
defineGlobalColor("four_min Neutral", color.gray);
defineGlobalColor("three_min PosUp", color.cyan);
defineGlobalColor("three_min PosDn", color.blue);
defineGlobalColor("three_min NegDn", color.red);
defineGlobalColor("three_min NegUp", color.yellow);
defineGlobalColor("three_min Neutral", color.gray);
defineGlobalColor("two_min PosUp", color.cyan);
defineGlobalColor("two_min PosDn", color.blue);
defineGlobalColor("two_min NegDn", color.red);
defineGlobalColor("two_min NegUp", color.yellow);
defineGlobalColor("two_min Neutral", color.gray);
defineGlobalColor("one_min PosUp", color.cyan);
defineGlobalColor("one_min PosDn", color.blue);
defineGlobalColor("one_min NegDn", color.red);
defineGlobalColor("one_min NegUp", color.yellow);
defineGlobalColor("one_min Neutral", color.gray);


def monthprice;
def Kmonth;
def monthmomo;
Def Month_ExpAverage;
Def monthpos;
Def monthneg;
Def monthup;
Def monthdn;
Def monthPosUp;
Def monthPosDn;
Def monthNegDn;
Def monthNegUp;
Def monthAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Month {
    monthprice = close(period="Month");
    Kmonth = (Highest(high(period="Month"), length) + Lowest(low(period="Month"), length)) /2 + ExpAverage(close(period="Month"), length);
    monthmomo = Inertia(monthprice- kmonth / 2, length);
    Month_ExpAverage = ExpAverage(close(period="Month"), Length);
    monthpos = monthmomo >= 0;
    monthneg = monthmomo < 0;
    monthup  = monthmomo >= monthmomo[1];
    monthdn  = monthmomo < monthmomo[1];

    monthPosUp = monthpos and monthup;
    monthPosDn = monthpos and monthdn;
    monthNegDn = monthneg and monthdn;
    monthNegUp = monthneg and monthup;
    monthAggregationPeriod = 1;
}
Else {
    monthprice = 0;
    Kmonth = 0;
    monthmomo = 0;
    Month_ExpAverage = 0;
    monthpos = 0;
    monthneg = 0;
    monthup = 0;
    monthdn = 0;
    monthPosUp = 0;
    monthPosDn = 0;
    monthNegDn = 0;
    monthNegUp = 0;
    monthAggregationPeriod = 0;
}
AddLabel(monthAggregationPeriod, "M", if monthPosUp then globalColor("Month PosUp") else if monthPosDn then globalColor("Month PosDn") else if monthNegDn then globalColor("Month NegDn") else if monthNegUp then globalColor("Month NegUp") else globalColor("Month Neutral"));

def Weekprice;
def KWeek;
def Weekmomo;
Def Week_ExpAverage;
Def Weekpos;
Def Weekneg;
Def Weekup;
Def Weekdn;
Def WeekPosUp;
Def WeekPosDn;
Def WeekNegDn;
Def WeekNegUp;
Def WeekAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Week {
    Weekprice = close(period="Week");
    KWeek = (Highest(high(period="Week"), length) + Lowest(low(period="Week"), length)) /2 + ExpAverage(close(period="week"), length);
    Weekmomo = Inertia(Weekprice- kWeek / 2, length);
    Week_ExpAverage = ExpAverage(close(period="Week"), Length);
    Weekpos = Weekmomo >= 0;
    Weekneg = Weekmomo < 0;
    Weekup  = Weekmomo >= Weekmomo[1];
    Weekdn  = Weekmomo < Weekmomo[1];

    WeekPosUp = Weekpos and Weekup;
    WeekPosDn = Weekpos and Weekdn;
    WeekNegDn = Weekneg and Weekdn;
    WeekNegUp = Weekneg and Weekup;
    WeekAggregationPeriod = 1;
}
Else {
    Weekprice = 0;
    KWeek = 0;
    Weekmomo = 0;
    Week_ExpAverage = 0;
    Weekpos = 0;
    Weekneg = 0;
    Weekup = 0;
    Weekdn = 0;
    WeekPosUp = 0;
    WeekPosDn = 0;
    WeekNegDn = 0;
    WeekNegUp = 0;
    WeekAggregationPeriod = 0;
}
AddLabel(WeekAggregationPeriod, "W", if WeekPosUp then globalColor("Week PosUp") else if WeekPosDn then globalColor("Week PosDn") else if WeekNegDn then globalColor("Week NegDn") else if WeekNegUp then globalColor("Week NegUp") else globalColor("Week Neutral"));


def four_daysprice;
def Kfour_days;
def four_daysmomo;
Def four_days_ExpAverage;
Def four_dayspos;
Def four_daysneg;
Def four_daysup;
Def four_daysdn;
Def four_daysPosUp;
Def four_daysPosDn;
Def four_daysNegDn;
Def four_daysNegUp;
Def four_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_days {
    four_daysprice = close(period="4 Days");
    Kfour_days = (Highest(high(period="4 Days"), length) + Lowest(low(period="4 Days"), length)) /2 + ExpAverage(close(period="4 Days"), length);
    four_daysmomo = Inertia(four_daysprice- kfour_days / 2, length);
    four_days_ExpAverage = ExpAverage(close(period="4 Days"), Length);
    four_dayspos = four_daysmomo >= 0;
    four_daysneg = four_daysmomo < 0;
    four_daysup  = four_daysmomo >= four_daysmomo[1];
    four_daysdn  = four_daysmomo < four_daysmomo[1];

    four_daysPosUp = four_dayspos and four_daysup;
    four_daysPosDn = four_dayspos and four_daysdn;
    four_daysNegDn = four_daysneg and four_daysdn;
    four_daysNegUp = four_daysneg and four_daysup;
    four_daysAggregationPeriod = 1;
}
Else {
    four_daysprice = 0;
    Kfour_days = 0;
    four_daysmomo = 0;
    four_days_ExpAverage = 0;
    four_dayspos = 0;
    four_daysneg = 0;
    four_daysup = 0;
    four_daysdn = 0;
    four_daysPosUp = 0;
    four_daysPosDn = 0;
    four_daysNegDn = 0;
    four_daysNegUp = 0;
    four_daysAggregationPeriod = 0;
}
AddLabel(four_daysAggregationPeriod, "4D", if four_daysPosUp then globalColor("four_days PosUp") else if four_daysPosDn then globalColor("four_days PosDn") else if four_daysNegDn then globalColor("four_days NegDn") else if four_daysNegUp then globalColor("four_days NegUp") else globalColor("four_days Neutral"));

def three_daysprice;
def Kthree_days;
def three_daysmomo;
Def three_days_ExpAverage;
Def three_dayspos;
Def three_daysneg;
Def three_daysup;
Def three_daysdn;
Def three_daysPosUp;
Def three_daysPosDn;
Def three_daysNegDn;
Def three_daysNegUp;
Def three_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.three_days {
    three_daysprice = close(period="3 Days");
    Kthree_days = (Highest(high(period="3 Days"), length) + Lowest(low(period="3 Days"), length)) /2 + ExpAverage(close(period="3 Days"), length);
    three_daysmomo = Inertia(three_daysprice- kthree_days / 2, length);
    three_days_ExpAverage = ExpAverage(close(period="3 Days"), Length);
    three_dayspos = three_daysmomo >= 0;
    three_daysneg = three_daysmomo < 0;
    three_daysup  = three_daysmomo >= three_daysmomo[1];
    three_daysdn  = three_daysmomo < three_daysmomo[1];

    three_daysPosUp = three_dayspos and three_daysup;
    three_daysPosDn = three_dayspos and three_daysdn;
    three_daysNegDn = three_daysneg and three_daysdn;
    three_daysNegUp = three_daysneg and three_daysup;
    three_daysAggregationPeriod = 1;
}
Else {
    three_daysprice = 0;
    Kthree_days = 0;
    three_daysmomo = 0;
    three_days_ExpAverage = 0;
    three_dayspos = 0;
    three_daysneg = 0;
    three_daysup = 0;
    three_daysdn = 0;
    three_daysPosUp = 0;
    three_daysPosDn = 0;
    three_daysNegDn = 0;
    three_daysNegUp = 0;
    three_daysAggregationPeriod = 0;
}
AddLabel(three_daysAggregationPeriod, "3D", if three_daysPosUp then globalColor("three_days PosUp") else if three_daysPosDn then globalColor("three_days PosDn") else if three_daysNegDn then globalColor("three_days NegDn") else if three_daysNegUp then globalColor("three_days NegUp") else globalColor("three_days Neutral"));




def two_daysprice;
def Ktwo_days;
def two_daysmomo;
Def two_days_ExpAverage;
Def two_dayspos;
Def two_daysneg;
Def two_daysup;
Def two_daysdn;
Def two_daysPosUp;
Def two_daysPosDn;
Def two_daysNegDn;
Def two_daysNegUp;
Def two_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_days {
    two_daysprice = close(period="2 Days");
    Ktwo_days = (Highest(high(period="2 Days"), length) + Lowest(low(period="2 Days"), length)) /2 + ExpAverage(close(period="2 Days"), length);
    two_daysmomo = Inertia(two_daysprice- ktwo_days / 2, length);
    two_days_ExpAverage = ExpAverage(close(period="2 Days"), Length);
    two_dayspos = two_daysmomo >= 0;
    two_daysneg = two_daysmomo < 0;
    two_daysup  = two_daysmomo >= two_daysmomo[1];
    two_daysdn  = two_daysmomo < two_daysmomo[1];

    two_daysPosUp = two_dayspos and two_daysup;
    two_daysPosDn = two_dayspos and two_daysdn;
    two_daysNegDn = two_daysneg and two_daysdn;
    two_daysNegUp = two_daysneg and two_daysup;
    two_daysAggregationPeriod = 1;
}
Else {
    two_daysprice = 0;
    Ktwo_days = 0;
    two_daysmomo = 0;
    two_days_ExpAverage = 0;
    two_dayspos = 0;
    two_daysneg = 0;
    two_daysup = 0;
    two_daysdn = 0;
    two_daysPosUp = 0;
    two_daysPosDn = 0;
    two_daysNegDn = 0;
    two_daysNegUp = 0;
    two_daysAggregationPeriod = 0;
}
AddLabel(two_daysAggregationPeriod, "2D", if two_daysPosUp then globalColor("two_days PosUp") else if two_daysPosDn then globalColor("two_days PosDn") else if two_daysNegDn then globalColor("two_days NegDn") else if two_daysNegUp then globalColor("two_days NegUp") else globalColor("two_days Neutral"));


def Dayprice;
def KDay;
def Daymomo;
Def Day_ExpAverage;
Def Daypos;
Def Dayneg;
Def Dayup;
Def Daydn;
Def DayPosUp;
Def DayPosDn;
Def DayNegDn;
Def DayNegUp;
Def DayAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Day {
    Dayprice = close(period="Day");
    KDay = (Highest(high(period="Day"), length) + Lowest(low(period="Day"), length)) /2 + ExpAverage(close(period="Day"), length);
    Daymomo = Inertia(Dayprice- kDay / 2, length);
    Day_ExpAverage = ExpAverage(close(period="Day"), Length);
    Daypos = Daymomo >= 0;
    Dayneg = Daymomo < 0;
    Dayup  = Daymomo >= Daymomo[1];
    Daydn  = Daymomo < Daymomo[1];

    DayPosUp = Daypos and Dayup;
    DayPosDn = Daypos and Daydn;
    DayNegDn = Dayneg and Daydn;
    DayNegUp = Dayneg and Dayup;
    DayAggregationPeriod = 1;
}
Else {
    Dayprice = 0;
    KDay = 0;
    Daymomo = 0;
    Day_ExpAverage = 0;
    Daypos = 0;
    Dayneg = 0;
    Dayup = 0;
    Daydn = 0;
    DayPosUp = 0;
    DayPosDn = 0;
    DayNegDn = 0;
    DayNegUp = 0;
    DayAggregationPeriod = 0;
}
AddLabel(DayAggregationPeriod, "D", if DayPosUp then globalColor("Day PosUp") else if DayPosDn then globalColor("Day PosDn") else if DayNegDn then globalColor("Day NegDn") else if DayNegUp then globalColor("Day NegUp") else globalColor("Day Neutral"));


def four_hoursprice;
def Kfour_hours;
def four_hoursmomo;
Def four_hours_ExpAverage;
Def four_hourspos;
Def four_hoursneg;
Def four_hoursup;
Def four_hoursdn;
Def four_hoursPosUp;
Def four_hoursPosDn;
Def four_hoursNegDn;
Def four_hoursNegUp;
Def four_hoursAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_hours {
    four_hoursprice = close(period="4 Hours");
    Kfour_hours = (Highest(high(period="4 Hours"), length) + Lowest(low(period="4 Hours"), length)) /2 + ExpAverage(close(period="4 Hours"), length);
    four_hoursmomo = Inertia(four_hoursprice- kfour_hours / 2, length);
    four_hours_ExpAverage = ExpAverage(close(period="4 Hours"), Length);
    four_hourspos = four_hoursmomo >= 0;
    four_hoursneg = four_hoursmomo < 0;
    four_hoursup  = four_hoursmomo >= four_hoursmomo[1];
    four_hoursdn  = four_hoursmomo < four_hoursmomo[1];

    four_hoursPosUp = four_hourspos and four_hoursup;
    four_hoursPosDn = four_hourspos and four_hoursdn;
    four_hoursNegDn = four_hoursneg and four_hoursdn;
    four_hoursNegUp = four_hoursneg and four_hoursup;
    four_hoursAggregationPeriod = 1;
}
Else {
    four_hoursprice = 0;
    Kfour_hours = 0;
    four_hoursmomo = 0;
    four_hours_ExpAverage = 0;
    four_hourspos = 0;
    four_hoursneg = 0;
    four_hoursup = 0;
    four_hoursdn = 0;
    four_hoursPosUp = 0;
    four_hoursPosDn = 0;
    four_hoursNegDn = 0;
    four_hoursNegUp = 0;
    four_hoursAggregationPeriod = 0;
}
AddLabel(four_hoursAggregationPeriod, "4h", if four_hoursPosUp then globalColor("four_hours PosUp") else if four_hoursPosDn then globalColor("four_hours PosDn") else if four_hoursNegDn then globalColor("four_hours NegDn") else if four_hoursNegUp then globalColor("four_hours NegUp") else globalColor("four_hours Neutral"));



def two_hoursprice;
def Ktwo_hours;
def two_hoursmomo;
Def two_hours_ExpAverage;
Def two_hourspos;
Def two_hoursneg;
Def two_hoursup;
Def two_hoursdn;
Def two_hoursPosUp;
Def two_hoursPosDn;
Def two_hoursNegDn;
Def two_hoursNegUp;
Def two_hoursAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_hours {
    two_hoursprice = close(period="2 Hours");
    Ktwo_hours = (Highest(high(period="2 Hours"), length) + Lowest(low(period="2 Hours"), length)) /2 + ExpAverage(close(period="2 Hours"), length);
    two_hoursmomo = Inertia(two_hoursprice- ktwo_hours / 2, length);
    two_hours_ExpAverage = ExpAverage(close(period="2 Hours"), Length);
    two_hourspos = two_hoursmomo >= 0;
    two_hoursneg = two_hoursmomo < 0;
    two_hoursup  = two_hoursmomo >= two_hoursmomo[1];
    two_hoursdn  = two_hoursmomo < two_hoursmomo[1];

    two_hoursPosUp = two_hourspos and two_hoursup;
    two_hoursPosDn = two_hourspos and two_hoursdn;
    two_hoursNegDn = two_hoursneg and two_hoursdn;
    two_hoursNegUp = two_hoursneg and two_hoursup;
    two_hoursAggregationPeriod = 1;
}
Else {
    two_hoursprice = 0;
    Ktwo_hours = 0;
    two_hoursmomo = 0;
    two_hours_ExpAverage = 0;
    two_hourspos = 0;
    two_hoursneg = 0;
    two_hoursup = 0;
    two_hoursdn = 0;
    two_hoursPosUp = 0;
    two_hoursPosDn = 0;
    two_hoursNegDn = 0;
    two_hoursNegUp = 0;
    two_hoursAggregationPeriod = 0;
}
AddLabel(two_hoursAggregationPeriod, "2h", if two_hoursPosUp then globalColor("two_hours PosUp") else if two_hoursPosDn then globalColor("two_hours PosDn") else if two_hoursNegDn then globalColor("two_hours NegDn") else if two_hoursNegUp then globalColor("two_hours NegUp") else globalColor("two_hours Neutral"));



def hourprice;
def Khour;
def hourmomo;
Def hour_ExpAverage;
Def hourpos;
Def hourneg;
Def hourup;
Def hourdn;
Def hourPosUp;
Def hourPosDn;
Def hourNegDn;
Def hourNegUp;
Def hourAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.hour {
    hourprice = close(period="1 Hour");
    Khour = (Highest(high(period="1 Hour"), length) + Lowest(low(period="1 Hour"), length)) /2 + ExpAverage(close(period="1 Hour"), length);
    hourmomo = Inertia(hourprice- khour / 2, length);
    hour_ExpAverage = ExpAverage(close(period="1 Hour"), Length);
    hourpos = hourmomo >= 0;
    hourneg = hourmomo < 0;
    hourup  = hourmomo >= hourmomo[1];
    hourdn  = hourmomo < hourmomo[1];

    hourPosUp = hourpos and hourup;
    hourPosDn = hourpos and hourdn;
    hourNegDn = hourneg and hourdn;
    hourNegUp = hourneg and hourup;
    hourAggregationPeriod = 1;
}
Else {
    hourprice = 0;
    Khour = 0;
    hourmomo = 0;
    hour_ExpAverage = 0;
    hourpos = 0;
    hourneg = 0;
    hourup = 0;
    hourdn = 0;
    hourPosUp = 0;
    hourPosDn = 0;
    hourNegDn = 0;
    hourNegUp = 0;
    hourAggregationPeriod = 0;
}
AddLabel(hourAggregationPeriod, "1h", if hourPosUp then globalColor("hour PosUp") else if hourPosDn then globalColor("hour PosDn") else if hourNegDn then globalColor("hour NegDn") else if hourNegUp then globalColor("hour NegUp") else globalColor("hour Neutral"));



def thirty_minprice;
def Kthirty_min;
def thirty_minmomo;
Def thirty_min_ExpAverage;
Def thirty_minpos;
Def thirty_minneg;
Def thirty_minup;
Def thirty_mindn;
Def thirty_minPosUp;
Def thirty_minPosDn;
Def thirty_minNegDn;
Def thirty_minNegUp;
Def thirty_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.thirty_min {
    thirty_minprice = close(period="30 Min");
    Kthirty_min = (Highest(high(period="30 Min"), length) + Lowest(low(period="30 Min"), length)) /2 + ExpAverage(close(period="30 Min"), length);
    thirty_minmomo = Inertia(thirty_minprice- kthirty_min / 2, length);
    thirty_min_ExpAverage = ExpAverage(close(period="30 Min"), Length);
    thirty_minpos = thirty_minmomo >= 0;
    thirty_minneg = thirty_minmomo < 0;
    thirty_minup  = thirty_minmomo >= thirty_minmomo[1];
    thirty_mindn  = thirty_minmomo < thirty_minmomo[1];

    thirty_minPosUp = thirty_minpos and thirty_minup;
    thirty_minPosDn = thirty_minpos and thirty_mindn;
    thirty_minNegDn = thirty_minneg and thirty_mindn;
    thirty_minNegUp = thirty_minneg and thirty_minup;
    thirty_minAggregationPeriod = 1;
}
Else {
    thirty_minprice = 0;
    Kthirty_min = 0;
    thirty_minmomo = 0;
    thirty_min_ExpAverage = 0;
    thirty_minpos = 0;
    thirty_minneg = 0;
    thirty_minup = 0;
    thirty_mindn = 0;
    thirty_minPosUp = 0;
    thirty_minPosDn = 0;
    thirty_minNegDn = 0;
    thirty_minNegUp = 0;
    thirty_minAggregationPeriod = 0;
}
AddLabel(thirty_minAggregationPeriod, "30m", if thirty_minPosUp then globalColor("thirty_min PosUp") else if thirty_minPosDn then globalColor("thirty_min PosDn") else if thirty_minNegDn then globalColor("thirty_min NegDn") else if thirty_minNegUp then globalColor("thirty_min NegUp") else globalColor("thirty_min Neutral"));



def twenty_minprice;
def Ktwenty_min;
def twenty_minmomo;
Def twenty_min_ExpAverage;
Def twenty_minpos;
Def twenty_minneg;
Def twenty_minup;
Def twenty_mindn;
Def twenty_minPosUp;
Def twenty_minPosDn;
Def twenty_minNegDn;
Def twenty_minNegUp;
Def twenty_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.twenty_min {
    twenty_minprice = close(period="20 Min");
    Ktwenty_min = (Highest(high(period="20 Min"), length) + Lowest(low(period="20 Min"), length)) /2 + ExpAverage(close(period="20 Min"), length);
    twenty_minmomo = Inertia(twenty_minprice- ktwenty_min / 2, length);
    twenty_min_ExpAverage = ExpAverage(close(period="20 Min"), Length);
    twenty_minpos = twenty_minmomo >= 0;
    twenty_minneg = twenty_minmomo < 0;
    twenty_minup  = twenty_minmomo >= twenty_minmomo[1];
    twenty_mindn  = twenty_minmomo < twenty_minmomo[1];

    twenty_minPosUp = twenty_minpos and twenty_minup;
    twenty_minPosDn = twenty_minpos and twenty_mindn;
    twenty_minNegDn = twenty_minneg and twenty_mindn;
    twenty_minNegUp = twenty_minneg and twenty_minup;
    twenty_minAggregationPeriod = 1;
}
Else {
    twenty_minprice = 0;
    Ktwenty_min = 0;
    twenty_minmomo = 0;
    twenty_min_ExpAverage = 0;
    twenty_minpos = 0;
    twenty_minneg = 0;
    twenty_minup = 0;
    twenty_mindn = 0;
    twenty_minPosUp = 0;
    twenty_minPosDn = 0;
    twenty_minNegDn = 0;
    twenty_minNegUp = 0;
    twenty_minAggregationPeriod = 0;
}
AddLabel(twenty_minAggregationPeriod, "20m", if twenty_minPosUp then globalColor("twenty_min PosUp") else if twenty_minPosDn then globalColor("twenty_min PosDn") else if twenty_minNegDn then globalColor("twenty_min NegDn") else if twenty_minNegUp then globalColor("twenty_min NegUp") else globalColor("twenty_min Neutral"));



def fifteen_minprice;
def Kfifteen_min;
def fifteen_minmomo;
Def fifteen_min_ExpAverage;
Def fifteen_minpos;
Def fifteen_minneg;
Def fifteen_minup;
Def fifteen_mindn;
Def fifteen_minPosUp;
Def fifteen_minPosDn;
Def fifteen_minNegDn;
Def fifteen_minNegUp;
Def fifteen_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.fifteen_min {
    fifteen_minprice = close(period="15 Min");
    Kfifteen_min = (Highest(high(period="15 Min"), length) + Lowest(low(period="15 Min"), length)) /2 + ExpAverage(close(period="15 Min"), length);
    fifteen_minmomo = Inertia(fifteen_minprice- kfifteen_min / 2, length);
    fifteen_min_ExpAverage = ExpAverage(close(period="15 Min"), Length);
    fifteen_minpos = fifteen_minmomo >= 0;
    fifteen_minneg = fifteen_minmomo < 0;
    fifteen_minup  = fifteen_minmomo >= fifteen_minmomo[1];
    fifteen_mindn  = fifteen_minmomo < fifteen_minmomo[1];

    fifteen_minPosUp = fifteen_minpos and fifteen_minup;
    fifteen_minPosDn = fifteen_minpos and fifteen_mindn;
    fifteen_minNegDn = fifteen_minneg and fifteen_mindn;
    fifteen_minNegUp = fifteen_minneg and fifteen_minup;
    fifteen_minAggregationPeriod = 1;
}
Else {
    fifteen_minprice = 0;
    Kfifteen_min = 0;
    fifteen_minmomo = 0;
    fifteen_min_ExpAverage = 0;
    fifteen_minpos = 0;
    fifteen_minneg = 0;
    fifteen_minup = 0;
    fifteen_mindn = 0;
    fifteen_minPosUp = 0;
    fifteen_minPosDn = 0;
    fifteen_minNegDn = 0;
    fifteen_minNegUp = 0;
    fifteen_minAggregationPeriod = 0;
}
AddLabel(fifteen_minAggregationPeriod, "15m", if fifteen_minPosUp then globalColor("fifteen_min PosUp") else if fifteen_minPosDn then globalColor("fifteen_min PosDn") else if fifteen_minNegDn then globalColor("fifteen_min NegDn") else if fifteen_minNegUp then globalColor("fifteen_min NegUp") else globalColor("fifteen_min Neutral"));



def ten_minprice;
def Kten_min;
def ten_minmomo;
Def ten_min_ExpAverage;
Def ten_minpos;
Def ten_minneg;
Def ten_minup;
Def ten_mindn;
Def ten_minPosUp;
Def ten_minPosDn;
Def ten_minNegDn;
Def ten_minNegUp;
Def ten_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.ten_min {
    ten_minprice = close(period="10 Min");
    Kten_min = (Highest(high(period="10 Min"), length) + Lowest(low(period="10 Min"), length)) /2 + ExpAverage(close(period="10 Min"), length);
    ten_minmomo = Inertia(ten_minprice- kten_min / 2, length);
    ten_min_ExpAverage = ExpAverage(close(period="10 Min"), Length);
    ten_minpos = ten_minmomo >= 0;
    ten_minneg = ten_minmomo < 0;
    ten_minup  = ten_minmomo >= ten_minmomo[1];
    ten_mindn  = ten_minmomo < ten_minmomo[1];

    ten_minPosUp = ten_minpos and ten_minup;
    ten_minPosDn = ten_minpos and ten_mindn;
    ten_minNegDn = ten_minneg and ten_mindn;
    ten_minNegUp = ten_minneg and ten_minup;
    ten_minAggregationPeriod = 1;
}
Else {
    ten_minprice = 0;
    Kten_min = 0;
    ten_minmomo = 0;
    ten_min_ExpAverage = 0;
    ten_minpos = 0;
    ten_minneg = 0;
    ten_minup = 0;
    ten_mindn = 0;
    ten_minPosUp = 0;
    ten_minPosDn = 0;
    ten_minNegDn = 0;
    ten_minNegUp = 0;
    ten_minAggregationPeriod = 0;
}
AddLabel(ten_minAggregationPeriod, "10m", if ten_minPosUp then globalColor("ten_min PosUp") else if ten_minPosDn then globalColor("ten_min PosDn") else if ten_minNegDn then globalColor("ten_min NegDn") else if ten_minNegUp then globalColor("ten_min NegUp") else globalColor("ten_min Neutral"));



def five_minprice;
def Kfive_min;
def five_minmomo;
Def five_min_ExpAverage;
Def five_minpos;
Def five_minneg;
Def five_minup;
Def five_mindn;
Def five_minPosUp;
Def five_minPosDn;
Def five_minNegDn;
Def five_minNegUp;
Def five_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.five_min {
    five_minprice = close(period="5 Min");
    Kfive_min = (Highest(high(period="5 Min"), length) + Lowest(low(period="5 Min"), length)) /2 + ExpAverage(close(period="5 Min"), length);
    five_minmomo = Inertia(five_minprice- kfive_min / 2, length);
    five_min_ExpAverage = ExpAverage(close(period="5 Min"), Length);
    five_minpos = five_minmomo >= 0;
    five_minneg = five_minmomo < 0;
    five_minup  = five_minmomo >= five_minmomo[1];
    five_mindn  = five_minmomo < five_minmomo[1];

    five_minPosUp = five_minpos and five_minup;
    five_minPosDn = five_minpos and five_mindn;
    five_minNegDn = five_minneg and five_mindn;
    five_minNegUp = five_minneg and five_minup;
    five_minAggregationPeriod = 1;
}
Else {
    five_minprice = 0;
    Kfive_min = 0;
    five_minmomo = 0;
    five_min_ExpAverage = 0;
    five_minpos = 0;
    five_minneg = 0;
    five_minup = 0;
    five_mindn = 0;
    five_minPosUp = 0;
    five_minPosDn = 0;
    five_minNegDn = 0;
    five_minNegUp = 0;
    five_minAggregationPeriod = 0;
}
AddLabel(five_minAggregationPeriod, "5m", if five_minPosUp then globalColor("five_min PosUp") else if five_minPosDn then globalColor("five_min PosDn") else if five_minNegDn then globalColor("five_min NegDn") else if five_minNegUp then globalColor("five_min NegUp") else globalColor("five_min Neutral"));



def four_minprice;
def Kfour_min;
def four_minmomo;
Def four_min_ExpAverage;
Def four_minpos;
Def four_minneg;
Def four_minup;
Def four_mindn;
Def four_minPosUp;
Def four_minPosDn;
Def four_minNegDn;
Def four_minNegUp;
Def four_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_min {
    four_minprice = close(period="4 Min");
    Kfour_min = (Highest(high(period="4 Min"), length) + Lowest(low(period="4 Min"), length)) /2 + ExpAverage(close(period="4 Min"), length);
    four_minmomo = Inertia(four_minprice- kfour_min / 2, length);
    four_min_ExpAverage = ExpAverage(close(period="4 Min"), Length);
    four_minpos = four_minmomo >= 0;
    four_minneg = four_minmomo < 0;
    four_minup  = four_minmomo >= four_minmomo[1];
    four_mindn  = four_minmomo < four_minmomo[1];

    four_minPosUp = four_minpos and four_minup;
    four_minPosDn = four_minpos and four_mindn;
    four_minNegDn = four_minneg and four_mindn;
    four_minNegUp = four_minneg and four_minup;
    four_minAggregationPeriod = 1;
}
Else {
    four_minprice = 0;
    Kfour_min = 0;
    four_minmomo = 0;
    four_min_ExpAverage = 0;
    four_minpos = 0;
    four_minneg = 0;
    four_minup = 0;
    four_mindn = 0;
    four_minPosUp = 0;
    four_minPosDn = 0;
    four_minNegDn = 0;
    four_minNegUp = 0;
    four_minAggregationPeriod = 0;
}
AddLabel(four_minAggregationPeriod, "4m", if four_minPosUp then globalColor("four_min PosUp") else if four_minPosDn then globalColor("four_min PosDn") else if four_minNegDn then globalColor("four_min NegDn") else if four_minNegUp then globalColor("four_min NegUp") else globalColor("four_min Neutral"));



def three_minprice;
def Kthree_min;
def three_minmomo;
Def three_min_ExpAverage;
Def three_minpos;
Def three_minneg;
Def three_minup;
Def three_mindn;
Def three_minPosUp;
Def three_minPosDn;
Def three_minNegDn;
Def three_minNegUp;
Def three_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.three_min {
    three_minprice = close(period="3 Min");
    Kthree_min = (Highest(high(period="3 Min"), length) + Lowest(low(period="3 Min"), length)) /2 + ExpAverage(close(period="3 Min"), length);
    three_minmomo = Inertia(three_minprice- kthree_min / 2, length);
    three_min_ExpAverage = ExpAverage(close(period="3 Min"), Length);
    three_minpos = three_minmomo >= 0;
    three_minneg = three_minmomo < 0;
    three_minup  = three_minmomo >= three_minmomo[1];
    three_mindn  = three_minmomo < three_minmomo[1];

    three_minPosUp = three_minpos and three_minup;
    three_minPosDn = three_minpos and three_mindn;
    three_minNegDn = three_minneg and three_mindn;
    three_minNegUp = three_minneg and three_minup;
    three_minAggregationPeriod = 1;
}
Else {
    three_minprice = 0;
    Kthree_min = 0;
    three_minmomo = 0;
    three_min_ExpAverage = 0;
    three_minpos = 0;
    three_minneg = 0;
    three_minup = 0;
    three_mindn = 0;
    three_minPosUp = 0;
    three_minPosDn = 0;
    three_minNegDn = 0;
    three_minNegUp = 0;
    three_minAggregationPeriod = 0;
}
AddLabel(three_minAggregationPeriod, "3m", if three_minPosUp then globalColor("three_min PosUp") else if three_minPosDn then globalColor("three_min PosDn") else if three_minNegDn then globalColor("three_min NegDn") else if three_minNegUp then globalColor("three_min NegUp") else globalColor("three_min Neutral"));



def two_minprice;
def Ktwo_min;
def two_minmomo;
Def two_min_ExpAverage;
Def two_minpos;
Def two_minneg;
Def two_minup;
Def two_mindn;
Def two_minPosUp;
Def two_minPosDn;
Def two_minNegDn;
Def two_minNegUp;
Def two_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_min {
    two_minprice = close(period="2 Min");
    Ktwo_min = (Highest(high(period="2 Min"), length) + Lowest(low(period="2 Min"), length)) /2 + ExpAverage(close(period="2 Min"), length);
    two_minmomo = Inertia(two_minprice- ktwo_min / 2, length);
    two_min_ExpAverage = ExpAverage(close(period="2 Min"), Length);
    two_minpos = two_minmomo >= 0;
    two_minneg = two_minmomo < 0;
    two_minup  = two_minmomo >= two_minmomo[1];
    two_mindn  = two_minmomo < two_minmomo[1];

    two_minPosUp = two_minpos and two_minup;
    two_minPosDn = two_minpos and two_mindn;
    two_minNegDn = two_minneg and two_mindn;
    two_minNegUp = two_minneg and two_minup;
    two_minAggregationPeriod = 1;
}
Else {
    two_minprice = 0;
    Ktwo_min = 0;
    two_minmomo = 0;
    two_min_ExpAverage = 0;
    two_minpos = 0;
    two_minneg = 0;
    two_minup = 0;
    two_mindn = 0;
    two_minPosUp = 0;
    two_minPosDn = 0;
    two_minNegDn = 0;
    two_minNegUp = 0;
    two_minAggregationPeriod = 0;
}
AddLabel(two_minAggregationPeriod, "2m", if two_minPosUp then globalColor("two_min PosUp") else if two_minPosDn then globalColor("two_min PosDn") else if two_minNegDn then globalColor("two_min NegDn") else if two_minNegUp then globalColor("two_min NegUp") else globalColor("two_min Neutral"));



def one_minprice;
def Kone_min;
def one_minmomo;
Def one_min_ExpAverage;
Def one_minpos;
Def one_minneg;
Def one_minup;
Def one_mindn;
Def one_minPosUp;
Def one_minPosDn;
Def one_minNegDn;
Def one_minNegUp;
Def one_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Min {
    one_minprice = close(period="1 Min");
    Kone_min = (Highest(high(period="1 Min"), length) + Lowest(low(period="1 Min"), length)) /2 + ExpAverage(close(period="1 Min"), length);
    one_minmomo = Inertia(one_minprice- kone_min / 2, length);
    one_min_ExpAverage = ExpAverage(close(period="1 Min"), Length);
    one_minpos = one_minmomo >= 0;
    one_minneg = one_minmomo < 0;
    one_minup  = one_minmomo >= one_minmomo[1];
    one_mindn  = one_minmomo < one_minmomo[1];

    one_minPosUp = one_minpos and one_minup;
    one_minPosDn = one_minpos and one_mindn;
    one_minNegDn = one_minneg and one_mindn;
    one_minNegUp = one_minneg and one_minup;
    one_minAggregationPeriod = 1;
}
Else {
    one_minprice = 0;
    Kone_min = 0;
    one_minmomo = 0;
    one_min_ExpAverage = 0;
    one_minpos = 0;
    one_minneg = 0;
    one_minup = 0;
    one_mindn = 0;
    one_minPosUp = 0;
    one_minPosDn = 0;
    one_minNegDn = 0;
    one_minNegUp = 0;
    one_minAggregationPeriod = 0;
}
AddLabel(one_minAggregationPeriod, "1m", if one_minPosUp then globalColor("one_min PosUp") else if one_minPosDn then globalColor("one_min PosDn") else if one_minNegDn then globalColor("one_min NegDn") else if one_minNegUp then globalColor("one_min NegUp") else globalColor("one_min Neutral"));
2gyx1Se.png
Coincidentally, I was working on the mtf histogram using the thinkorswim TTM_squeeze().histogram function. That didn’t work ! The higher timeframe output always display the current timeframe output.
Your code came just in time!
Thanks for doing the heavy lifting for us!
Just one question for you.. How do you place the histogram labels below the squeeze labels as shown on the top right hand corner of the chart?
 
Coincidentally, I was working on the mtf histogram using the thinkorswim TTM_squeeze().histogram function. That didn’t work ! The higher timeframe output always display the current timeframe output.
Your code came just in time!
Thanks for doing the heavy lifting for us!
Just one question for you.. How do you place the histogram labels below the squeeze labels as shown on the top right hand corner of the chart?
Btw can you post the MTF squeeze code as well? I realised from the screen short its for the 3 squeeze pro version.
Thanks!
 
Btw can you post the MTF squeeze code as well? I realised from the screen short its for the 3 squeeze pro version.
Thanks!
No problem! Happy to share my findings and creations with anybody that wants them! The only way I know of how to place the histogram labels below the squeeze labels is to manually change the size of the chart by clicking and dragging it. My MTF Squeeze Pro Labels script is already on here. It was posted 2 days ago to its own thread.

https://usethinkscript.com/threads/multi-time-fram-mtf-squeeze-pro-labels-for-thinkorswim.9282/
 
Last edited:
Last edited:
Multi Time Frame MTF Squeeze HISTOGRAM Colored Labels for ThinkOrSwim

For anybody interested, here is the script for the MTF Squeeze Histogram Colored Labels I wrote. It's identical to the new "Simpler Trading" indicator. This is the bottom row of labels in the picture. It's based on momentum and does not show you if there's a squeeze, but rather the momentum of the trend during each time period. I'm not sure if there are any parts of the script that aren't necessary. Regardless, it functions as it should. Any comments, corrections, and/or constructive criticism are welcomed. I hope somebody else finds this script helpful!

UPDATE: In case anybody else wants the MTF Squeeze PRO Labels script as well, here is the link for it.

https://usethinkscript.com/threads/multi-time-fram-mtf-squeeze-pro-labels-for-thinkorswim.9282/

Code:
##MTF Squeeze Histogram Labels
##Created By: Casey Brett
##Global Variables

input price = close;
input length = 20;
input averageType = AverageType.EXPONENTIAL;
input displace = 0;

def K = (Highest(high, length) + Lowest(low, length)) /2 + ExpAverage(close, length);
def momo = Inertia(price - K / 2, length);

def pos         = momo >= 0;
def neg         = momo < 0;
def up         = momo >= momo[1];
def dn         = momo < momo[1];

def PosUp = pos and up;
def PosDn = pos and dn;
def NegDn = neg and dn;
def NegUp = neg and up;

defineGlobalColor("Month PosUp", color.cyan);
defineGlobalColor("Month PosDn", color.blue);
defineGlobalColor("Month NegDn", color.red);
defineGlobalColor("Month NegUp", color.yellow);
defineGlobalColor("Month Neutral", color.gray);
defineGlobalColor("Week PosUp", color.cyan);
defineGlobalColor("Week PosDn", color.blue);
defineGlobalColor("Week NegDn", color.red);
defineGlobalColor("Week NegUp", color.yellow);
defineGlobalColor("Week Neutral", color.gray);
defineGlobalColor("four_days PosUp", color.cyan);
defineGlobalColor("four_days PosDn", color.blue);
defineGlobalColor("four_days NegDn", color.red);
defineGlobalColor("four_days NegUp", color.yellow);
defineGlobalColor("four_days Neutral", color.gray);
defineGlobalColor("three_days PosUp", color.cyan);
defineGlobalColor("three_days PosDn", color.blue);
defineGlobalColor("three_days NegDn", color.red);
defineGlobalColor("three_days NegUp", color.yellow);
defineGlobalColor("three_days Neutral", color.gray);
defineGlobalColor("two_days PosUp", color.cyan);
defineGlobalColor("two_days PosDn", color.blue);
defineGlobalColor("two_days NegDn", color.red);
defineGlobalColor("two_days NegUp", color.yellow);
defineGlobalColor("two_days Neutral", color.gray);
defineGlobalColor("Day PosUp", color.cyan);
defineGlobalColor("Day PosDn", color.blue);
defineGlobalColor("Day NegDn", color.red);
defineGlobalColor("Day NegUp", color.yellow);
defineGlobalColor("Day Neutral", color.gray);
defineGlobalColor("four_hours PosUp", color.cyan);
defineGlobalColor("four_hours PosDn", color.blue);
defineGlobalColor("four_hours NegDn", color.red);
defineGlobalColor("four_hours NegUp", color.yellow);
defineGlobalColor("four_hours Neutral", color.gray);
defineGlobalColor("two_hours PosUp", color.cyan);
defineGlobalColor("two_hours PosDn", color.blue);
defineGlobalColor("two_hours NegDn", color.red);
defineGlobalColor("two_hours NegUp", color.yellow);
defineGlobalColor("two_hours Neutral", color.gray);
defineGlobalColor("hour PosUp", color.cyan);
defineGlobalColor("hour PosDn", color.blue);
defineGlobalColor("hour NegDn", color.red);
defineGlobalColor("hour NegUp", color.yellow);
defineGlobalColor("hour Neutral", color.gray);
defineGlobalColor("thirty_min PosUp", color.cyan);
defineGlobalColor("thirty_min PosDn", color.blue);
defineGlobalColor("thirty_min NegDn", color.red);
defineGlobalColor("thirty_min NegUp", color.yellow);
defineGlobalColor("thirty_min Neutral", color.gray);
defineGlobalColor("twenty_min PosUp", color.cyan);
defineGlobalColor("twenty_min PosDn", color.blue);
defineGlobalColor("twenty_min NegDn", color.red);
defineGlobalColor("twenty_min NegUp", color.yellow);
defineGlobalColor("twenty_min Neutral", color.gray);
defineGlobalColor("fifteen_min PosUp", color.cyan);
defineGlobalColor("fifteen_min PosDn", color.blue);
defineGlobalColor("fifteen_min NegDn", color.red);
defineGlobalColor("fifteen_min NegUp", color.yellow);
defineGlobalColor("fifteen_min Neutral", color.gray);
defineGlobalColor("ten_min PosUp", color.cyan);
defineGlobalColor("ten_min PosDn", color.blue);
defineGlobalColor("ten_min NegDn", color.red);
defineGlobalColor("ten_min NegUp", color.yellow);
defineGlobalColor("ten_min Neutral", color.gray);
defineGlobalColor("five_min PosUp", color.cyan);
defineGlobalColor("five_min PosDn", color.blue);
defineGlobalColor("five_min NegDn", color.red);
defineGlobalColor("five_min NegUp", color.yellow);
defineGlobalColor("five_min Neutral", color.gray);
defineGlobalColor("four_min PosUp", color.cyan);
defineGlobalColor("four_min PosDn", color.blue);
defineGlobalColor("four_min NegDn", color.red);
defineGlobalColor("four_min NegUp", color.yellow);
defineGlobalColor("four_min Neutral", color.gray);
defineGlobalColor("three_min PosUp", color.cyan);
defineGlobalColor("three_min PosDn", color.blue);
defineGlobalColor("three_min NegDn", color.red);
defineGlobalColor("three_min NegUp", color.yellow);
defineGlobalColor("three_min Neutral", color.gray);
defineGlobalColor("two_min PosUp", color.cyan);
defineGlobalColor("two_min PosDn", color.blue);
defineGlobalColor("two_min NegDn", color.red);
defineGlobalColor("two_min NegUp", color.yellow);
defineGlobalColor("two_min Neutral", color.gray);
defineGlobalColor("one_min PosUp", color.cyan);
defineGlobalColor("one_min PosDn", color.blue);
defineGlobalColor("one_min NegDn", color.red);
defineGlobalColor("one_min NegUp", color.yellow);
defineGlobalColor("one_min Neutral", color.gray);


def monthprice;
def Kmonth;
def monthmomo;
Def Month_ExpAverage;
Def monthpos;
Def monthneg;
Def monthup;
Def monthdn;
Def monthPosUp;
Def monthPosDn;
Def monthNegDn;
Def monthNegUp;
Def monthAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Month {
    monthprice = close(period="Month");
    Kmonth = (Highest(high(period="Month"), length) + Lowest(low(period="Month"), length)) /2 + ExpAverage(close(period="Month"), length);
    monthmomo = Inertia(monthprice- kmonth / 2, length);
    Month_ExpAverage = ExpAverage(close(period="Month"), Length);
    monthpos = monthmomo >= 0;
    monthneg = monthmomo < 0;
    monthup  = monthmomo >= monthmomo[1];
    monthdn  = monthmomo < monthmomo[1];

    monthPosUp = monthpos and monthup;
    monthPosDn = monthpos and monthdn;
    monthNegDn = monthneg and monthdn;
    monthNegUp = monthneg and monthup;
    monthAggregationPeriod = 1;
}
Else {
    monthprice = 0;
    Kmonth = 0;
    monthmomo = 0;
    Month_ExpAverage = 0;
    monthpos = 0;
    monthneg = 0;
    monthup = 0;
    monthdn = 0;
    monthPosUp = 0;
    monthPosDn = 0;
    monthNegDn = 0;
    monthNegUp = 0;
    monthAggregationPeriod = 0;
}
AddLabel(monthAggregationPeriod, "M", if monthPosUp then globalColor("Month PosUp") else if monthPosDn then globalColor("Month PosDn") else if monthNegDn then globalColor("Month NegDn") else if monthNegUp then globalColor("Month NegUp") else globalColor("Month Neutral"));

def Weekprice;
def KWeek;
def Weekmomo;
Def Week_ExpAverage;
Def Weekpos;
Def Weekneg;
Def Weekup;
Def Weekdn;
Def WeekPosUp;
Def WeekPosDn;
Def WeekNegDn;
Def WeekNegUp;
Def WeekAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Week {
    Weekprice = close(period="Week");
    KWeek = (Highest(high(period="Week"), length) + Lowest(low(period="Week"), length)) /2 + ExpAverage(close(period="week"), length);
    Weekmomo = Inertia(Weekprice- kWeek / 2, length);
    Week_ExpAverage = ExpAverage(close(period="Week"), Length);
    Weekpos = Weekmomo >= 0;
    Weekneg = Weekmomo < 0;
    Weekup  = Weekmomo >= Weekmomo[1];
    Weekdn  = Weekmomo < Weekmomo[1];

    WeekPosUp = Weekpos and Weekup;
    WeekPosDn = Weekpos and Weekdn;
    WeekNegDn = Weekneg and Weekdn;
    WeekNegUp = Weekneg and Weekup;
    WeekAggregationPeriod = 1;
}
Else {
    Weekprice = 0;
    KWeek = 0;
    Weekmomo = 0;
    Week_ExpAverage = 0;
    Weekpos = 0;
    Weekneg = 0;
    Weekup = 0;
    Weekdn = 0;
    WeekPosUp = 0;
    WeekPosDn = 0;
    WeekNegDn = 0;
    WeekNegUp = 0;
    WeekAggregationPeriod = 0;
}
AddLabel(WeekAggregationPeriod, "W", if WeekPosUp then globalColor("Week PosUp") else if WeekPosDn then globalColor("Week PosDn") else if WeekNegDn then globalColor("Week NegDn") else if WeekNegUp then globalColor("Week NegUp") else globalColor("Week Neutral"));


def four_daysprice;
def Kfour_days;
def four_daysmomo;
Def four_days_ExpAverage;
Def four_dayspos;
Def four_daysneg;
Def four_daysup;
Def four_daysdn;
Def four_daysPosUp;
Def four_daysPosDn;
Def four_daysNegDn;
Def four_daysNegUp;
Def four_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_days {
    four_daysprice = close(period="4 Days");
    Kfour_days = (Highest(high(period="4 Days"), length) + Lowest(low(period="4 Days"), length)) /2 + ExpAverage(close(period="4 Days"), length);
    four_daysmomo = Inertia(four_daysprice- kfour_days / 2, length);
    four_days_ExpAverage = ExpAverage(close(period="4 Days"), Length);
    four_dayspos = four_daysmomo >= 0;
    four_daysneg = four_daysmomo < 0;
    four_daysup  = four_daysmomo >= four_daysmomo[1];
    four_daysdn  = four_daysmomo < four_daysmomo[1];

    four_daysPosUp = four_dayspos and four_daysup;
    four_daysPosDn = four_dayspos and four_daysdn;
    four_daysNegDn = four_daysneg and four_daysdn;
    four_daysNegUp = four_daysneg and four_daysup;
    four_daysAggregationPeriod = 1;
}
Else {
    four_daysprice = 0;
    Kfour_days = 0;
    four_daysmomo = 0;
    four_days_ExpAverage = 0;
    four_dayspos = 0;
    four_daysneg = 0;
    four_daysup = 0;
    four_daysdn = 0;
    four_daysPosUp = 0;
    four_daysPosDn = 0;
    four_daysNegDn = 0;
    four_daysNegUp = 0;
    four_daysAggregationPeriod = 0;
}
AddLabel(four_daysAggregationPeriod, "4D", if four_daysPosUp then globalColor("four_days PosUp") else if four_daysPosDn then globalColor("four_days PosDn") else if four_daysNegDn then globalColor("four_days NegDn") else if four_daysNegUp then globalColor("four_days NegUp") else globalColor("four_days Neutral"));

def three_daysprice;
def Kthree_days;
def three_daysmomo;
Def three_days_ExpAverage;
Def three_dayspos;
Def three_daysneg;
Def three_daysup;
Def three_daysdn;
Def three_daysPosUp;
Def three_daysPosDn;
Def three_daysNegDn;
Def three_daysNegUp;
Def three_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.three_days {
    three_daysprice = close(period="3 Days");
    Kthree_days = (Highest(high(period="3 Days"), length) + Lowest(low(period="3 Days"), length)) /2 + ExpAverage(close(period="3 Days"), length);
    three_daysmomo = Inertia(three_daysprice- kthree_days / 2, length);
    three_days_ExpAverage = ExpAverage(close(period="3 Days"), Length);
    three_dayspos = three_daysmomo >= 0;
    three_daysneg = three_daysmomo < 0;
    three_daysup  = three_daysmomo >= three_daysmomo[1];
    three_daysdn  = three_daysmomo < three_daysmomo[1];

    three_daysPosUp = three_dayspos and three_daysup;
    three_daysPosDn = three_dayspos and three_daysdn;
    three_daysNegDn = three_daysneg and three_daysdn;
    three_daysNegUp = three_daysneg and three_daysup;
    three_daysAggregationPeriod = 1;
}
Else {
    three_daysprice = 0;
    Kthree_days = 0;
    three_daysmomo = 0;
    three_days_ExpAverage = 0;
    three_dayspos = 0;
    three_daysneg = 0;
    three_daysup = 0;
    three_daysdn = 0;
    three_daysPosUp = 0;
    three_daysPosDn = 0;
    three_daysNegDn = 0;
    three_daysNegUp = 0;
    three_daysAggregationPeriod = 0;
}
AddLabel(three_daysAggregationPeriod, "3D", if three_daysPosUp then globalColor("three_days PosUp") else if three_daysPosDn then globalColor("three_days PosDn") else if three_daysNegDn then globalColor("three_days NegDn") else if three_daysNegUp then globalColor("three_days NegUp") else globalColor("three_days Neutral"));




def two_daysprice;
def Ktwo_days;
def two_daysmomo;
Def two_days_ExpAverage;
Def two_dayspos;
Def two_daysneg;
Def two_daysup;
Def two_daysdn;
Def two_daysPosUp;
Def two_daysPosDn;
Def two_daysNegDn;
Def two_daysNegUp;
Def two_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_days {
    two_daysprice = close(period="2 Days");
    Ktwo_days = (Highest(high(period="2 Days"), length) + Lowest(low(period="2 Days"), length)) /2 + ExpAverage(close(period="2 Days"), length);
    two_daysmomo = Inertia(two_daysprice- ktwo_days / 2, length);
    two_days_ExpAverage = ExpAverage(close(period="2 Days"), Length);
    two_dayspos = two_daysmomo >= 0;
    two_daysneg = two_daysmomo < 0;
    two_daysup  = two_daysmomo >= two_daysmomo[1];
    two_daysdn  = two_daysmomo < two_daysmomo[1];

    two_daysPosUp = two_dayspos and two_daysup;
    two_daysPosDn = two_dayspos and two_daysdn;
    two_daysNegDn = two_daysneg and two_daysdn;
    two_daysNegUp = two_daysneg and two_daysup;
    two_daysAggregationPeriod = 1;
}
Else {
    two_daysprice = 0;
    Ktwo_days = 0;
    two_daysmomo = 0;
    two_days_ExpAverage = 0;
    two_dayspos = 0;
    two_daysneg = 0;
    two_daysup = 0;
    two_daysdn = 0;
    two_daysPosUp = 0;
    two_daysPosDn = 0;
    two_daysNegDn = 0;
    two_daysNegUp = 0;
    two_daysAggregationPeriod = 0;
}
AddLabel(two_daysAggregationPeriod, "2D", if two_daysPosUp then globalColor("two_days PosUp") else if two_daysPosDn then globalColor("two_days PosDn") else if two_daysNegDn then globalColor("two_days NegDn") else if two_daysNegUp then globalColor("two_days NegUp") else globalColor("two_days Neutral"));


def Dayprice;
def KDay;
def Daymomo;
Def Day_ExpAverage;
Def Daypos;
Def Dayneg;
Def Dayup;
Def Daydn;
Def DayPosUp;
Def DayPosDn;
Def DayNegDn;
Def DayNegUp;
Def DayAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Day {
    Dayprice = close(period="Day");
    KDay = (Highest(high(period="Day"), length) + Lowest(low(period="Day"), length)) /2 + ExpAverage(close(period="Day"), length);
    Daymomo = Inertia(Dayprice- kDay / 2, length);
    Day_ExpAverage = ExpAverage(close(period="Day"), Length);
    Daypos = Daymomo >= 0;
    Dayneg = Daymomo < 0;
    Dayup  = Daymomo >= Daymomo[1];
    Daydn  = Daymomo < Daymomo[1];

    DayPosUp = Daypos and Dayup;
    DayPosDn = Daypos and Daydn;
    DayNegDn = Dayneg and Daydn;
    DayNegUp = Dayneg and Dayup;
    DayAggregationPeriod = 1;
}
Else {
    Dayprice = 0;
    KDay = 0;
    Daymomo = 0;
    Day_ExpAverage = 0;
    Daypos = 0;
    Dayneg = 0;
    Dayup = 0;
    Daydn = 0;
    DayPosUp = 0;
    DayPosDn = 0;
    DayNegDn = 0;
    DayNegUp = 0;
    DayAggregationPeriod = 0;
}
AddLabel(DayAggregationPeriod, "D", if DayPosUp then globalColor("Day PosUp") else if DayPosDn then globalColor("Day PosDn") else if DayNegDn then globalColor("Day NegDn") else if DayNegUp then globalColor("Day NegUp") else globalColor("Day Neutral"));


def four_hoursprice;
def Kfour_hours;
def four_hoursmomo;
Def four_hours_ExpAverage;
Def four_hourspos;
Def four_hoursneg;
Def four_hoursup;
Def four_hoursdn;
Def four_hoursPosUp;
Def four_hoursPosDn;
Def four_hoursNegDn;
Def four_hoursNegUp;
Def four_hoursAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_hours {
    four_hoursprice = close(period="4 Hours");
    Kfour_hours = (Highest(high(period="4 Hours"), length) + Lowest(low(period="4 Hours"), length)) /2 + ExpAverage(close(period="4 Hours"), length);
    four_hoursmomo = Inertia(four_hoursprice- kfour_hours / 2, length);
    four_hours_ExpAverage = ExpAverage(close(period="4 Hours"), Length);
    four_hourspos = four_hoursmomo >= 0;
    four_hoursneg = four_hoursmomo < 0;
    four_hoursup  = four_hoursmomo >= four_hoursmomo[1];
    four_hoursdn  = four_hoursmomo < four_hoursmomo[1];

    four_hoursPosUp = four_hourspos and four_hoursup;
    four_hoursPosDn = four_hourspos and four_hoursdn;
    four_hoursNegDn = four_hoursneg and four_hoursdn;
    four_hoursNegUp = four_hoursneg and four_hoursup;
    four_hoursAggregationPeriod = 1;
}
Else {
    four_hoursprice = 0;
    Kfour_hours = 0;
    four_hoursmomo = 0;
    four_hours_ExpAverage = 0;
    four_hourspos = 0;
    four_hoursneg = 0;
    four_hoursup = 0;
    four_hoursdn = 0;
    four_hoursPosUp = 0;
    four_hoursPosDn = 0;
    four_hoursNegDn = 0;
    four_hoursNegUp = 0;
    four_hoursAggregationPeriod = 0;
}
AddLabel(four_hoursAggregationPeriod, "4h", if four_hoursPosUp then globalColor("four_hours PosUp") else if four_hoursPosDn then globalColor("four_hours PosDn") else if four_hoursNegDn then globalColor("four_hours NegDn") else if four_hoursNegUp then globalColor("four_hours NegUp") else globalColor("four_hours Neutral"));



def two_hoursprice;
def Ktwo_hours;
def two_hoursmomo;
Def two_hours_ExpAverage;
Def two_hourspos;
Def two_hoursneg;
Def two_hoursup;
Def two_hoursdn;
Def two_hoursPosUp;
Def two_hoursPosDn;
Def two_hoursNegDn;
Def two_hoursNegUp;
Def two_hoursAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_hours {
    two_hoursprice = close(period="2 Hours");
    Ktwo_hours = (Highest(high(period="2 Hours"), length) + Lowest(low(period="2 Hours"), length)) /2 + ExpAverage(close(period="2 Hours"), length);
    two_hoursmomo = Inertia(two_hoursprice- ktwo_hours / 2, length);
    two_hours_ExpAverage = ExpAverage(close(period="2 Hours"), Length);
    two_hourspos = two_hoursmomo >= 0;
    two_hoursneg = two_hoursmomo < 0;
    two_hoursup  = two_hoursmomo >= two_hoursmomo[1];
    two_hoursdn  = two_hoursmomo < two_hoursmomo[1];

    two_hoursPosUp = two_hourspos and two_hoursup;
    two_hoursPosDn = two_hourspos and two_hoursdn;
    two_hoursNegDn = two_hoursneg and two_hoursdn;
    two_hoursNegUp = two_hoursneg and two_hoursup;
    two_hoursAggregationPeriod = 1;
}
Else {
    two_hoursprice = 0;
    Ktwo_hours = 0;
    two_hoursmomo = 0;
    two_hours_ExpAverage = 0;
    two_hourspos = 0;
    two_hoursneg = 0;
    two_hoursup = 0;
    two_hoursdn = 0;
    two_hoursPosUp = 0;
    two_hoursPosDn = 0;
    two_hoursNegDn = 0;
    two_hoursNegUp = 0;
    two_hoursAggregationPeriod = 0;
}
AddLabel(two_hoursAggregationPeriod, "2h", if two_hoursPosUp then globalColor("two_hours PosUp") else if two_hoursPosDn then globalColor("two_hours PosDn") else if two_hoursNegDn then globalColor("two_hours NegDn") else if two_hoursNegUp then globalColor("two_hours NegUp") else globalColor("two_hours Neutral"));



def hourprice;
def Khour;
def hourmomo;
Def hour_ExpAverage;
Def hourpos;
Def hourneg;
Def hourup;
Def hourdn;
Def hourPosUp;
Def hourPosDn;
Def hourNegDn;
Def hourNegUp;
Def hourAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.hour {
    hourprice = close(period="1 Hour");
    Khour = (Highest(high(period="1 Hour"), length) + Lowest(low(period="1 Hour"), length)) /2 + ExpAverage(close(period="1 Hour"), length);
    hourmomo = Inertia(hourprice- khour / 2, length);
    hour_ExpAverage = ExpAverage(close(period="1 Hour"), Length);
    hourpos = hourmomo >= 0;
    hourneg = hourmomo < 0;
    hourup  = hourmomo >= hourmomo[1];
    hourdn  = hourmomo < hourmomo[1];

    hourPosUp = hourpos and hourup;
    hourPosDn = hourpos and hourdn;
    hourNegDn = hourneg and hourdn;
    hourNegUp = hourneg and hourup;
    hourAggregationPeriod = 1;
}
Else {
    hourprice = 0;
    Khour = 0;
    hourmomo = 0;
    hour_ExpAverage = 0;
    hourpos = 0;
    hourneg = 0;
    hourup = 0;
    hourdn = 0;
    hourPosUp = 0;
    hourPosDn = 0;
    hourNegDn = 0;
    hourNegUp = 0;
    hourAggregationPeriod = 0;
}
AddLabel(hourAggregationPeriod, "1h", if hourPosUp then globalColor("hour PosUp") else if hourPosDn then globalColor("hour PosDn") else if hourNegDn then globalColor("hour NegDn") else if hourNegUp then globalColor("hour NegUp") else globalColor("hour Neutral"));



def thirty_minprice;
def Kthirty_min;
def thirty_minmomo;
Def thirty_min_ExpAverage;
Def thirty_minpos;
Def thirty_minneg;
Def thirty_minup;
Def thirty_mindn;
Def thirty_minPosUp;
Def thirty_minPosDn;
Def thirty_minNegDn;
Def thirty_minNegUp;
Def thirty_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.thirty_min {
    thirty_minprice = close(period="30 Min");
    Kthirty_min = (Highest(high(period="30 Min"), length) + Lowest(low(period="30 Min"), length)) /2 + ExpAverage(close(period="30 Min"), length);
    thirty_minmomo = Inertia(thirty_minprice- kthirty_min / 2, length);
    thirty_min_ExpAverage = ExpAverage(close(period="30 Min"), Length);
    thirty_minpos = thirty_minmomo >= 0;
    thirty_minneg = thirty_minmomo < 0;
    thirty_minup  = thirty_minmomo >= thirty_minmomo[1];
    thirty_mindn  = thirty_minmomo < thirty_minmomo[1];

    thirty_minPosUp = thirty_minpos and thirty_minup;
    thirty_minPosDn = thirty_minpos and thirty_mindn;
    thirty_minNegDn = thirty_minneg and thirty_mindn;
    thirty_minNegUp = thirty_minneg and thirty_minup;
    thirty_minAggregationPeriod = 1;
}
Else {
    thirty_minprice = 0;
    Kthirty_min = 0;
    thirty_minmomo = 0;
    thirty_min_ExpAverage = 0;
    thirty_minpos = 0;
    thirty_minneg = 0;
    thirty_minup = 0;
    thirty_mindn = 0;
    thirty_minPosUp = 0;
    thirty_minPosDn = 0;
    thirty_minNegDn = 0;
    thirty_minNegUp = 0;
    thirty_minAggregationPeriod = 0;
}
AddLabel(thirty_minAggregationPeriod, "30m", if thirty_minPosUp then globalColor("thirty_min PosUp") else if thirty_minPosDn then globalColor("thirty_min PosDn") else if thirty_minNegDn then globalColor("thirty_min NegDn") else if thirty_minNegUp then globalColor("thirty_min NegUp") else globalColor("thirty_min Neutral"));



def twenty_minprice;
def Ktwenty_min;
def twenty_minmomo;
Def twenty_min_ExpAverage;
Def twenty_minpos;
Def twenty_minneg;
Def twenty_minup;
Def twenty_mindn;
Def twenty_minPosUp;
Def twenty_minPosDn;
Def twenty_minNegDn;
Def twenty_minNegUp;
Def twenty_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.twenty_min {
    twenty_minprice = close(period="20 Min");
    Ktwenty_min = (Highest(high(period="20 Min"), length) + Lowest(low(period="20 Min"), length)) /2 + ExpAverage(close(period="20 Min"), length);
    twenty_minmomo = Inertia(twenty_minprice- ktwenty_min / 2, length);
    twenty_min_ExpAverage = ExpAverage(close(period="20 Min"), Length);
    twenty_minpos = twenty_minmomo >= 0;
    twenty_minneg = twenty_minmomo < 0;
    twenty_minup  = twenty_minmomo >= twenty_minmomo[1];
    twenty_mindn  = twenty_minmomo < twenty_minmomo[1];

    twenty_minPosUp = twenty_minpos and twenty_minup;
    twenty_minPosDn = twenty_minpos and twenty_mindn;
    twenty_minNegDn = twenty_minneg and twenty_mindn;
    twenty_minNegUp = twenty_minneg and twenty_minup;
    twenty_minAggregationPeriod = 1;
}
Else {
    twenty_minprice = 0;
    Ktwenty_min = 0;
    twenty_minmomo = 0;
    twenty_min_ExpAverage = 0;
    twenty_minpos = 0;
    twenty_minneg = 0;
    twenty_minup = 0;
    twenty_mindn = 0;
    twenty_minPosUp = 0;
    twenty_minPosDn = 0;
    twenty_minNegDn = 0;
    twenty_minNegUp = 0;
    twenty_minAggregationPeriod = 0;
}
AddLabel(twenty_minAggregationPeriod, "20m", if twenty_minPosUp then globalColor("twenty_min PosUp") else if twenty_minPosDn then globalColor("twenty_min PosDn") else if twenty_minNegDn then globalColor("twenty_min NegDn") else if twenty_minNegUp then globalColor("twenty_min NegUp") else globalColor("twenty_min Neutral"));



def fifteen_minprice;
def Kfifteen_min;
def fifteen_minmomo;
Def fifteen_min_ExpAverage;
Def fifteen_minpos;
Def fifteen_minneg;
Def fifteen_minup;
Def fifteen_mindn;
Def fifteen_minPosUp;
Def fifteen_minPosDn;
Def fifteen_minNegDn;
Def fifteen_minNegUp;
Def fifteen_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.fifteen_min {
    fifteen_minprice = close(period="15 Min");
    Kfifteen_min = (Highest(high(period="15 Min"), length) + Lowest(low(period="15 Min"), length)) /2 + ExpAverage(close(period="15 Min"), length);
    fifteen_minmomo = Inertia(fifteen_minprice- kfifteen_min / 2, length);
    fifteen_min_ExpAverage = ExpAverage(close(period="15 Min"), Length);
    fifteen_minpos = fifteen_minmomo >= 0;
    fifteen_minneg = fifteen_minmomo < 0;
    fifteen_minup  = fifteen_minmomo >= fifteen_minmomo[1];
    fifteen_mindn  = fifteen_minmomo < fifteen_minmomo[1];

    fifteen_minPosUp = fifteen_minpos and fifteen_minup;
    fifteen_minPosDn = fifteen_minpos and fifteen_mindn;
    fifteen_minNegDn = fifteen_minneg and fifteen_mindn;
    fifteen_minNegUp = fifteen_minneg and fifteen_minup;
    fifteen_minAggregationPeriod = 1;
}
Else {
    fifteen_minprice = 0;
    Kfifteen_min = 0;
    fifteen_minmomo = 0;
    fifteen_min_ExpAverage = 0;
    fifteen_minpos = 0;
    fifteen_minneg = 0;
    fifteen_minup = 0;
    fifteen_mindn = 0;
    fifteen_minPosUp = 0;
    fifteen_minPosDn = 0;
    fifteen_minNegDn = 0;
    fifteen_minNegUp = 0;
    fifteen_minAggregationPeriod = 0;
}
AddLabel(fifteen_minAggregationPeriod, "15m", if fifteen_minPosUp then globalColor("fifteen_min PosUp") else if fifteen_minPosDn then globalColor("fifteen_min PosDn") else if fifteen_minNegDn then globalColor("fifteen_min NegDn") else if fifteen_minNegUp then globalColor("fifteen_min NegUp") else globalColor("fifteen_min Neutral"));



def ten_minprice;
def Kten_min;
def ten_minmomo;
Def ten_min_ExpAverage;
Def ten_minpos;
Def ten_minneg;
Def ten_minup;
Def ten_mindn;
Def ten_minPosUp;
Def ten_minPosDn;
Def ten_minNegDn;
Def ten_minNegUp;
Def ten_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.ten_min {
    ten_minprice = close(period="10 Min");
    Kten_min = (Highest(high(period="10 Min"), length) + Lowest(low(period="10 Min"), length)) /2 + ExpAverage(close(period="10 Min"), length);
    ten_minmomo = Inertia(ten_minprice- kten_min / 2, length);
    ten_min_ExpAverage = ExpAverage(close(period="10 Min"), Length);
    ten_minpos = ten_minmomo >= 0;
    ten_minneg = ten_minmomo < 0;
    ten_minup  = ten_minmomo >= ten_minmomo[1];
    ten_mindn  = ten_minmomo < ten_minmomo[1];

    ten_minPosUp = ten_minpos and ten_minup;
    ten_minPosDn = ten_minpos and ten_mindn;
    ten_minNegDn = ten_minneg and ten_mindn;
    ten_minNegUp = ten_minneg and ten_minup;
    ten_minAggregationPeriod = 1;
}
Else {
    ten_minprice = 0;
    Kten_min = 0;
    ten_minmomo = 0;
    ten_min_ExpAverage = 0;
    ten_minpos = 0;
    ten_minneg = 0;
    ten_minup = 0;
    ten_mindn = 0;
    ten_minPosUp = 0;
    ten_minPosDn = 0;
    ten_minNegDn = 0;
    ten_minNegUp = 0;
    ten_minAggregationPeriod = 0;
}
AddLabel(ten_minAggregationPeriod, "10m", if ten_minPosUp then globalColor("ten_min PosUp") else if ten_minPosDn then globalColor("ten_min PosDn") else if ten_minNegDn then globalColor("ten_min NegDn") else if ten_minNegUp then globalColor("ten_min NegUp") else globalColor("ten_min Neutral"));



def five_minprice;
def Kfive_min;
def five_minmomo;
Def five_min_ExpAverage;
Def five_minpos;
Def five_minneg;
Def five_minup;
Def five_mindn;
Def five_minPosUp;
Def five_minPosDn;
Def five_minNegDn;
Def five_minNegUp;
Def five_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.five_min {
    five_minprice = close(period="5 Min");
    Kfive_min = (Highest(high(period="5 Min"), length) + Lowest(low(period="5 Min"), length)) /2 + ExpAverage(close(period="5 Min"), length);
    five_minmomo = Inertia(five_minprice- kfive_min / 2, length);
    five_min_ExpAverage = ExpAverage(close(period="5 Min"), Length);
    five_minpos = five_minmomo >= 0;
    five_minneg = five_minmomo < 0;
    five_minup  = five_minmomo >= five_minmomo[1];
    five_mindn  = five_minmomo < five_minmomo[1];

    five_minPosUp = five_minpos and five_minup;
    five_minPosDn = five_minpos and five_mindn;
    five_minNegDn = five_minneg and five_mindn;
    five_minNegUp = five_minneg and five_minup;
    five_minAggregationPeriod = 1;
}
Else {
    five_minprice = 0;
    Kfive_min = 0;
    five_minmomo = 0;
    five_min_ExpAverage = 0;
    five_minpos = 0;
    five_minneg = 0;
    five_minup = 0;
    five_mindn = 0;
    five_minPosUp = 0;
    five_minPosDn = 0;
    five_minNegDn = 0;
    five_minNegUp = 0;
    five_minAggregationPeriod = 0;
}
AddLabel(five_minAggregationPeriod, "5m", if five_minPosUp then globalColor("five_min PosUp") else if five_minPosDn then globalColor("five_min PosDn") else if five_minNegDn then globalColor("five_min NegDn") else if five_minNegUp then globalColor("five_min NegUp") else globalColor("five_min Neutral"));



def four_minprice;
def Kfour_min;
def four_minmomo;
Def four_min_ExpAverage;
Def four_minpos;
Def four_minneg;
Def four_minup;
Def four_mindn;
Def four_minPosUp;
Def four_minPosDn;
Def four_minNegDn;
Def four_minNegUp;
Def four_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_min {
    four_minprice = close(period="4 Min");
    Kfour_min = (Highest(high(period="4 Min"), length) + Lowest(low(period="4 Min"), length)) /2 + ExpAverage(close(period="4 Min"), length);
    four_minmomo = Inertia(four_minprice- kfour_min / 2, length);
    four_min_ExpAverage = ExpAverage(close(period="4 Min"), Length);
    four_minpos = four_minmomo >= 0;
    four_minneg = four_minmomo < 0;
    four_minup  = four_minmomo >= four_minmomo[1];
    four_mindn  = four_minmomo < four_minmomo[1];

    four_minPosUp = four_minpos and four_minup;
    four_minPosDn = four_minpos and four_mindn;
    four_minNegDn = four_minneg and four_mindn;
    four_minNegUp = four_minneg and four_minup;
    four_minAggregationPeriod = 1;
}
Else {
    four_minprice = 0;
    Kfour_min = 0;
    four_minmomo = 0;
    four_min_ExpAverage = 0;
    four_minpos = 0;
    four_minneg = 0;
    four_minup = 0;
    four_mindn = 0;
    four_minPosUp = 0;
    four_minPosDn = 0;
    four_minNegDn = 0;
    four_minNegUp = 0;
    four_minAggregationPeriod = 0;
}
AddLabel(four_minAggregationPeriod, "4m", if four_minPosUp then globalColor("four_min PosUp") else if four_minPosDn then globalColor("four_min PosDn") else if four_minNegDn then globalColor("four_min NegDn") else if four_minNegUp then globalColor("four_min NegUp") else globalColor("four_min Neutral"));



def three_minprice;
def Kthree_min;
def three_minmomo;
Def three_min_ExpAverage;
Def three_minpos;
Def three_minneg;
Def three_minup;
Def three_mindn;
Def three_minPosUp;
Def three_minPosDn;
Def three_minNegDn;
Def three_minNegUp;
Def three_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.three_min {
    three_minprice = close(period="3 Min");
    Kthree_min = (Highest(high(period="3 Min"), length) + Lowest(low(period="3 Min"), length)) /2 + ExpAverage(close(period="3 Min"), length);
    three_minmomo = Inertia(three_minprice- kthree_min / 2, length);
    three_min_ExpAverage = ExpAverage(close(period="3 Min"), Length);
    three_minpos = three_minmomo >= 0;
    three_minneg = three_minmomo < 0;
    three_minup  = three_minmomo >= three_minmomo[1];
    three_mindn  = three_minmomo < three_minmomo[1];

    three_minPosUp = three_minpos and three_minup;
    three_minPosDn = three_minpos and three_mindn;
    three_minNegDn = three_minneg and three_mindn;
    three_minNegUp = three_minneg and three_minup;
    three_minAggregationPeriod = 1;
}
Else {
    three_minprice = 0;
    Kthree_min = 0;
    three_minmomo = 0;
    three_min_ExpAverage = 0;
    three_minpos = 0;
    three_minneg = 0;
    three_minup = 0;
    three_mindn = 0;
    three_minPosUp = 0;
    three_minPosDn = 0;
    three_minNegDn = 0;
    three_minNegUp = 0;
    three_minAggregationPeriod = 0;
}
AddLabel(three_minAggregationPeriod, "3m", if three_minPosUp then globalColor("three_min PosUp") else if three_minPosDn then globalColor("three_min PosDn") else if three_minNegDn then globalColor("three_min NegDn") else if three_minNegUp then globalColor("three_min NegUp") else globalColor("three_min Neutral"));



def two_minprice;
def Ktwo_min;
def two_minmomo;
Def two_min_ExpAverage;
Def two_minpos;
Def two_minneg;
Def two_minup;
Def two_mindn;
Def two_minPosUp;
Def two_minPosDn;
Def two_minNegDn;
Def two_minNegUp;
Def two_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_min {
    two_minprice = close(period="2 Min");
    Ktwo_min = (Highest(high(period="2 Min"), length) + Lowest(low(period="2 Min"), length)) /2 + ExpAverage(close(period="2 Min"), length);
    two_minmomo = Inertia(two_minprice- ktwo_min / 2, length);
    two_min_ExpAverage = ExpAverage(close(period="2 Min"), Length);
    two_minpos = two_minmomo >= 0;
    two_minneg = two_minmomo < 0;
    two_minup  = two_minmomo >= two_minmomo[1];
    two_mindn  = two_minmomo < two_minmomo[1];

    two_minPosUp = two_minpos and two_minup;
    two_minPosDn = two_minpos and two_mindn;
    two_minNegDn = two_minneg and two_mindn;
    two_minNegUp = two_minneg and two_minup;
    two_minAggregationPeriod = 1;
}
Else {
    two_minprice = 0;
    Ktwo_min = 0;
    two_minmomo = 0;
    two_min_ExpAverage = 0;
    two_minpos = 0;
    two_minneg = 0;
    two_minup = 0;
    two_mindn = 0;
    two_minPosUp = 0;
    two_minPosDn = 0;
    two_minNegDn = 0;
    two_minNegUp = 0;
    two_minAggregationPeriod = 0;
}
AddLabel(two_minAggregationPeriod, "2m", if two_minPosUp then globalColor("two_min PosUp") else if two_minPosDn then globalColor("two_min PosDn") else if two_minNegDn then globalColor("two_min NegDn") else if two_minNegUp then globalColor("two_min NegUp") else globalColor("two_min Neutral"));



def one_minprice;
def Kone_min;
def one_minmomo;
Def one_min_ExpAverage;
Def one_minpos;
Def one_minneg;
Def one_minup;
Def one_mindn;
Def one_minPosUp;
Def one_minPosDn;
Def one_minNegDn;
Def one_minNegUp;
Def one_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Min {
    one_minprice = close(period="1 Min");
    Kone_min = (Highest(high(period="1 Min"), length) + Lowest(low(period="1 Min"), length)) /2 + ExpAverage(close(period="1 Min"), length);
    one_minmomo = Inertia(one_minprice- kone_min / 2, length);
    one_min_ExpAverage = ExpAverage(close(period="1 Min"), Length);
    one_minpos = one_minmomo >= 0;
    one_minneg = one_minmomo < 0;
    one_minup  = one_minmomo >= one_minmomo[1];
    one_mindn  = one_minmomo < one_minmomo[1];

    one_minPosUp = one_minpos and one_minup;
    one_minPosDn = one_minpos and one_mindn;
    one_minNegDn = one_minneg and one_mindn;
    one_minNegUp = one_minneg and one_minup;
    one_minAggregationPeriod = 1;
}
Else {
    one_minprice = 0;
    Kone_min = 0;
    one_minmomo = 0;
    one_min_ExpAverage = 0;
    one_minpos = 0;
    one_minneg = 0;
    one_minup = 0;
    one_mindn = 0;
    one_minPosUp = 0;
    one_minPosDn = 0;
    one_minNegDn = 0;
    one_minNegUp = 0;
    one_minAggregationPeriod = 0;
}
AddLabel(one_minAggregationPeriod, "1m", if one_minPosUp then globalColor("one_min PosUp") else if one_minPosDn then globalColor("one_min PosDn") else if one_minNegDn then globalColor("one_min NegDn") else if one_minNegUp then globalColor("one_min NegUp") else globalColor("one_min Neutral"));
2gyx1Se.png
Thanx so much!!! I have been trying to build this and have been struggling for hours. Very much appreciate it!!
 
Thank you so much for the code, @caseyjbrett - I'd been bothered for while trying to get histogram labels that better matched what the Squeeze code prints. Your seems to do it better than any I've seen.

I took the liberty of making some modifications to clean up the color naming- you don't need unique color names for each time frame, so it saves a few lines of code. Note that I've also commented out some time frames I don't use in what's below... I havent' gotten to it yet, but I'd prefer to have "input" lines that allow the user to flag whether or not to show a given time frame. Wasn't quite sure how to make those mods yet, so sharing what I have so far:

##MTF Squeeze Histogram Labels
##Created By: Casey Brett
##Global Variables

input price = close;
input length = 20;
input averageType = AverageType.EXPONENTIAL;
input displace = 0;

DefineGlobalColor("BullRising", Color.CYAN);
DefineGlobalColor("BullFalling", CreateColor(102, 102, 255));
DefineGlobalColor("BearFalling", Color.RED);
DefineGlobalColor("BearRising", Color.YELLOW);

DefineGlobalColor("Neutral", Color.GRAY);



def K = (Highest(high, length) + Lowest(low, length)) /2 + ExpAverage(close, length);
def momo = Inertia(price - K / 2, length);

def pos = momo >= 0;
def neg = momo < 0;
def up = momo >= momo[1];
def dn = momo < momo[1];

def PosUp = pos and up;
def PosDn = pos and dn;
def NegDn = neg and dn;
def NegUp = neg and up;


def monthprice;
def Kmonth;
def monthmomo;
Def Month_ExpAverage;
Def monthpos;
Def monthneg;
Def monthup;
Def monthdn;
Def monthPosUp;
Def monthPosDn;
Def monthNegDn;
Def monthNegUp;
Def monthAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Month {
monthprice = close(period="Month");
Kmonth = (Highest(high(period="Month"), length) + Lowest(low(period="Month"), length)) /2 + ExpAverage(close(period="Month"), length);
monthmomo = Inertia(monthprice- kmonth / 2, length);
Month_ExpAverage = ExpAverage(close(period="Month"), Length);
monthpos = monthmomo >= 0;
monthneg = monthmomo < 0;
monthup = monthmomo >= monthmomo[1];
monthdn = monthmomo < monthmomo[1];

monthPosUp = monthpos and monthup;
monthPosDn = monthpos and monthdn;
monthNegDn = monthneg and monthdn;
monthNegUp = monthneg and monthup;
monthAggregationPeriod = 1;
}
Else {
monthprice = 0;
Kmonth = 0;
monthmomo = 0;
Month_ExpAverage = 0;
monthpos = 0;
monthneg = 0;
monthup = 0;
monthdn = 0;
monthPosUp = 0;
monthPosDn = 0;
monthNegDn = 0;
monthNegUp = 0;
monthAggregationPeriod = 0;
}
AddLabel(monthAggregationPeriod, "mo M", if monthPosUp then globalColor("BullRising") else if monthPosDn then globalColor("BullFalling") else if monthNegDn then globalColor("BearFalling") else if monthNegUp then globalColor("BearRising") else globalColor("Neutral"));

def Weekprice;
def KWeek;
def Weekmomo;
Def Week_ExpAverage;
Def Weekpos;
Def Weekneg;
Def Weekup;
Def Weekdn;
Def WeekPosUp;
Def WeekPosDn;
Def WeekNegDn;
Def WeekNegUp;
Def WeekAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Week {
Weekprice = close(period="Week");
KWeek = (Highest(high(period="Week"), length) + Lowest(low(period="Week"), length)) /2 + ExpAverage(close(period="week"), length);
Weekmomo = Inertia(Weekprice- kWeek / 2, length);
Week_ExpAverage = ExpAverage(close(period="Week"), Length);
Weekpos = Weekmomo >= 0;
Weekneg = Weekmomo < 0;
Weekup = Weekmomo >= Weekmomo[1];
Weekdn = Weekmomo < Weekmomo[1];

WeekPosUp = Weekpos and Weekup;
WeekPosDn = Weekpos and Weekdn;
WeekNegDn = Weekneg and Weekdn;
WeekNegUp = Weekneg and Weekup;
WeekAggregationPeriod = 1;
}
Else {
Weekprice = 0;
KWeek = 0;
Weekmomo = 0;
Week_ExpAverage = 0;
Weekpos = 0;
Weekneg = 0;
Weekup = 0;
Weekdn = 0;
WeekPosUp = 0;
WeekPosDn = 0;
WeekNegDn = 0;
WeekNegUp = 0;
WeekAggregationPeriod = 0;
}
AddLabel(WeekAggregationPeriod, "mo W", if WeekPosUp then globalColor("BullRising") else if WeekPosDn then globalColor("BullFalling") else if WeekNegDn then globalColor("BearFalling") else if WeekNegUp then globalColor("BearRising") else globalColor("Neutral"));


def four_daysprice;
def Kfour_days;
def four_daysmomo;
Def four_days_ExpAverage;
Def four_dayspos;
Def four_daysneg;
Def four_daysup;
Def four_daysdn;
Def four_daysPosUp;
Def four_daysPosDn;
Def four_daysNegDn;
Def four_daysNegUp;
Def four_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_days {
four_daysprice = close(period="4 Days");
Kfour_days = (Highest(high(period="4 Days"), length) + Lowest(low(period="4 Days"), length)) /2 + ExpAverage(close(period="4 Days"), length);
four_daysmomo = Inertia(four_daysprice- kfour_days / 2, length);
four_days_ExpAverage = ExpAverage(close(period="4 Days"), Length);
four_dayspos = four_daysmomo >= 0;
four_daysneg = four_daysmomo < 0;
four_daysup = four_daysmomo >= four_daysmomo[1];
four_daysdn = four_daysmomo < four_daysmomo[1];

four_daysPosUp = four_dayspos and four_daysup;
four_daysPosDn = four_dayspos and four_daysdn;
four_daysNegDn = four_daysneg and four_daysdn;
four_daysNegUp = four_daysneg and four_daysup;
four_daysAggregationPeriod = 1;
}
Else {
four_daysprice = 0;
Kfour_days = 0;
four_daysmomo = 0;
four_days_ExpAverage = 0;
four_dayspos = 0;
four_daysneg = 0;
four_daysup = 0;
four_daysdn = 0;
four_daysPosUp = 0;
four_daysPosDn = 0;
four_daysNegDn = 0;
four_daysNegUp = 0;
four_daysAggregationPeriod = 0;
}
AddLabel(four_daysAggregationPeriod, "mo 4D", if four_daysPosUp then globalColor("BullRising") else if four_daysPosDn then globalColor("BullFalling") else if four_daysNegDn then globalColor("BearFalling") else if four_daysNegUp then globalColor("BearRising") else globalColor("Neutral"));

def three_daysprice;
def Kthree_days;
def three_daysmomo;
Def three_days_ExpAverage;
Def three_dayspos;
Def three_daysneg;
Def three_daysup;
Def three_daysdn;
Def three_daysPosUp;
Def three_daysPosDn;
Def three_daysNegDn;
Def three_daysNegUp;
Def three_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.three_days {
three_daysprice = close(period="3 Days");
Kthree_days = (Highest(high(period="3 Days"), length) + Lowest(low(period="3 Days"), length)) /2 + ExpAverage(close(period="3 Days"), length);
three_daysmomo = Inertia(three_daysprice- kthree_days / 2, length);
three_days_ExpAverage = ExpAverage(close(period="3 Days"), Length);
three_dayspos = three_daysmomo >= 0;
three_daysneg = three_daysmomo < 0;
three_daysup = three_daysmomo >= three_daysmomo[1];
three_daysdn = three_daysmomo < three_daysmomo[1];

three_daysPosUp = three_dayspos and three_daysup;
three_daysPosDn = three_dayspos and three_daysdn;
three_daysNegDn = three_daysneg and three_daysdn;
three_daysNegUp = three_daysneg and three_daysup;
three_daysAggregationPeriod = 1;
}
Else {
three_daysprice = 0;
Kthree_days = 0;
three_daysmomo = 0;
three_days_ExpAverage = 0;
three_dayspos = 0;
three_daysneg = 0;
three_daysup = 0;
three_daysdn = 0;
three_daysPosUp = 0;
three_daysPosDn = 0;
three_daysNegDn = 0;
three_daysNegUp = 0;
three_daysAggregationPeriod = 0;
}
AddLabel(three_daysAggregationPeriod, "mo 3D", if three_daysPosUp then globalColor("BullRising") else if three_daysPosDn then globalColor("BullFalling") else if three_daysNegDn then globalColor("BearFalling") else if three_daysNegUp then globalColor("BearRising") else globalColor("Neutral"));




def two_daysprice;
def Ktwo_days;
def two_daysmomo;
Def two_days_ExpAverage;
Def two_dayspos;
Def two_daysneg;
Def two_daysup;
Def two_daysdn;
Def two_daysPosUp;
Def two_daysPosDn;
Def two_daysNegDn;
Def two_daysNegUp;
Def two_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_days {
two_daysprice = close(period="2 Days");
Ktwo_days = (Highest(high(period="2 Days"), length) + Lowest(low(period="2 Days"), length)) /2 + ExpAverage(close(period="2 Days"), length);
two_daysmomo = Inertia(two_daysprice- ktwo_days / 2, length);
two_days_ExpAverage = ExpAverage(close(period="2 Days"), Length);
two_dayspos = two_daysmomo >= 0;
two_daysneg = two_daysmomo < 0;
two_daysup = two_daysmomo >= two_daysmomo[1];
two_daysdn = two_daysmomo < two_daysmomo[1];

two_daysPosUp = two_dayspos and two_daysup;
two_daysPosDn = two_dayspos and two_daysdn;
two_daysNegDn = two_daysneg and two_daysdn;
two_daysNegUp = two_daysneg and two_daysup;
two_daysAggregationPeriod = 1;
}
Else {
two_daysprice = 0;
Ktwo_days = 0;
two_daysmomo = 0;
two_days_ExpAverage = 0;
two_dayspos = 0;
two_daysneg = 0;
two_daysup = 0;
two_daysdn = 0;
two_daysPosUp = 0;
two_daysPosDn = 0;
two_daysNegDn = 0;
two_daysNegUp = 0;
two_daysAggregationPeriod = 0;
}
AddLabel(two_daysAggregationPeriod, "mo 2D", if two_daysPosUp then globalColor("BullRising") else if two_daysPosDn then globalColor("BullFalling") else if two_daysNegDn then globalColor("BearFalling") else if two_daysNegUp then globalColor("BearRising") else globalColor("Neutral"));


def Dayprice;
def KDay;
def Daymomo;
Def Day_ExpAverage;
Def Daypos;
Def Dayneg;
Def Dayup;
Def Daydn;
Def DayPosUp;
Def DayPosDn;
Def DayNegDn;
Def DayNegUp;
Def DayAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Day {
Dayprice = close(period="Day");
KDay = (Highest(high(period="Day"), length) + Lowest(low(period="Day"), length)) /2 + ExpAverage(close(period="Day"), length);
Daymomo = Inertia(Dayprice- kDay / 2, length);
Day_ExpAverage = ExpAverage(close(period="Day"), Length);
Daypos = Daymomo >= 0;
Dayneg = Daymomo < 0;
Dayup = Daymomo >= Daymomo[1];
Daydn = Daymomo < Daymomo[1];

DayPosUp = Daypos and Dayup;
DayPosDn = Daypos and Daydn;
DayNegDn = Dayneg and Daydn;
DayNegUp = Dayneg and Dayup;
DayAggregationPeriod = 1;
}
Else {
Dayprice = 0;
KDay = 0;
Daymomo = 0;
Day_ExpAverage = 0;
Daypos = 0;
Dayneg = 0;
Dayup = 0;
Daydn = 0;
DayPosUp = 0;
DayPosDn = 0;
DayNegDn = 0;
DayNegUp = 0;
DayAggregationPeriod = 0;
}
AddLabel(DayAggregationPeriod, "mo D", if DayPosUp then globalColor("BullRising") else if DayPosDn then globalColor("BullFalling") else if DayNegDn then globalColor("BearFalling") else if DayNegUp then globalColor("BearRising") else globalColor("Neutral"));


def four_hoursprice;
def Kfour_hours;
def four_hoursmomo;
Def four_hours_ExpAverage;
Def four_hourspos;
Def four_hoursneg;
Def four_hoursup;
Def four_hoursdn;
Def four_hoursPosUp;
Def four_hoursPosDn;
Def four_hoursNegDn;
Def four_hoursNegUp;
Def four_hoursAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_hours {
four_hoursprice = close(period="4 Hours");
Kfour_hours = (Highest(high(period="4 Hours"), length) + Lowest(low(period="4 Hours"), length)) /2 + ExpAverage(close(period="4 Hours"), length);
four_hoursmomo = Inertia(four_hoursprice- kfour_hours / 2, length);
four_hours_ExpAverage = ExpAverage(close(period="4 Hours"), Length);
four_hourspos = four_hoursmomo >= 0;
four_hoursneg = four_hoursmomo < 0;
four_hoursup = four_hoursmomo >= four_hoursmomo[1];
four_hoursdn = four_hoursmomo < four_hoursmomo[1];

four_hoursPosUp = four_hourspos and four_hoursup;
four_hoursPosDn = four_hourspos and four_hoursdn;
four_hoursNegDn = four_hoursneg and four_hoursdn;
four_hoursNegUp = four_hoursneg and four_hoursup;
four_hoursAggregationPeriod = 1;
}
Else {
four_hoursprice = 0;
Kfour_hours = 0;
four_hoursmomo = 0;
four_hours_ExpAverage = 0;
four_hourspos = 0;
four_hoursneg = 0;
four_hoursup = 0;
four_hoursdn = 0;
four_hoursPosUp = 0;
four_hoursPosDn = 0;
four_hoursNegDn = 0;
four_hoursNegUp = 0;
four_hoursAggregationPeriod = 0;
}
AddLabel(four_hoursAggregationPeriod, "mo 4h", if four_hoursPosUp then globalColor("BullRising") else if four_hoursPosDn then globalColor("BullFalling") else if four_hoursNegDn then globalColor("BearFalling") else if four_hoursNegUp then globalColor("BearRising") else globalColor("Neutral"));



def two_hoursprice;
def Ktwo_hours;
def two_hoursmomo;
Def two_hours_ExpAverage;
Def two_hourspos;
Def two_hoursneg;
Def two_hoursup;
Def two_hoursdn;
Def two_hoursPosUp;
Def two_hoursPosDn;
Def two_hoursNegDn;
Def two_hoursNegUp;
Def two_hoursAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_hours {
two_hoursprice = close(period="2 Hours");
Ktwo_hours = (Highest(high(period="2 Hours"), length) + Lowest(low(period="2 Hours"), length)) /2 + ExpAverage(close(period="2 Hours"), length);
two_hoursmomo = Inertia(two_hoursprice- ktwo_hours / 2, length);
two_hours_ExpAverage = ExpAverage(close(period="2 Hours"), Length);
two_hourspos = two_hoursmomo >= 0;
two_hoursneg = two_hoursmomo < 0;
two_hoursup = two_hoursmomo >= two_hoursmomo[1];
two_hoursdn = two_hoursmomo < two_hoursmomo[1];

two_hoursPosUp = two_hourspos and two_hoursup;
two_hoursPosDn = two_hourspos and two_hoursdn;
two_hoursNegDn = two_hoursneg and two_hoursdn;
two_hoursNegUp = two_hoursneg and two_hoursup;
two_hoursAggregationPeriod = 1;
}
Else {
two_hoursprice = 0;
Ktwo_hours = 0;
two_hoursmomo = 0;
two_hours_ExpAverage = 0;
two_hourspos = 0;
two_hoursneg = 0;
two_hoursup = 0;
two_hoursdn = 0;
two_hoursPosUp = 0;
two_hoursPosDn = 0;
two_hoursNegDn = 0;
two_hoursNegUp = 0;
two_hoursAggregationPeriod = 0;
}
AddLabel(two_hoursAggregationPeriod, "mo 2h", if two_hoursPosUp then globalColor("BullRising") else if two_hoursPosDn then globalColor("BullFalling") else if two_hoursNegDn then globalColor("BearFalling") else if two_hoursNegUp then globalColor("BearRising") else globalColor("Neutral"));



def hourprice;
def Khour;
def hourmomo;
Def hour_ExpAverage;
Def hourpos;
Def hourneg;
Def hourup;
Def hourdn;
Def hourPosUp;
Def hourPosDn;
Def hourNegDn;
Def hourNegUp;
Def hourAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.hour {
hourprice = close(period="1 Hour");
Khour = (Highest(high(period="1 Hour"), length) + Lowest(low(period="1 Hour"), length)) /2 + ExpAverage(close(period="1 Hour"), length);
hourmomo = Inertia(hourprice- khour / 2, length);
hour_ExpAverage = ExpAverage(close(period="1 Hour"), Length);
hourpos = hourmomo >= 0;
hourneg = hourmomo < 0;
hourup = hourmomo >= hourmomo[1];
hourdn = hourmomo < hourmomo[1];

hourPosUp = hourpos and hourup;
hourPosDn = hourpos and hourdn;
hourNegDn = hourneg and hourdn;
hourNegUp = hourneg and hourup;
hourAggregationPeriod = 1;
}
Else {
hourprice = 0;
Khour = 0;
hourmomo = 0;
hour_ExpAverage = 0;
hourpos = 0;
hourneg = 0;
hourup = 0;
hourdn = 0;
hourPosUp = 0;
hourPosDn = 0;
hourNegDn = 0;
hourNegUp = 0;
hourAggregationPeriod = 0;
}
AddLabel(hourAggregationPeriod, "mo 1h", if hourPosUp then globalColor("BullRising") else if hourPosDn then globalColor("BullFalling") else if hourNegDn then globalColor("BearFalling") else if hourNegUp then globalColor("BearRising") else globalColor("Neutral"));



def thirty_minprice;
def Kthirty_min;
def thirty_minmomo;
Def thirty_min_ExpAverage;
Def thirty_minpos;
Def thirty_minneg;
Def thirty_minup;
Def thirty_mindn;
Def thirty_minPosUp;
Def thirty_minPosDn;
Def thirty_minNegDn;
Def thirty_minNegUp;
Def thirty_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.thirty_min {
thirty_minprice = close(period="30 Min");
Kthirty_min = (Highest(high(period="30 Min"), length) + Lowest(low(period="30 Min"), length)) /2 + ExpAverage(close(period="30 Min"), length);
thirty_minmomo = Inertia(thirty_minprice- kthirty_min / 2, length);
thirty_min_ExpAverage = ExpAverage(close(period="30 Min"), Length);
thirty_minpos = thirty_minmomo >= 0;
thirty_minneg = thirty_minmomo < 0;
thirty_minup = thirty_minmomo >= thirty_minmomo[1];
thirty_mindn = thirty_minmomo < thirty_minmomo[1];

thirty_minPosUp = thirty_minpos and thirty_minup;
thirty_minPosDn = thirty_minpos and thirty_mindn;
thirty_minNegDn = thirty_minneg and thirty_mindn;
thirty_minNegUp = thirty_minneg and thirty_minup;
thirty_minAggregationPeriod = 1;
}
Else {
thirty_minprice = 0;
Kthirty_min = 0;
thirty_minmomo = 0;
thirty_min_ExpAverage = 0;
thirty_minpos = 0;
thirty_minneg = 0;
thirty_minup = 0;
thirty_mindn = 0;
thirty_minPosUp = 0;
thirty_minPosDn = 0;
thirty_minNegDn = 0;
thirty_minNegUp = 0;
thirty_minAggregationPeriod = 0;
}
AddLabel(thirty_minAggregationPeriod, "mo 30m", if thirty_minPosUp then globalColor("BullRising") else if thirty_minPosDn then globalColor("BullFalling") else if thirty_minNegDn then globalColor("BearFalling") else if thirty_minNegUp then globalColor("BearRising") else globalColor("Neutral"));



def twenty_minprice;
def Ktwenty_min;
def twenty_minmomo;
Def twenty_min_ExpAverage;
Def twenty_minpos;
Def twenty_minneg;
Def twenty_minup;
Def twenty_mindn;
Def twenty_minPosUp;
Def twenty_minPosDn;
Def twenty_minNegDn;
Def twenty_minNegUp;
Def twenty_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.twenty_min {
twenty_minprice = close(period="20 Min");
Ktwenty_min = (Highest(high(period="20 Min"), length) + Lowest(low(period="20 Min"), length)) /2 + ExpAverage(close(period="20 Min"), length);
twenty_minmomo = Inertia(twenty_minprice- ktwenty_min / 2, length);
twenty_min_ExpAverage = ExpAverage(close(period="20 Min"), Length);
twenty_minpos = twenty_minmomo >= 0;
twenty_minneg = twenty_minmomo < 0;
twenty_minup = twenty_minmomo >= twenty_minmomo[1];
twenty_mindn = twenty_minmomo < twenty_minmomo[1];

twenty_minPosUp = twenty_minpos and twenty_minup;
twenty_minPosDn = twenty_minpos and twenty_mindn;
twenty_minNegDn = twenty_minneg and twenty_mindn;
twenty_minNegUp = twenty_minneg and twenty_minup;
twenty_minAggregationPeriod = 1;
}
Else {
twenty_minprice = 0;
Ktwenty_min = 0;
twenty_minmomo = 0;
twenty_min_ExpAverage = 0;
twenty_minpos = 0;
twenty_minneg = 0;
twenty_minup = 0;
twenty_mindn = 0;
twenty_minPosUp = 0;
twenty_minPosDn = 0;
twenty_minNegDn = 0;
twenty_minNegUp = 0;
twenty_minAggregationPeriod = 0;
}
#AddLabel(twenty_minAggregationPeriod, "mo 20m", if twenty_minPosUp #then globalColor("BullRising") else if twenty_minPosDn then #globalColor("BullFalling") else if twenty_minNegDn then #globalColor("BearFalling") else if twenty_minNegUp then #globalColor("BearRising") else globalColor("Neutral"));



def fifteen_minprice;
def Kfifteen_min;
def fifteen_minmomo;
Def fifteen_min_ExpAverage;
Def fifteen_minpos;
Def fifteen_minneg;
Def fifteen_minup;
Def fifteen_mindn;
Def fifteen_minPosUp;
Def fifteen_minPosDn;
Def fifteen_minNegDn;
Def fifteen_minNegUp;
Def fifteen_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.fifteen_min {
fifteen_minprice = close(period="15 Min");
Kfifteen_min = (Highest(high(period="15 Min"), length) + Lowest(low(period="15 Min"), length)) /2 + ExpAverage(close(period="15 Min"), length);
fifteen_minmomo = Inertia(fifteen_minprice- kfifteen_min / 2, length);
fifteen_min_ExpAverage = ExpAverage(close(period="15 Min"), Length);
fifteen_minpos = fifteen_minmomo >= 0;
fifteen_minneg = fifteen_minmomo < 0;
fifteen_minup = fifteen_minmomo >= fifteen_minmomo[1];
fifteen_mindn = fifteen_minmomo < fifteen_minmomo[1];

fifteen_minPosUp = fifteen_minpos and fifteen_minup;
fifteen_minPosDn = fifteen_minpos and fifteen_mindn;
fifteen_minNegDn = fifteen_minneg and fifteen_mindn;
fifteen_minNegUp = fifteen_minneg and fifteen_minup;
fifteen_minAggregationPeriod = 1;
}
Else {
fifteen_minprice = 0;
Kfifteen_min = 0;
fifteen_minmomo = 0;
fifteen_min_ExpAverage = 0;
fifteen_minpos = 0;
fifteen_minneg = 0;
fifteen_minup = 0;
fifteen_mindn = 0;
fifteen_minPosUp = 0;
fifteen_minPosDn = 0;
fifteen_minNegDn = 0;
fifteen_minNegUp = 0;
fifteen_minAggregationPeriod = 0;
}
AddLabel(fifteen_minAggregationPeriod, "mo 15m", if fifteen_minPosUp then globalColor("BullRising") else if fifteen_minPosDn then globalColor("BullFalling") else if fifteen_minNegDn then globalColor("BearFalling") else if fifteen_minNegUp then globalColor("BearRising") else globalColor("Neutral"));



def ten_minprice;
def Kten_min;
def ten_minmomo;
Def ten_min_ExpAverage;
Def ten_minpos;
Def ten_minneg;
Def ten_minup;
Def ten_mindn;
Def ten_minPosUp;
Def ten_minPosDn;
Def ten_minNegDn;
Def ten_minNegUp;
Def ten_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.ten_min {
ten_minprice = close(period="10 Min");
Kten_min = (Highest(high(period="10 Min"), length) + Lowest(low(period="10 Min"), length)) /2 + ExpAverage(close(period="10 Min"), length);
ten_minmomo = Inertia(ten_minprice- kten_min / 2, length);
ten_min_ExpAverage = ExpAverage(close(period="10 Min"), Length);
ten_minpos = ten_minmomo >= 0;
ten_minneg = ten_minmomo < 0;
ten_minup = ten_minmomo >= ten_minmomo[1];
ten_mindn = ten_minmomo < ten_minmomo[1];

ten_minPosUp = ten_minpos and ten_minup;
ten_minPosDn = ten_minpos and ten_mindn;
ten_minNegDn = ten_minneg and ten_mindn;
ten_minNegUp = ten_minneg and ten_minup;
ten_minAggregationPeriod = 1;
}
Else {
ten_minprice = 0;
Kten_min = 0;
ten_minmomo = 0;
ten_min_ExpAverage = 0;
ten_minpos = 0;
ten_minneg = 0;
ten_minup = 0;
ten_mindn = 0;
ten_minPosUp = 0;
ten_minPosDn = 0;
ten_minNegDn = 0;
ten_minNegUp = 0;
ten_minAggregationPeriod = 0;
}
AddLabel(ten_minAggregationPeriod, "mo 10m", if ten_minPosUp then globalColor("BullRising") else if ten_minPosDn then globalColor("BullFalling") else if ten_minNegDn then globalColor("BearFalling") else if ten_minNegUp then globalColor("BearRising") else globalColor("Neutral"));



def five_minprice;
def Kfive_min;
def five_minmomo;
Def five_min_ExpAverage;
Def five_minpos;
Def five_minneg;
Def five_minup;
Def five_mindn;
Def five_minPosUp;
Def five_minPosDn;
Def five_minNegDn;
Def five_minNegUp;
Def five_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.five_min {
five_minprice = close(period="5 Min");
Kfive_min = (Highest(high(period="5 Min"), length) + Lowest(low(period="5 Min"), length)) /2 + ExpAverage(close(period="5 Min"), length);
five_minmomo = Inertia(five_minprice- kfive_min / 2, length);
five_min_ExpAverage = ExpAverage(close(period="5 Min"), Length);
five_minpos = five_minmomo >= 0;
five_minneg = five_minmomo < 0;
five_minup = five_minmomo >= five_minmomo[1];
five_mindn = five_minmomo < five_minmomo[1];

five_minPosUp = five_minpos and five_minup;
five_minPosDn = five_minpos and five_mindn;
five_minNegDn = five_minneg and five_mindn;
five_minNegUp = five_minneg and five_minup;
five_minAggregationPeriod = 1;
}
Else {
five_minprice = 0;
Kfive_min = 0;
five_minmomo = 0;
five_min_ExpAverage = 0;
five_minpos = 0;
five_minneg = 0;
five_minup = 0;
five_mindn = 0;
five_minPosUp = 0;
five_minPosDn = 0;
five_minNegDn = 0;
five_minNegUp = 0;
five_minAggregationPeriod = 0;
}
AddLabel(five_minAggregationPeriod, "mo 5m", if five_minPosUp then globalColor("BullRising") else if five_minPosDn then globalColor("BullFalling") else if five_minNegDn then globalColor("BearFalling") else if five_minNegUp then globalColor("BearRising") else globalColor("Neutral"));



def four_minprice;
def Kfour_min;
def four_minmomo;
Def four_min_ExpAverage;
Def four_minpos;
Def four_minneg;
Def four_minup;
Def four_mindn;
Def four_minPosUp;
Def four_minPosDn;
Def four_minNegDn;
Def four_minNegUp;
Def four_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_min {
four_minprice = close(period="4 Min");
Kfour_min = (Highest(high(period="4 Min"), length) + Lowest(low(period="4 Min"), length)) /2 + ExpAverage(close(period="4 Min"), length);
four_minmomo = Inertia(four_minprice- kfour_min / 2, length);
four_min_ExpAverage = ExpAverage(close(period="4 Min"), Length);
four_minpos = four_minmomo >= 0;
four_minneg = four_minmomo < 0;
four_minup = four_minmomo >= four_minmomo[1];
four_mindn = four_minmomo < four_minmomo[1];

four_minPosUp = four_minpos and four_minup;
four_minPosDn = four_minpos and four_mindn;
four_minNegDn = four_minneg and four_mindn;
four_minNegUp = four_minneg and four_minup;
four_minAggregationPeriod = 1;
}
Else {
four_minprice = 0;
Kfour_min = 0;
four_minmomo = 0;
four_min_ExpAverage = 0;
four_minpos = 0;
four_minneg = 0;
four_minup = 0;
four_mindn = 0;
four_minPosUp = 0;
four_minPosDn = 0;
four_minNegDn = 0;
four_minNegUp = 0;
four_minAggregationPeriod = 0;
}
#AddLabel(four_minAggregationPeriod, "mo 4m", if four_minPosUp then globalColor("BullRising") else if four_minPosDn then globalColor("BullFalling") else if four_minNegDn then globalColor("BearFalling") else if four_minNegUp then globalColor("BearRising") else globalColor("Neutral"));



def three_minprice;
def Kthree_min;
def three_minmomo;
Def three_min_ExpAverage;
Def three_minpos;
Def three_minneg;
Def three_minup;
Def three_mindn;
Def three_minPosUp;
Def three_minPosDn;
Def three_minNegDn;
Def three_minNegUp;
Def three_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.three_min {
three_minprice = close(period="3 Min");
Kthree_min = (Highest(high(period="3 Min"), length) + Lowest(low(period="3 Min"), length)) /2 + ExpAverage(close(period="3 Min"), length);
three_minmomo = Inertia(three_minprice- kthree_min / 2, length);
three_min_ExpAverage = ExpAverage(close(period="3 Min"), Length);
three_minpos = three_minmomo >= 0;
three_minneg = three_minmomo < 0;
three_minup = three_minmomo >= three_minmomo[1];
three_mindn = three_minmomo < three_minmomo[1];

three_minPosUp = three_minpos and three_minup;
three_minPosDn = three_minpos and three_mindn;
three_minNegDn = three_minneg and three_mindn;
three_minNegUp = three_minneg and three_minup;
three_minAggregationPeriod = 1;
}
Else {
three_minprice = 0;
Kthree_min = 0;
three_minmomo = 0;
three_min_ExpAverage = 0;
three_minpos = 0;
three_minneg = 0;
three_minup = 0;
three_mindn = 0;
three_minPosUp = 0;
three_minPosDn = 0;
three_minNegDn = 0;
three_minNegUp = 0;
three_minAggregationPeriod = 0;
}
AddLabel(three_minAggregationPeriod, "mo 3m", if three_minPosUp then globalColor("BullRising") else if three_minPosDn then globalColor("BullFalling") else if three_minNegDn then globalColor("BearFalling") else if three_minNegUp then globalColor("BearRising") else globalColor("Neutral"));



def two_minprice;
def Ktwo_min;
def two_minmomo;
Def two_min_ExpAverage;
Def two_minpos;
Def two_minneg;
Def two_minup;
Def two_mindn;
Def two_minPosUp;
Def two_minPosDn;
Def two_minNegDn;
Def two_minNegUp;
Def two_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_min {
two_minprice = close(period="2 Min");
Ktwo_min = (Highest(high(period="2 Min"), length) + Lowest(low(period="2 Min"), length)) /2 + ExpAverage(close(period="2 Min"), length);
two_minmomo = Inertia(two_minprice- ktwo_min / 2, length);
two_min_ExpAverage = ExpAverage(close(period="2 Min"), Length);
two_minpos = two_minmomo >= 0;
two_minneg = two_minmomo < 0;
two_minup = two_minmomo >= two_minmomo[1];
two_mindn = two_minmomo < two_minmomo[1];

two_minPosUp = two_minpos and two_minup;
two_minPosDn = two_minpos and two_mindn;
two_minNegDn = two_minneg and two_mindn;
two_minNegUp = two_minneg and two_minup;
two_minAggregationPeriod = 1;
}
Else {
two_minprice = 0;
Ktwo_min = 0;
two_minmomo = 0;
two_min_ExpAverage = 0;
two_minpos = 0;
two_minneg = 0;
two_minup = 0;
two_mindn = 0;
two_minPosUp = 0;
two_minPosDn = 0;
two_minNegDn = 0;
two_minNegUp = 0;
two_minAggregationPeriod = 0;
}
#AddLabel(two_minAggregationPeriod, "mo 2m", if two_minPosUp then globalColor("BullRising") else if two_minPosDn then globalColor("BullFalling") else if two_minNegDn then globalColor("BearFalling") else if two_minNegUp then globalColor("BearRising") else globalColor("Neutral"));



def one_minprice;
def Kone_min;
def one_minmomo;
Def one_min_ExpAverage;
Def one_minpos;
Def one_minneg;
Def one_minup;
Def one_mindn;
Def one_minPosUp;
Def one_minPosDn;
Def one_minNegDn;
Def one_minNegUp;
Def one_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Min {
one_minprice = close(period="1 Min");
Kone_min = (Highest(high(period="1 Min"), length) + Lowest(low(period="1 Min"), length)) /2 + ExpAverage(close(period="1 Min"), length);
one_minmomo = Inertia(one_minprice- kone_min / 2, length);
one_min_ExpAverage = ExpAverage(close(period="1 Min"), Length);
one_minpos = one_minmomo >= 0;
one_minneg = one_minmomo < 0;
one_minup = one_minmomo >= one_minmomo[1];
one_mindn = one_minmomo < one_minmomo[1];

one_minPosUp = one_minpos and one_minup;
one_minPosDn = one_minpos and one_mindn;
one_minNegDn = one_minneg and one_mindn;
one_minNegUp = one_minneg and one_minup;
one_minAggregationPeriod = 1;
}
Else {
one_minprice = 0;
Kone_min = 0;
one_minmomo = 0;
one_min_ExpAverage = 0;
one_minpos = 0;
one_minneg = 0;
one_minup = 0;
one_mindn = 0;
one_minPosUp = 0;
one_minPosDn = 0;
one_minNegDn = 0;
one_minNegUp = 0;
one_minAggregationPeriod = 0;
}
AddLabel(one_minAggregationPeriod, "mo 1m", if one_minPosUp then globalColor("BullRising") else if one_minPosDn then globalColor("BullFalling") else if one_minNegDn then globalColor("BearFalling") else if one_minNegUp then globalColor("BearRising") else globalColor("Neutral"));
 
Thank you so much for the code, @caseyjbrett - I'd been bothered for while trying to get histogram labels that better matched what the Squeeze code prints. Your seems to do it better than any I've seen.

I took the liberty of making some modifications to clean up the color naming- you don't need unique color names for each time frame, so it saves a few lines of code. Note that I've also commented out some time frames I don't use in what's below... I havent' gotten to it yet, but I'd prefer to have "input" lines that allow the user to flag whether or not to show a given time frame. Wasn't quite sure how to make those mods yet, so sharing what I have so far:
You're so very welcome for the code. I'm glad my time writing it wasn't just wasted on myself! It makes it worthwhile that other people are enjoying it. I just took a minute to check it out. I mistakenly applied your request to the "Squeeze Pro Labels" script. I will do it to the histogram labels as well when I get a chance later. This new Squeeze Pro Labels script is more succinct - I removed the redundant GlobalColor variables. I also allowed input for each time frame. This means that each squeeze label can be toggled on or off! I'm going to post the updated Squeeze Pro Labels script under that thread. I'll post the updated Histogram one here when I fix it later.
 
Thank you so much for the code, @caseyjbrett - I'd been bothered for while trying to get histogram labels that better matched what the Squeeze code prints. Your seems to do it better than any I've seen.

I took the liberty of making some modifications to clean up the color naming- you don't need unique color names for each time frame, so it saves a few lines of code. Note that I've also commented out some time frames I don't use in what's below... I havent' gotten to it yet, but I'd prefer to have "input" lines that allow the user to flag whether or not to show a given time frame. Wasn't quite sure how to make those mods yet, so sharing what I have so far:
See the revised code attached. Took out the GlobalColor redundancies and added on/off selections for each time frame! I'm going to edit the script at the top of this thread with this new version as well.
Code:
##MTF Squeeze Histogram Labels
##Created By: Casey Brett
##Global Variables

input price = close;
input length = 20;
input averageType = AverageType.EXPONENTIAL;
input displace = 0;

def K = (Highest(high, length) + Lowest(low, length)) /2 + ExpAverage(close, length);
def momo = Inertia(price - K / 2, length);

def pos         = momo >= 0;
def neg         = momo < 0;
def up         = momo >= momo[1];
def dn         = momo < momo[1];

def PosUp = pos and up;
def PosDn = pos and dn;
def NegDn = neg and dn;
def NegUp = neg and up;

input MonthLabel = yes;
input WeekLabel = yes;
input FourDayLabel = yes;
input ThreeDayLabel = yes;
input TwoDayLabel = yes;
input DayLabel = yes;
input FourHourLabel = yes;
input TwoHourLabel = yes;
input OneHourLabel = yes;
input ThirtyMinLabel = yes;
input TwentyMinLabel = yes;
input FifteenMinLabel = yes;
input TenMinLabel = yes;
input FiveMinLabel = yes;
input FourMinLabel = yes;
input ThreeMinLabel = yes;
input TwoMinLabel = yes;
input OneMinLabel = yes;


defineGlobalColor("PosUp", color.cyan);
defineGlobalColor("PosDn", color.blue);
defineGlobalColor("NegDn", color.red);
defineGlobalColor("NegUp", color.yellow);
defineGlobalColor("Neutral", color.gray);

def monthprice;
def Kmonth;
def monthmomo;
Def Month_ExpAverage;
Def monthpos;
Def monthneg;
Def monthup;
Def monthdn;
Def monthPosUp;
Def monthPosDn;
Def monthNegDn;
Def monthNegUp;
Def monthAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Month {
    monthprice = close(period="Month");
    Kmonth = (Highest(high(period="Month"), length) + Lowest(low(period="Month"), length)) /2 + ExpAverage(close(period="Month"), length);
    monthmomo = Inertia(monthprice- kmonth / 2, length);
    Month_ExpAverage = ExpAverage(close(period="Month"), Length);
    monthpos = monthmomo >= 0;
    monthneg = monthmomo < 0;
    monthup  = monthmomo >= monthmomo[1];
    monthdn  = monthmomo < monthmomo[1];

    monthPosUp = monthpos and monthup;
    monthPosDn = monthpos and monthdn;
    monthNegDn = monthneg and monthdn;
    monthNegUp = monthneg and monthup;
    monthAggregationPeriod = 1;
}
Else {
    monthprice = 0;
    Kmonth = 0;
    monthmomo = 0;
    Month_ExpAverage = 0;
    monthpos = 0;
    monthneg = 0;
    monthup = 0;
    monthdn = 0;
    monthPosUp = 0;
    monthPosDn = 0;
    monthNegDn = 0;
    monthNegUp = 0;
    monthAggregationPeriod = 0;
}
AddLabel(monthLabel and monthAggregationPeriod, "M", if monthPosUp then globalColor("PosUp") else if monthPosDn then globalColor("PosDn") else if monthNegDn then globalColor("NegDn") else if monthNegUp then globalColor("NegUp") else globalColor("Neutral"));

def Weekprice;
def KWeek;
def Weekmomo;
Def Week_ExpAverage;
Def Weekpos;
Def Weekneg;
Def Weekup;
Def Weekdn;
Def WeekPosUp;
Def WeekPosDn;
Def WeekNegDn;
Def WeekNegUp;
Def WeekAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Week {
    Weekprice = close(period="Week");
    KWeek = (Highest(high(period="Week"), length) + Lowest(low(period="Week"), length)) /2 + ExpAverage(close(period="week"), length);
    Weekmomo = Inertia(Weekprice- kWeek / 2, length);
    Week_ExpAverage = ExpAverage(close(period="Week"), Length);
    Weekpos = Weekmomo >= 0;
    Weekneg = Weekmomo < 0;
    Weekup  = Weekmomo >= Weekmomo[1];
    Weekdn  = Weekmomo < Weekmomo[1];

    WeekPosUp = Weekpos and Weekup;
    WeekPosDn = Weekpos and Weekdn;
    WeekNegDn = Weekneg and Weekdn;
    WeekNegUp = Weekneg and Weekup;
    WeekAggregationPeriod = 1;
}
Else {
    Weekprice = 0;
    KWeek = 0;
    Weekmomo = 0;
    Week_ExpAverage = 0;
    Weekpos = 0;
    Weekneg = 0;
    Weekup = 0;
    Weekdn = 0;
    WeekPosUp = 0;
    WeekPosDn = 0;
    WeekNegDn = 0;
    WeekNegUp = 0;
    WeekAggregationPeriod = 0;
}
AddLabel(WeekLabel and WeekAggregationPeriod, "W", if WeekPosUp then globalColor("PosUp") else if WeekPosDn then globalColor("PosDn") else if WeekNegDn then globalColor("NegDn") else if WeekNegUp then globalColor("NegUp") else globalColor("Neutral"));


def four_daysprice;
def Kfour_days;
def four_daysmomo;
Def four_days_ExpAverage;
Def four_dayspos;
Def four_daysneg;
Def four_daysup;
Def four_daysdn;
Def four_daysPosUp;
Def four_daysPosDn;
Def four_daysNegDn;
Def four_daysNegUp;
Def four_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_days {
    four_daysprice = close(period="4 Days");
    Kfour_days = (Highest(high(period="4 Days"), length) + Lowest(low(period="4 Days"), length)) /2 + ExpAverage(close(period="4 Days"), length);
    four_daysmomo = Inertia(four_daysprice- kfour_days / 2, length);
    four_days_ExpAverage = ExpAverage(close(period="4 Days"), Length);
    four_dayspos = four_daysmomo >= 0;
    four_daysneg = four_daysmomo < 0;
    four_daysup  = four_daysmomo >= four_daysmomo[1];
    four_daysdn  = four_daysmomo < four_daysmomo[1];

    four_daysPosUp = four_dayspos and four_daysup;
    four_daysPosDn = four_dayspos and four_daysdn;
    four_daysNegDn = four_daysneg and four_daysdn;
    four_daysNegUp = four_daysneg and four_daysup;
    four_daysAggregationPeriod = 1;
}
Else {
    four_daysprice = 0;
    Kfour_days = 0;
    four_daysmomo = 0;
    four_days_ExpAverage = 0;
    four_dayspos = 0;
    four_daysneg = 0;
    four_daysup = 0;
    four_daysdn = 0;
    four_daysPosUp = 0;
    four_daysPosDn = 0;
    four_daysNegDn = 0;
    four_daysNegUp = 0;
    four_daysAggregationPeriod = 0;
}
AddLabel(FourDayLabel and four_daysAggregationPeriod, "4D", if four_daysPosUp then globalColor("PosUp") else if four_daysPosDn then globalColor("PosDn") else if four_daysNegDn then globalColor("NegDn") else if four_daysNegUp then globalColor("NegUp") else globalColor("Neutral"));

def three_daysprice;
def Kthree_days;
def three_daysmomo;
Def three_days_ExpAverage;
Def three_dayspos;
Def three_daysneg;
Def three_daysup;
Def three_daysdn;
Def three_daysPosUp;
Def three_daysPosDn;
Def three_daysNegDn;
Def three_daysNegUp;
Def three_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.three_days {
    three_daysprice = close(period="3 Days");
    Kthree_days = (Highest(high(period="3 Days"), length) + Lowest(low(period="3 Days"), length)) /2 + ExpAverage(close(period="3 Days"), length);
    three_daysmomo = Inertia(three_daysprice- kthree_days / 2, length);
    three_days_ExpAverage = ExpAverage(close(period="3 Days"), Length);
    three_dayspos = three_daysmomo >= 0;
    three_daysneg = three_daysmomo < 0;
    three_daysup  = three_daysmomo >= three_daysmomo[1];
    three_daysdn  = three_daysmomo < three_daysmomo[1];

    three_daysPosUp = three_dayspos and three_daysup;
    three_daysPosDn = three_dayspos and three_daysdn;
    three_daysNegDn = three_daysneg and three_daysdn;
    three_daysNegUp = three_daysneg and three_daysup;
    three_daysAggregationPeriod = 1;
}
Else {
    three_daysprice = 0;
    Kthree_days = 0;
    three_daysmomo = 0;
    three_days_ExpAverage = 0;
    three_dayspos = 0;
    three_daysneg = 0;
    three_daysup = 0;
    three_daysdn = 0;
    three_daysPosUp = 0;
    three_daysPosDn = 0;
    three_daysNegDn = 0;
    three_daysNegUp = 0;
    three_daysAggregationPeriod = 0;
}
AddLabel(ThreeDayLabel and three_daysAggregationPeriod, "3D", if three_daysPosUp then globalColor("PosUp") else if three_daysPosDn then globalColor("PosDn") else if three_daysNegDn then globalColor("NegDn") else if three_daysNegUp then globalColor("NegUp") else globalColor("Neutral"));




def two_daysprice;
def Ktwo_days;
def two_daysmomo;
Def two_days_ExpAverage;
Def two_dayspos;
Def two_daysneg;
Def two_daysup;
Def two_daysdn;
Def two_daysPosUp;
Def two_daysPosDn;
Def two_daysNegDn;
Def two_daysNegUp;
Def two_daysAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_days {
    two_daysprice = close(period="2 Days");
    Ktwo_days = (Highest(high(period="2 Days"), length) + Lowest(low(period="2 Days"), length)) /2 + ExpAverage(close(period="2 Days"), length);
    two_daysmomo = Inertia(two_daysprice- ktwo_days / 2, length);
    two_days_ExpAverage = ExpAverage(close(period="2 Days"), Length);
    two_dayspos = two_daysmomo >= 0;
    two_daysneg = two_daysmomo < 0;
    two_daysup  = two_daysmomo >= two_daysmomo[1];
    two_daysdn  = two_daysmomo < two_daysmomo[1];

    two_daysPosUp = two_dayspos and two_daysup;
    two_daysPosDn = two_dayspos and two_daysdn;
    two_daysNegDn = two_daysneg and two_daysdn;
    two_daysNegUp = two_daysneg and two_daysup;
    two_daysAggregationPeriod = 1;
}
Else {
    two_daysprice = 0;
    Ktwo_days = 0;
    two_daysmomo = 0;
    two_days_ExpAverage = 0;
    two_dayspos = 0;
    two_daysneg = 0;
    two_daysup = 0;
    two_daysdn = 0;
    two_daysPosUp = 0;
    two_daysPosDn = 0;
    two_daysNegDn = 0;
    two_daysNegUp = 0;
    two_daysAggregationPeriod = 0;
}
AddLabel(TwoDayLabel and two_daysAggregationPeriod, "2D", if two_daysPosUp then globalColor("PosUp") else if two_daysPosDn then globalColor("PosDn") else if two_daysNegDn then globalColor("NegDn") else if two_daysNegUp then globalColor("NegUp") else globalColor("Neutral"));


def Dayprice;
def KDay;
def Daymomo;
Def Day_ExpAverage;
Def Daypos;
Def Dayneg;
Def Dayup;
Def Daydn;
Def DayPosUp;
Def DayPosDn;
Def DayNegDn;
Def DayNegUp;
Def DayAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Day {
    Dayprice = close(period="Day");
    KDay = (Highest(high(period="Day"), length) + Lowest(low(period="Day"), length)) /2 + ExpAverage(close(period="Day"), length);
    Daymomo = Inertia(Dayprice- kDay / 2, length);
    Day_ExpAverage = ExpAverage(close(period="Day"), Length);
    Daypos = Daymomo >= 0;
    Dayneg = Daymomo < 0;
    Dayup  = Daymomo >= Daymomo[1];
    Daydn  = Daymomo < Daymomo[1];

    DayPosUp = Daypos and Dayup;
    DayPosDn = Daypos and Daydn;
    DayNegDn = Dayneg and Daydn;
    DayNegUp = Dayneg and Dayup;
    DayAggregationPeriod = 1;
}
Else {
    Dayprice = 0;
    KDay = 0;
    Daymomo = 0;
    Day_ExpAverage = 0;
    Daypos = 0;
    Dayneg = 0;
    Dayup = 0;
    Daydn = 0;
    DayPosUp = 0;
    DayPosDn = 0;
    DayNegDn = 0;
    DayNegUp = 0;
    DayAggregationPeriod = 0;
}
AddLabel(DayLabel and DayAggregationPeriod, "D", if DayPosUp then globalColor("PosUp") else if DayPosDn then globalColor("PosDn") else if DayNegDn then globalColor("NegDn") else if DayNegUp then globalColor("NegUp") else globalColor("Neutral"));


def four_hoursprice;
def Kfour_hours;
def four_hoursmomo;
Def four_hours_ExpAverage;
Def four_hourspos;
Def four_hoursneg;
Def four_hoursup;
Def four_hoursdn;
Def four_hoursPosUp;
Def four_hoursPosDn;
Def four_hoursNegDn;
Def four_hoursNegUp;
Def four_hoursAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_hours {
    four_hoursprice = close(period="4 Hours");
    Kfour_hours = (Highest(high(period="4 Hours"), length) + Lowest(low(period="4 Hours"), length)) /2 + ExpAverage(close(period="4 Hours"), length);
    four_hoursmomo = Inertia(four_hoursprice- kfour_hours / 2, length);
    four_hours_ExpAverage = ExpAverage(close(period="4 Hours"), Length);
    four_hourspos = four_hoursmomo >= 0;
    four_hoursneg = four_hoursmomo < 0;
    four_hoursup  = four_hoursmomo >= four_hoursmomo[1];
    four_hoursdn  = four_hoursmomo < four_hoursmomo[1];

    four_hoursPosUp = four_hourspos and four_hoursup;
    four_hoursPosDn = four_hourspos and four_hoursdn;
    four_hoursNegDn = four_hoursneg and four_hoursdn;
    four_hoursNegUp = four_hoursneg and four_hoursup;
    four_hoursAggregationPeriod = 1;
}
Else {
    four_hoursprice = 0;
    Kfour_hours = 0;
    four_hoursmomo = 0;
    four_hours_ExpAverage = 0;
    four_hourspos = 0;
    four_hoursneg = 0;
    four_hoursup = 0;
    four_hoursdn = 0;
    four_hoursPosUp = 0;
    four_hoursPosDn = 0;
    four_hoursNegDn = 0;
    four_hoursNegUp = 0;
    four_hoursAggregationPeriod = 0;
}
AddLabel(FourHourLabel and four_hoursAggregationPeriod, "4h", if four_hoursPosUp then globalColor("PosUp") else if four_hoursPosDn then globalColor("PosDn") else if four_hoursNegDn then globalColor("NegDn") else if four_hoursNegUp then globalColor("NegUp") else globalColor("Neutral"));



def two_hoursprice;
def Ktwo_hours;
def two_hoursmomo;
Def two_hours_ExpAverage;
Def two_hourspos;
Def two_hoursneg;
Def two_hoursup;
Def two_hoursdn;
Def two_hoursPosUp;
Def two_hoursPosDn;
Def two_hoursNegDn;
Def two_hoursNegUp;
Def two_hoursAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_hours {
    two_hoursprice = close(period="2 Hours");
    Ktwo_hours = (Highest(high(period="2 Hours"), length) + Lowest(low(period="2 Hours"), length)) /2 + ExpAverage(close(period="2 Hours"), length);
    two_hoursmomo = Inertia(two_hoursprice- ktwo_hours / 2, length);
    two_hours_ExpAverage = ExpAverage(close(period="2 Hours"), Length);
    two_hourspos = two_hoursmomo >= 0;
    two_hoursneg = two_hoursmomo < 0;
    two_hoursup  = two_hoursmomo >= two_hoursmomo[1];
    two_hoursdn  = two_hoursmomo < two_hoursmomo[1];

    two_hoursPosUp = two_hourspos and two_hoursup;
    two_hoursPosDn = two_hourspos and two_hoursdn;
    two_hoursNegDn = two_hoursneg and two_hoursdn;
    two_hoursNegUp = two_hoursneg and two_hoursup;
    two_hoursAggregationPeriod = 1;
}
Else {
    two_hoursprice = 0;
    Ktwo_hours = 0;
    two_hoursmomo = 0;
    two_hours_ExpAverage = 0;
    two_hourspos = 0;
    two_hoursneg = 0;
    two_hoursup = 0;
    two_hoursdn = 0;
    two_hoursPosUp = 0;
    two_hoursPosDn = 0;
    two_hoursNegDn = 0;
    two_hoursNegUp = 0;
    two_hoursAggregationPeriod = 0;
}
AddLabel(TwoHourLabel and two_hoursAggregationPeriod, "2h", if two_hoursPosUp then globalColor("PosUp") else if two_hoursPosDn then globalColor("PosDn") else if two_hoursNegDn then globalColor("NegDn") else if two_hoursNegUp then globalColor("NegUp") else globalColor("Neutral"));



def hourprice;
def Khour;
def hourmomo;
Def hour_ExpAverage;
Def hourpos;
Def hourneg;
Def hourup;
Def hourdn;
Def hourPosUp;
Def hourPosDn;
Def hourNegDn;
Def hourNegUp;
Def hourAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.hour {
    hourprice = close(period="1 Hour");
    Khour = (Highest(high(period="1 Hour"), length) + Lowest(low(period="1 Hour"), length)) /2 + ExpAverage(close(period="1 Hour"), length);
    hourmomo = Inertia(hourprice- khour / 2, length);
    hour_ExpAverage = ExpAverage(close(period="1 Hour"), Length);
    hourpos = hourmomo >= 0;
    hourneg = hourmomo < 0;
    hourup  = hourmomo >= hourmomo[1];
    hourdn  = hourmomo < hourmomo[1];

    hourPosUp = hourpos and hourup;
    hourPosDn = hourpos and hourdn;
    hourNegDn = hourneg and hourdn;
    hourNegUp = hourneg and hourup;
    hourAggregationPeriod = 1;
}
Else {
    hourprice = 0;
    Khour = 0;
    hourmomo = 0;
    hour_ExpAverage = 0;
    hourpos = 0;
    hourneg = 0;
    hourup = 0;
    hourdn = 0;
    hourPosUp = 0;
    hourPosDn = 0;
    hourNegDn = 0;
    hourNegUp = 0;
    hourAggregationPeriod = 0;
}
AddLabel(OneHourLabel and hourAggregationPeriod, "1h", if hourPosUp then globalColor("PosUp") else if hourPosDn then globalColor("PosDn") else if hourNegDn then globalColor("NegDn") else if hourNegUp then globalColor("NegUp") else globalColor("Neutral"));



def thirty_minprice;
def Kthirty_min;
def thirty_minmomo;
Def thirty_min_ExpAverage;
Def thirty_minpos;
Def thirty_minneg;
Def thirty_minup;
Def thirty_mindn;
Def thirty_minPosUp;
Def thirty_minPosDn;
Def thirty_minNegDn;
Def thirty_minNegUp;
Def thirty_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.thirty_min {
    thirty_minprice = close(period="30 Min");
    Kthirty_min = (Highest(high(period="30 Min"), length) + Lowest(low(period="30 Min"), length)) /2 + ExpAverage(close(period="30 Min"), length);
    thirty_minmomo = Inertia(thirty_minprice- kthirty_min / 2, length);
    thirty_min_ExpAverage = ExpAverage(close(period="30 Min"), Length);
    thirty_minpos = thirty_minmomo >= 0;
    thirty_minneg = thirty_minmomo < 0;
    thirty_minup  = thirty_minmomo >= thirty_minmomo[1];
    thirty_mindn  = thirty_minmomo < thirty_minmomo[1];

    thirty_minPosUp = thirty_minpos and thirty_minup;
    thirty_minPosDn = thirty_minpos and thirty_mindn;
    thirty_minNegDn = thirty_minneg and thirty_mindn;
    thirty_minNegUp = thirty_minneg and thirty_minup;
    thirty_minAggregationPeriod = 1;
}
Else {
    thirty_minprice = 0;
    Kthirty_min = 0;
    thirty_minmomo = 0;
    thirty_min_ExpAverage = 0;
    thirty_minpos = 0;
    thirty_minneg = 0;
    thirty_minup = 0;
    thirty_mindn = 0;
    thirty_minPosUp = 0;
    thirty_minPosDn = 0;
    thirty_minNegDn = 0;
    thirty_minNegUp = 0;
    thirty_minAggregationPeriod = 0;
}
AddLabel(ThirtyMinLabel and thirty_minAggregationPeriod, "30m", if thirty_minPosUp then globalColor("PosUp") else if thirty_minPosDn then globalColor("PosDn") else if thirty_minNegDn then globalColor("NegDn") else if thirty_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def twenty_minprice;
def Ktwenty_min;
def twenty_minmomo;
Def twenty_min_ExpAverage;
Def twenty_minpos;
Def twenty_minneg;
Def twenty_minup;
Def twenty_mindn;
Def twenty_minPosUp;
Def twenty_minPosDn;
Def twenty_minNegDn;
Def twenty_minNegUp;
Def twenty_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.twenty_min {
    twenty_minprice = close(period="20 Min");
    Ktwenty_min = (Highest(high(period="20 Min"), length) + Lowest(low(period="20 Min"), length)) /2 + ExpAverage(close(period="20 Min"), length);
    twenty_minmomo = Inertia(twenty_minprice- ktwenty_min / 2, length);
    twenty_min_ExpAverage = ExpAverage(close(period="20 Min"), Length);
    twenty_minpos = twenty_minmomo >= 0;
    twenty_minneg = twenty_minmomo < 0;
    twenty_minup  = twenty_minmomo >= twenty_minmomo[1];
    twenty_mindn  = twenty_minmomo < twenty_minmomo[1];

    twenty_minPosUp = twenty_minpos and twenty_minup;
    twenty_minPosDn = twenty_minpos and twenty_mindn;
    twenty_minNegDn = twenty_minneg and twenty_mindn;
    twenty_minNegUp = twenty_minneg and twenty_minup;
    twenty_minAggregationPeriod = 1;
}
Else {
    twenty_minprice = 0;
    Ktwenty_min = 0;
    twenty_minmomo = 0;
    twenty_min_ExpAverage = 0;
    twenty_minpos = 0;
    twenty_minneg = 0;
    twenty_minup = 0;
    twenty_mindn = 0;
    twenty_minPosUp = 0;
    twenty_minPosDn = 0;
    twenty_minNegDn = 0;
    twenty_minNegUp = 0;
    twenty_minAggregationPeriod = 0;
}
AddLabel(TwentyMinLabel and twenty_minAggregationPeriod, "20m", if twenty_minPosUp then globalColor("PosUp") else if twenty_minPosDn then globalColor("PosDn") else if twenty_minNegDn then globalColor("NegDn") else if twenty_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def fifteen_minprice;
def Kfifteen_min;
def fifteen_minmomo;
Def fifteen_min_ExpAverage;
Def fifteen_minpos;
Def fifteen_minneg;
Def fifteen_minup;
Def fifteen_mindn;
Def fifteen_minPosUp;
Def fifteen_minPosDn;
Def fifteen_minNegDn;
Def fifteen_minNegUp;
Def fifteen_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.fifteen_min {
    fifteen_minprice = close(period="15 Min");
    Kfifteen_min = (Highest(high(period="15 Min"), length) + Lowest(low(period="15 Min"), length)) /2 + ExpAverage(close(period="15 Min"), length);
    fifteen_minmomo = Inertia(fifteen_minprice- kfifteen_min / 2, length);
    fifteen_min_ExpAverage = ExpAverage(close(period="15 Min"), Length);
    fifteen_minpos = fifteen_minmomo >= 0;
    fifteen_minneg = fifteen_minmomo < 0;
    fifteen_minup  = fifteen_minmomo >= fifteen_minmomo[1];
    fifteen_mindn  = fifteen_minmomo < fifteen_minmomo[1];

    fifteen_minPosUp = fifteen_minpos and fifteen_minup;
    fifteen_minPosDn = fifteen_minpos and fifteen_mindn;
    fifteen_minNegDn = fifteen_minneg and fifteen_mindn;
    fifteen_minNegUp = fifteen_minneg and fifteen_minup;
    fifteen_minAggregationPeriod = 1;
}
Else {
    fifteen_minprice = 0;
    Kfifteen_min = 0;
    fifteen_minmomo = 0;
    fifteen_min_ExpAverage = 0;
    fifteen_minpos = 0;
    fifteen_minneg = 0;
    fifteen_minup = 0;
    fifteen_mindn = 0;
    fifteen_minPosUp = 0;
    fifteen_minPosDn = 0;
    fifteen_minNegDn = 0;
    fifteen_minNegUp = 0;
    fifteen_minAggregationPeriod = 0;
}
AddLabel(FifteenMinLabel and fifteen_minAggregationPeriod, "15m", if fifteen_minPosUp then globalColor("PosUp") else if fifteen_minPosDn then globalColor("PosDn") else if fifteen_minNegDn then globalColor("NegDn") else if fifteen_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def ten_minprice;
def Kten_min;
def ten_minmomo;
Def ten_min_ExpAverage;
Def ten_minpos;
Def ten_minneg;
Def ten_minup;
Def ten_mindn;
Def ten_minPosUp;
Def ten_minPosDn;
Def ten_minNegDn;
Def ten_minNegUp;
Def ten_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.ten_min {
    ten_minprice = close(period="10 Min");
    Kten_min = (Highest(high(period="10 Min"), length) + Lowest(low(period="10 Min"), length)) /2 + ExpAverage(close(period="10 Min"), length);
    ten_minmomo = Inertia(ten_minprice- kten_min / 2, length);
    ten_min_ExpAverage = ExpAverage(close(period="10 Min"), Length);
    ten_minpos = ten_minmomo >= 0;
    ten_minneg = ten_minmomo < 0;
    ten_minup  = ten_minmomo >= ten_minmomo[1];
    ten_mindn  = ten_minmomo < ten_minmomo[1];

    ten_minPosUp = ten_minpos and ten_minup;
    ten_minPosDn = ten_minpos and ten_mindn;
    ten_minNegDn = ten_minneg and ten_mindn;
    ten_minNegUp = ten_minneg and ten_minup;
    ten_minAggregationPeriod = 1;
}
Else {
    ten_minprice = 0;
    Kten_min = 0;
    ten_minmomo = 0;
    ten_min_ExpAverage = 0;
    ten_minpos = 0;
    ten_minneg = 0;
    ten_minup = 0;
    ten_mindn = 0;
    ten_minPosUp = 0;
    ten_minPosDn = 0;
    ten_minNegDn = 0;
    ten_minNegUp = 0;
    ten_minAggregationPeriod = 0;
}
AddLabel(TenMinLabel and ten_minAggregationPeriod, "10m", if ten_minPosUp then globalColor("PosUp") else if ten_minPosDn then globalColor("PosDn") else if ten_minNegDn then globalColor("NegDn") else if ten_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def five_minprice;
def Kfive_min;
def five_minmomo;
Def five_min_ExpAverage;
Def five_minpos;
Def five_minneg;
Def five_minup;
Def five_mindn;
Def five_minPosUp;
Def five_minPosDn;
Def five_minNegDn;
Def five_minNegUp;
Def five_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.five_min {
    five_minprice = close(period="5 Min");
    Kfive_min = (Highest(high(period="5 Min"), length) + Lowest(low(period="5 Min"), length)) /2 + ExpAverage(close(period="5 Min"), length);
    five_minmomo = Inertia(five_minprice- kfive_min / 2, length);
    five_min_ExpAverage = ExpAverage(close(period="5 Min"), Length);
    five_minpos = five_minmomo >= 0;
    five_minneg = five_minmomo < 0;
    five_minup  = five_minmomo >= five_minmomo[1];
    five_mindn  = five_minmomo < five_minmomo[1];

    five_minPosUp = five_minpos and five_minup;
    five_minPosDn = five_minpos and five_mindn;
    five_minNegDn = five_minneg and five_mindn;
    five_minNegUp = five_minneg and five_minup;
    five_minAggregationPeriod = 1;
}
Else {
    five_minprice = 0;
    Kfive_min = 0;
    five_minmomo = 0;
    five_min_ExpAverage = 0;
    five_minpos = 0;
    five_minneg = 0;
    five_minup = 0;
    five_mindn = 0;
    five_minPosUp = 0;
    five_minPosDn = 0;
    five_minNegDn = 0;
    five_minNegUp = 0;
    five_minAggregationPeriod = 0;
}
AddLabel(FiveMinLabel and five_minAggregationPeriod, "5m", if five_minPosUp then globalColor("PosUp") else if five_minPosDn then globalColor("PosDn") else if five_minNegDn then globalColor("NegDn") else if five_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def four_minprice;
def Kfour_min;
def four_minmomo;
Def four_min_ExpAverage;
Def four_minpos;
Def four_minneg;
Def four_minup;
Def four_mindn;
Def four_minPosUp;
Def four_minPosDn;
Def four_minNegDn;
Def four_minNegUp;
Def four_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.four_min {
    four_minprice = close(period="4 Min");
    Kfour_min = (Highest(high(period="4 Min"), length) + Lowest(low(period="4 Min"), length)) /2 + ExpAverage(close(period="4 Min"), length);
    four_minmomo = Inertia(four_minprice- kfour_min / 2, length);
    four_min_ExpAverage = ExpAverage(close(period="4 Min"), Length);
    four_minpos = four_minmomo >= 0;
    four_minneg = four_minmomo < 0;
    four_minup  = four_minmomo >= four_minmomo[1];
    four_mindn  = four_minmomo < four_minmomo[1];

    four_minPosUp = four_minpos and four_minup;
    four_minPosDn = four_minpos and four_mindn;
    four_minNegDn = four_minneg and four_mindn;
    four_minNegUp = four_minneg and four_minup;
    four_minAggregationPeriod = 1;
}
Else {
    four_minprice = 0;
    Kfour_min = 0;
    four_minmomo = 0;
    four_min_ExpAverage = 0;
    four_minpos = 0;
    four_minneg = 0;
    four_minup = 0;
    four_mindn = 0;
    four_minPosUp = 0;
    four_minPosDn = 0;
    four_minNegDn = 0;
    four_minNegUp = 0;
    four_minAggregationPeriod = 0;
}
AddLabel(FourMinLabel and four_minAggregationPeriod, "4m", if four_minPosUp then globalColor("PosUp") else if four_minPosDn then globalColor("PosDn") else if four_minNegDn then globalColor("NegDn") else if four_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def three_minprice;
def Kthree_min;
def three_minmomo;
Def three_min_ExpAverage;
Def three_minpos;
Def three_minneg;
Def three_minup;
Def three_mindn;
Def three_minPosUp;
Def three_minPosDn;
Def three_minNegDn;
Def three_minNegUp;
Def three_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.three_min {
    three_minprice = close(period="3 Min");
    Kthree_min = (Highest(high(period="3 Min"), length) + Lowest(low(period="3 Min"), length)) /2 + ExpAverage(close(period="3 Min"), length);
    three_minmomo = Inertia(three_minprice- kthree_min / 2, length);
    three_min_ExpAverage = ExpAverage(close(period="3 Min"), Length);
    three_minpos = three_minmomo >= 0;
    three_minneg = three_minmomo < 0;
    three_minup  = three_minmomo >= three_minmomo[1];
    three_mindn  = three_minmomo < three_minmomo[1];

    three_minPosUp = three_minpos and three_minup;
    three_minPosDn = three_minpos and three_mindn;
    three_minNegDn = three_minneg and three_mindn;
    three_minNegUp = three_minneg and three_minup;
    three_minAggregationPeriod = 1;
}
Else {
    three_minprice = 0;
    Kthree_min = 0;
    three_minmomo = 0;
    three_min_ExpAverage = 0;
    three_minpos = 0;
    three_minneg = 0;
    three_minup = 0;
    three_mindn = 0;
    three_minPosUp = 0;
    three_minPosDn = 0;
    three_minNegDn = 0;
    three_minNegUp = 0;
    three_minAggregationPeriod = 0;
}
AddLabel(ThreeMinLabel and three_minAggregationPeriod, "3m", if three_minPosUp then globalColor("PosUp") else if three_minPosDn then globalColor("PosDn") else if three_minNegDn then globalColor("NegDn") else if three_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def two_minprice;
def Ktwo_min;
def two_minmomo;
Def two_min_ExpAverage;
Def two_minpos;
Def two_minneg;
Def two_minup;
Def two_mindn;
Def two_minPosUp;
Def two_minPosDn;
Def two_minNegDn;
Def two_minNegUp;
Def two_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.two_min {
    two_minprice = close(period="2 Min");
    Ktwo_min = (Highest(high(period="2 Min"), length) + Lowest(low(period="2 Min"), length)) /2 + ExpAverage(close(period="2 Min"), length);
    two_minmomo = Inertia(two_minprice- ktwo_min / 2, length);
    two_min_ExpAverage = ExpAverage(close(period="2 Min"), Length);
    two_minpos = two_minmomo >= 0;
    two_minneg = two_minmomo < 0;
    two_minup  = two_minmomo >= two_minmomo[1];
    two_mindn  = two_minmomo < two_minmomo[1];

    two_minPosUp = two_minpos and two_minup;
    two_minPosDn = two_minpos and two_mindn;
    two_minNegDn = two_minneg and two_mindn;
    two_minNegUp = two_minneg and two_minup;
    two_minAggregationPeriod = 1;
}
Else {
    two_minprice = 0;
    Ktwo_min = 0;
    two_minmomo = 0;
    two_min_ExpAverage = 0;
    two_minpos = 0;
    two_minneg = 0;
    two_minup = 0;
    two_mindn = 0;
    two_minPosUp = 0;
    two_minPosDn = 0;
    two_minNegDn = 0;
    two_minNegUp = 0;
    two_minAggregationPeriod = 0;
}
AddLabel(TwoMinLabel and two_minAggregationPeriod, "2m", if two_minPosUp then globalColor("PosUp") else if two_minPosDn then globalColor("PosDn") else if two_minNegDn then globalColor("NegDn") else if two_minNegUp then globalColor("NegUp") else globalColor("Neutral"));



def one_minprice;
def Kone_min;
def one_minmomo;
Def one_min_ExpAverage;
Def one_minpos;
Def one_minneg;
Def one_minup;
Def one_mindn;
Def one_minPosUp;
Def one_minPosDn;
Def one_minNegDn;
Def one_minNegUp;
Def one_minAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.Min {
    one_minprice = close(period="1 Min");
    Kone_min = (Highest(high(period="1 Min"), length) + Lowest(low(period="1 Min"), length)) /2 + ExpAverage(close(period="1 Min"), length);
    one_minmomo = Inertia(one_minprice- kone_min / 2, length);
    one_min_ExpAverage = ExpAverage(close(period="1 Min"), Length);
    one_minpos = one_minmomo >= 0;
    one_minneg = one_minmomo < 0;
    one_minup  = one_minmomo >= one_minmomo[1];
    one_mindn  = one_minmomo < one_minmomo[1];

    one_minPosUp = one_minpos and one_minup;
    one_minPosDn = one_minpos and one_mindn;
    one_minNegDn = one_minneg and one_mindn;
    one_minNegUp = one_minneg and one_minup;
    one_minAggregationPeriod = 1;
}
Else {
    one_minprice = 0;
    Kone_min = 0;
    one_minmomo = 0;
    one_min_ExpAverage = 0;
    one_minpos = 0;
    one_minneg = 0;
    one_minup = 0;
    one_mindn = 0;
    one_minPosUp = 0;
    one_minPosDn = 0;
    one_minNegDn = 0;
    one_minNegUp = 0;
    one_minAggregationPeriod = 0;
}
AddLabel(OneMinLabel and one_minAggregationPeriod, "1m", if one_minPosUp then globalColor("PosUp") else if one_minPosDn then globalColor("PosDn") else if one_minNegDn then globalColor("NegDn") else if one_minNegUp then globalColor("NegUp") else globalColor("Neutral"));
 
is there a script to scan for a change in the color of the histogram?
Your question is a bit vague. Do you mean just a scan that will provide results when a stock that’s currently squeezing changes momentum? To be clear - the squeeze histogram changes color based on directional momentum. Like MerryDay said, you cannot scan using a multi time frame study. However, if you want to do the aforementioned scan then yes, that’s possible for a single timeframe of your choice.

Theoretically, you could scan for multiple time frames that are squeezing and have changed momentum within X bars, but you’d have to add them (each time frame) as their own scan study.

If youre not following what I’m saying, you can easily scan for multiple time frame squeezes by adding a study filter to a scan, then selecting TTM_Squeeze as the study, select SqueezeAlert for the plot and then select is equal to Value “0”. The default timeframe is Day. You can copy and paste that script into another (added) study filter. Then just change the time frame to hour or week or any time frame you’d like. Repeat for however many time frames you want to scan for squeezes in.
 
I should've been more specific. My question is not specific to the multi-tume frame scan. I'm just looking for a scan for the regular ttm squeeze to see if it's possible to scan for a change in the color of the histogram. I can build a regular scan for the number of red dots and a change from red dots to green dots but no scan for the histogram bars from red to yellow indicating a change in momentum.
 
Okay. I'm not totally sure but this would be my starting point - I'd recommend going into the histogram script and grabbing the snippets of code related to "NegUp". Paste them into a new indicator that you create and give it a title. Then add a new study to a scan and select this newly created indicator as the study. Let's say you titled it NegUp. The study would say NegUp == 1 (or, is True) within 1 bar. Then add another study filter. Reference this same indicator but have it changed to - NegUp ==0 (or, is false) 2 bars ago [2]. My thought on this is that you're scanning for a squeezing stock that has Negative momentum that's reversing and shows you in the most recent bar, but the bar prior to that one was different momentum - in this case, it was negative momentum that was decreasing (further to the downside).

Someone else may be able to assist further. Most of my scans and scripts are completed via trial and error!
 
I am not tech savy, can anyone give me a ""TTM Histrogram squeeze script" code for a watchlist , would really appreciate, thank you
 
Anybody know how I can use this squeeze Histogram in certain timeframes in the scan as a condition? Such as lets say find stock that has magenta increasing momentum over 0 on daily? or If you wanted to find stocks to short with negative momentum red on the weekly for example
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
454 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