CandlestickAggregation - based on candlestick math for ThinkOrSwim

John Snyder

New member
#This is an indicator inspired by the concept of "candlestick math". It aggregates multiple candles into one. Furthermore, it does so for both traditional Japanese candles and Heikin Ashi candles.

#Written by John Snyder. Contributed to the public domain April 3, 2022.

declare lower;

input AggWidth = 0;
input CandleType = {default JapaneseCandles, HeikinAshiCandles};

DefineGlobalColor("G1", CreateColor(102, 255, 102)); #Green
DefineGlobalColor("G2", CreateColor(55, 210, 55)); #51, 204, 51)); #Green
DefineGlobalColor("G3", CreateColor(28, 165, 28)); #25, 153, 25)); #Green
DefineGlobalColor("G4", CreateColor(0, 127, 0)); #Green
DefineGlobalColor("G5", CreateColor(0, 102, 0)); #Green
DefineGlobalColor("G6", CreateColor(0, 80, 0)); #Green
DefineGlobalColor("R1", CreateColor(255, 0, 0)); #Red
DefineGlobalColor("R2", CreateColor(215, 0, 0)); #Red
DefineGlobalColor("R3", CreateColor(180, 0, 0)); #Red
DefineGlobalColor("R4", CreateColor(150, 0, 0)); #Red
DefineGlobalColor("R5", CreateColor(125, 0, 0)); #Red
DefineGlobalColor("R6", CreateColor(105, 0, 0)); #Red
DefineGlobalColor("Y1", CreateColor(255, 255, 0)); #Yellow
DefineGlobalColor("Y2", CreateColor(219, 219, 0)); #Yellow
DefineGlobalColor("Y3", CreateColor(186, 186, 0)); #Yellow
DefineGlobalColor("Y4", CreateColor(153, 153, 0)); #Yellow
DefineGlobalColor("M1", CreateColor(255, 0, 255)); #Magenta
DefineGlobalColor("M2", CreateColor(219, 0, 219)); #Magenta
DefineGlobalColor("M3", CreateColor(186, 0, 186)); #Magenta
DefineGlobalColor("M4", CreateColor(153, 0, 153)); #Magenta
DefineGlobalColor("B1", CreateColor(51, 204, 255)); #Blue
DefineGlobalColor("B2", CreateColor(38, 154, 255)); #Blue
DefineGlobalColor("B3", CreateColor(31, 136, 236)); #Blue
DefineGlobalColor("B4", CreateColor(20, 102, 224)); #Blue
DefineGlobalColor("Gray", CreateColor(28, 28, 28)); #Gray

script UIStudy { # Multiple Candlestick Aggregation Periods
input AggWidth = 0;
def AggOpen = close[AggWidth + 1];
def AggHigh = Highest(high, AggWidth + 1);
def AggLow = Lowest (low, AggWidth + 1);
def AggClose = close;
plot Lwick = AggLow;
plot Lbody = if AggOpen < AggClose then AggOpen else AggClose;
plot Ubody = if AggOpen > AggClose then AggOpen else AggClose;
plot Uwick = AggHigh;
plot UIclose = AggClose;
plot UIopen = AggOpen;
}

script HAStudy { # Multiple Candlestick Aggregation Periods
input AggWidth = 0;
def AggClose = close;
def AggOpen = close[AggWidth + 1]; #to accomodate Renko charts
def AggHigh = Highest(high, AggWidth + 1);
def AggLow = Lowest (low, AggWidth + 1);
def HA_close = (AggOpen + AggHigh + AggLow + AggClose) * 0.25;
def HA_open = CompoundValue(AggWidth + 1, (HA_open[AggWidth + 1] + HA_close[AggWidth + 1]) * 0.5, (AggOpen[AggWidth + 1] + AggClose[AggWidth + 1]) * 0.5);
def HA_high = Max(Max(AggHigh, HA_open), HA_close);
def HA_low = Min(Min(AggLow, HA_open), HA_close);
plot LWick = HA_low;
plot Lbody = if HA_close < HA_open then HA_close else HA_open;
plot UBody = if HA_close > HA_open then HA_close else HA_open;
plot Uwick = HA_high;
plot HAclose = HA_close;
plot HAopen = HA_open;
}

def LWick;
def LBody;
def UBody;
def UWick;
def UIclose;
def UIopen;

switch (CandleType) {
case JapaneseCandles:
LWick = UIStudy(AggWidth).Lwick;
LBody = UIStudy(AggWidth).Lbody;
UBody = UIStudy(AggWidth).Ubody;
UWick = UIStudy(AggWidth).Uwick;
UIclose = UIStudy(AggWidth).UIclose;
UIopen = UIStudy(AggWidth).UIopen;
case HeikinAshiCandles:
LWick = HAStudy(AggWidth).Lwick;
LBody = HAStudy(AggWidth).Lbody;
UBody = HAStudy(AggWidth).Ubody;
UWick = HAStudy(AggWidth).Uwick;
UIclose = HAStudy(AggWidth).HAclose;
UIopen = HAStudy(AggWidth).HAopen;
}

plot Tr_LowerWick = LWick;
#Tr_LowerWick.hide();
Tr_LowerWick.AssignValueColor(GlobalColor("Gray"));
Tr_LowerWick.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot Tr_LowerBody = LBody;
#Tr_LowerBody.hide();
Tr_LowerBody.AssignValueColor(if UIclose > UIopen then GlobalColor("G6") else GlobalColor("R6"));
Tr_LowerBody.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot Tr_UpperBody = UBody;
#Tr_UpperBody.hide();
Tr_UpperBody.AssignValueColor(if UIclose > UIopen then Color.GREEN else Color.RED);
Tr_UpperBody.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot Tr_UpperWick = UWick;
#Tr_UpperWick.hide();
Tr_UpperWick.AssignValueColor(if UIclose > UIopen then GlobalColor("G6") else GlobalColor("R6"));
Tr_UpperWick.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

plot Tr_high = UWick;
Tr_high.AssignValueColor(Color.GRAY);
plot Tr_low = LWick;
Tr_low.AssignValueColor(Color.GRAY);
plot Tr_avg = (UBody + LBody) * 0.5;
Tr_Avg.AssignVAlueColor(Color.YELLOW);

This is how Japanese candle compression looks with the 4 previous candles are aggregated into the current candle.
http://tos.mx/UJwW3No
sUTuKGk.png


Hmmm ... I don't know why those black vertical lines are showing up in this picture, because they don't show up when the indicator is loaded into ThinkorSwim. It looks like when this picture was converted from a black background to a white background, the display code:
Tr_LowerWick.AssignValueColor(GlobalColor("Gray"));
caused what was otherwise hidden in the black background to become visible. If one chooses to use a white background, one would need to change the color specified by this line of code to white.
 
Last edited:

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

#This is an indicator inspired by the concept of "candlestick math". It aggregates multiple candles into one. Furthermore, it does so for both traditional Japanese candles and Heikin Ashi candles.

#Written by John Snyder. Contributed to the public domain April 3, 2022.

declare lower;

input AggWidth = 0;
input CandleType = {default JapaneseCandles, HeikinAshiCandles};

DefineGlobalColor("G1", CreateColor(102, 255, 102)); #Green
DefineGlobalColor("G2", CreateColor(55, 210, 55)); #51, 204, 51)); #Green
DefineGlobalColor("G3", CreateColor(28, 165, 28)); #25, 153, 25)); #Green
DefineGlobalColor("G4", CreateColor(0, 127, 0)); #Green
DefineGlobalColor("G5", CreateColor(0, 102, 0)); #Green
DefineGlobalColor("G6", CreateColor(0, 80, 0)); #Green
DefineGlobalColor("R1", CreateColor(255, 0, 0)); #Red
DefineGlobalColor("R2", CreateColor(215, 0, 0)); #Red
DefineGlobalColor("R3", CreateColor(180, 0, 0)); #Red
DefineGlobalColor("R4", CreateColor(150, 0, 0)); #Red
DefineGlobalColor("R5", CreateColor(125, 0, 0)); #Red
DefineGlobalColor("R6", CreateColor(105, 0, 0)); #Red
DefineGlobalColor("Y1", CreateColor(255, 255, 0)); #Yellow
DefineGlobalColor("Y2", CreateColor(219, 219, 0)); #Yellow
DefineGlobalColor("Y3", CreateColor(186, 186, 0)); #Yellow
DefineGlobalColor("Y4", CreateColor(153, 153, 0)); #Yellow
DefineGlobalColor("M1", CreateColor(255, 0, 255)); #Magenta
DefineGlobalColor("M2", CreateColor(219, 0, 219)); #Magenta
DefineGlobalColor("M3", CreateColor(186, 0, 186)); #Magenta
DefineGlobalColor("M4", CreateColor(153, 0, 153)); #Magenta
DefineGlobalColor("B1", CreateColor(51, 204, 255)); #Blue
DefineGlobalColor("B2", CreateColor(38, 154, 255)); #Blue
DefineGlobalColor("B3", CreateColor(31, 136, 236)); #Blue
DefineGlobalColor("B4", CreateColor(20, 102, 224)); #Blue
DefineGlobalColor("Gray", CreateColor(28, 28, 28)); #Gray

script UIStudy { # Multiple Candlestick Aggregation Periods
input AggWidth = 0;
def AggOpen = close[AggWidth + 1];
def AggHigh = Highest(high, AggWidth + 1);
def AggLow = Lowest (low, AggWidth + 1);
def AggClose = close;
plot Lwick = AggLow;
plot Lbody = if AggOpen < AggClose then AggOpen else AggClose;
plot Ubody = if AggOpen > AggClose then AggOpen else AggClose;
plot Uwick = AggHigh;
plot UIclose = AggClose;
plot UIopen = AggOpen;
}

script HAStudy { # Multiple Candlestick Aggregation Periods
input AggWidth = 0;
def AggClose = close;
def AggOpen = close[AggWidth + 1]; #to accomodate Renko charts
def AggHigh = Highest(high, AggWidth + 1);
def AggLow = Lowest (low, AggWidth + 1);
def HA_close = (AggOpen + AggHigh + AggLow + AggClose) * 0.25;
def HA_open = CompoundValue(AggWidth + 1, (HA_open[AggWidth + 1] + HA_close[AggWidth + 1]) * 0.5, (AggOpen[AggWidth + 1] + AggClose[AggWidth + 1]) * 0.5);
def HA_high = Max(Max(AggHigh, HA_open), HA_close);
def HA_low = Min(Min(AggLow, HA_open), HA_close);
plot LWick = HA_low;
plot Lbody = if HA_close < HA_open then HA_close else HA_open;
plot UBody = if HA_close > HA_open then HA_close else HA_open;
plot Uwick = HA_high;
plot HAclose = HA_close;
plot HAopen = HA_open;
}

def LWick;
def LBody;
def UBody;
def UWick;
def UIclose;
def UIopen;

switch (CandleType) {
case JapaneseCandles:
LWick = UIStudy(AggWidth).Lwick;
LBody = UIStudy(AggWidth).Lbody;
UBody = UIStudy(AggWidth).Ubody;
UWick = UIStudy(AggWidth).Uwick;
UIclose = UIStudy(AggWidth).UIclose;
UIopen = UIStudy(AggWidth).UIopen;
case HeikinAshiCandles:
LWick = HAStudy(AggWidth).Lwick;
LBody = HAStudy(AggWidth).Lbody;
UBody = HAStudy(AggWidth).Ubody;
UWick = HAStudy(AggWidth).Uwick;
UIclose = HAStudy(AggWidth).HAclose;
UIopen = HAStudy(AggWidth).HAopen;
}

plot Tr_LowerWick = LWick;
#Tr_LowerWick.hide();
Tr_LowerWick.AssignValueColor(GlobalColor("Gray"));
Tr_LowerWick.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot Tr_LowerBody = LBody;
#Tr_LowerBody.hide();
Tr_LowerBody.AssignValueColor(if UIclose > UIopen then GlobalColor("G6") else GlobalColor("R6"));
Tr_LowerBody.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot Tr_UpperBody = UBody;
#Tr_UpperBody.hide();
Tr_UpperBody.AssignValueColor(if UIclose > UIopen then Color.GREEN else Color.RED);
Tr_UpperBody.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plot Tr_UpperWick = UWick;
#Tr_UpperWick.hide();
Tr_UpperWick.AssignValueColor(if UIclose > UIopen then GlobalColor("G6") else GlobalColor("R6"));
Tr_UpperWick.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

plot Tr_high = UWick;
Tr_high.AssignValueColor(Color.GRAY);
plot Tr_low = LWick;
Tr_low.AssignValueColor(Color.GRAY);
plot Tr_avg = (UBody + LBody) * 0.5;
Tr_Avg.AssignVAlueColor(Color.YELLOW);

This is how Japanese candle compression looks with the 4 previous candles are aggregated into the current candle.
http://tos.mx/UJwW3No
sUTuKGk.png


Hmmm ... I don't know why those black vertical lines are showing up in this picture, because they don't show up when the indicator is loaded into ThinkorSwim. It looks like when this picture was converted from a black background to a white background, the display code:
Tr_LowerWick.AssignValueColor(GlobalColor("Gray"));
caused what was otherwise hidden in the black background to become visible. If one chooses to use a white background, one would need to change the color specified by this line of code to white.
Hi John,
Awesome work... (y)
Was looking for this for the longest time...
Finally my prayer answer... 🙏

Here is a link related to something like this and thought u may like to have a look... They created the script to group any nos. of candle together with lots of custom selection to tailor to the user requirement...
https://usethinkscript.com/threads/multi-timeframe-candles-overlay-for-thinkorswim.1425/post-76971

Again, Thanks for taking the time and effort for this...
 
Here's an indicator which takes the data generated by the multiple time frame "candlestick math" indicator shown above and analyses it.


Code:
#CandlestickAggregationAnalysis
#This indicator calculates data for 16 separate user-selectable time frames and averages the data into a single trace.

#Written by John Snyder

#Released into the public domain on April 4, 2022

#This indicator analyzes the aggregated candles using the following criteria:
    #current bar Cl-Op diff, 
    #Cl-Op diff between successive bars, 
    #Trend direction diff between successive bars, 
    #Wick info

#Understanding the colors:
    #Bright green: increasing acceleration up away from zero
    #Dark green:  decreasing acceleration up away from zero
    #Bright blue:  increasing deceleration down towards zero
    #Dark blue:  decreasing deceleration down towards zero
    #Bright red: increasing acceleration down away from zero
    #Dark red:  decreasing acceleration down away from zero
    #Bright yellow:  increasing deceleration up towards zero
    #Dark yellow:  decreasing deceleration up towards zero

declare lower;

input MinAggWidth = 0;
input MaxAggWidth = 15;
input CandleType = {JapaneseCandles, default HeikinAshiCandles};
input RateOfChange = no;
input smLen = 5;

def inc = (MaxAggWidth - MinAggWidth) / 15;

DefineGlobalColor("G1", CreateColor(102, 255, 102));  #Green
DefineGlobalColor("G2", CreateColor(51, 204, 51));  #Green
DefineGlobalColor("G3", CreateColor(25, 153, 25));  #Green
DefineGlobalColor("G4", CreateColor(0, 127, 0));  #Green
DefineGlobalColor("G5", CreateColor(0, 102, 0));  #Green
DefineGlobalColor("G6", CreateColor(0, 80, 0));  #Green
DefineGlobalColor("R1", CreateColor(255, 0, 0));  #Red
DefineGlobalColor("R2", CreateColor(204, 0, 0));  #Red
DefineGlobalColor("R3", CreateColor(172, 0, 0));  #Red
DefineGlobalColor("R4", CreateColor(140, 0, 0));  #Red
DefineGlobalColor("R5", CreateColor(108, 0, 0));  #Red
DefineGlobalColor("R6", CreateColor(80, 0, 0));  #Red
DefineGlobalColor("Y1", CreateColor(255, 255, 0));  #Yellow
DefineGlobalColor("Y2", CreateColor(204, 204, 0));  #Yellow
DefineGlobalColor("Y3", CreateColor(172, 172, 0));  #Yellow
DefineGlobalColor("Y4", CreateColor(140, 140, 0));  #Yellow
DefineGlobalColor("M1", CreateColor(255, 0, 255));  #Magenta
DefineGlobalColor("M2", CreateColor(204, 0, 204));  #Magenta
DefineGlobalColor("M3", CreateColor(172, 0, 172));  #Magenta
DefineGlobalColor("M4", CreateColor(140, 0, 140));  #Magenta
DefineGlobalColor("B1", CreateColor(0, 255, 255));  #Blue
DefineGlobalColor("B2", CreateColor(0, 204, 204));  #Blue
DefineGlobalColor("B3", CreateColor(0, 172, 172));  #Blue
DefineGlobalColor("B4", CreateColor(0, 140, 140));  #Blue
DefineGlobalColor("Gray", CreateColor(28, 28, 28));  #Gray

script Normalize {
    input value = close;
    def maxvalue = HighestAll(value);
    def minvalue = LowestAll(value);
    def range = if ((maxvalue > 0 and minvalue > 0) or (maxvalue < 0 and minvalue < 0))
                then maxvalue - minvalue 
                else Max(maxvalue, AbsValue(minvalue));
    def normvalue = value / range;
    plot Normalize = normvalue;
}

script UIStudy {   # Multiple Candlestick Aggregation Periods
    input AggWidth = 0;
    def AggOpen = close[AggWidth + 1];
    def AggHigh = Highest(high, AggWidth + 1);
    def AggLow = Lowest (low, AggWidth + 1);
    def AggClose = close;
    def Lwick = AggLow;
    def Lbody = if AggOpen < AggClose then AggOpen else AggClose;
    def Ubody = if AggOpen > AggClose then AggOpen else AggClose;
    def Uwick = AggHigh;
    def UIclose = AggClose;
    def UIopen = AggOpen;
    def Analysis = (UIclose - UIopen) + (UIclose - UIclose[1]) + ((Ubody - Lbody) - (Ubody[1] - Lbody[1])) + ((Ubody - Uwick) + (Lbody - Lwick));  #current bar Cl-Op diff, Cl-Op diff between successive bars, trend direction, wick info
    def Anal_Movt = if Analysis > Analysis[1] then -1 else if Analysis < Analysis[1] then 1 else 0;
    plot aStudy = Analysis;
    plot dStudy = Anal_Movt;
}

script HAStudy {   # Multiple Candlestick Aggregation Periods
    input AggWidth = 0;
    def AggClose = close;
    def AggOpen = close[AggWidth + 1];  #to accomodate Renko charts
    def AggHigh = Highest(high, AggWidth + 1);
    def AggLow =  Lowest (low, AggWidth + 1);
    def HA_close = (AggOpen + AggHigh + AggLow + AggClose) * 0.25;
    def HA_open = CompoundValue(AggWidth + 1, (HA_open[AggWidth + 1] + HA_close[AggWidth + 1]) * 0.5, (AggOpen[AggWidth + 1] + AggClose[AggWidth + 1]) * 0.5);
    def HA_high = Max(Max(AggHigh, HA_open), HA_close);
    def HA_low = Min(Min(AggLow, HA_open), HA_close);
    def LWick = HA_low;
    def Lbody = if HA_close < HA_open then HA_close else HA_open;
    def UBody = if HA_close > HA_open then HA_close else HA_open;
    def Uwick = HA_high;
    def HAclose = HA_close;
    def HAopen = HA_open;
    def Analysis = (HAclose - HAopen) + (HAclose - HAclose[1]) + ((UBody - Lbody) - (UBody[1] - Lbody[1])) + ((UWick - UBody) + (LWick - LBody));  
    def Anal_Movt = if Analysis > Analysis[1] then -1 else if Analysis < Analysis[1] then 1 else 0;
    plot aStudy = Analysis;
    plot dStudy = Anal_Movt;
}

def aValue0;
def aValue1;
def aValue2;
def aValue3;
def aValue4;
def aValue5;
def aValue6;
def aValue7;
def aValue8;
def aValue9;
def aValue10;
def aValue11;
def aValue12;
def aValue13;
def aValue14;
def aValue15;
def aValue;
def n_aValue;
def aValue_ROC;
def n_aValue_ROC;

def dValue0;
def dValue1;
def dValue2;
def dValue3;
def dValue4;
def dValue5;
def dValue6;
def dValue7;
def dValue8;
def dValue9;
def dValue10;
def dValue11;
def dValue12;
def dValue13;
def dValue14;
def dValue15;
def dValue;

def Candle;

switch (CandleType) {
case JapaneseCandles:
    aValue0 = UIStudy(MinAggWidth + 0 * inc).aStudy;
    aValue1 = UIStudy(MinAggWidth + 1 * inc).aStudy;
    aValue2 = UIStudy(MinAggWidth + 2 * inc).aStudy;
    aValue3 = UIStudy(MinAggWidth + 3 * inc).aStudy;
    aValue4 = UIStudy(MinAggWidth + 4 * inc).aStudy;
    aValue5 = UIStudy(MinAggWidth + 5 * inc).aStudy;
    aValue6 = UIStudy(MinAggWidth + 6 * inc).aStudy;
    aValue7 = UIStudy(MinAggWidth + 7 * inc).aStudy;
    aValue8 = UIStudy(MinAggWidth + 8 * inc).aStudy;
    aValue9 = UIStudy(MinAggWidth + 9 * inc).aStudy;
    aValue10 = UIStudy(MinAggWidth + 10 * inc).aStudy;
    aValue11 = UIStudy(MinAggWidth + 11 * inc).aStudy;
    aValue12 = UIStudy(MinAggWidth + 12 * inc).aStudy;
    aValue13 = UIStudy(MinAggWidth + 13 * inc).aStudy;
    aValue14 = UIStudy(MinAggWidth + 14 * inc).aStudy;
    aValue15 = UIStudy(MinAggWidth + 15 * inc).aStudy;
    aValue = WildersSmoothing((aValue0 + aValue1 + aValue2 + aValue3 + aValue4 + aValue5 + aValue6 + aValue7 + aValue8 + aValue9 + aValue10 + aValue11 + aValue12 + aValue13 + aValue14 + aValue15) / 16, if smLen < 1 then 1 else smLen);
    n_aValue = Normalize(aValue);
    aValue_ROC = WildersSmoothing((aValue - aValue[1]), if smLen < 1 then 1 else smLen);
    n_aValue_ROC = Normalize(aValue_ROC);

    dValue0 = UIStudy(MinAggWidth + 0 * inc).dStudy;
    dValue1 = UIStudy(MinAggWidth + 1 * inc).dStudy;
    dValue2 = UIStudy(MinAggWidth + 2 * inc).dStudy;
    dValue3 = UIStudy(MinAggWidth + 3 * inc).dStudy;
    dValue4 = UIStudy(MinAggWidth + 4 * inc).dStudy;
    dValue5 = UIStudy(MinAggWidth + 5 * inc).dStudy;
    dValue6 = UIStudy(MinAggWidth + 6 * inc).dStudy;
    dValue7 = UIStudy(MinAggWidth + 7 * inc).dStudy;
    dValue8 = UIStudy(MinAggWidth + 8 * inc).dStudy;
    dValue9 = UIStudy(MinAggWidth + 9 * inc).dStudy;
    dValue10 = UIStudy(MinAggWidth + 10 * inc).dStudy;
    dValue11 = UIStudy(MinAggWidth + 11 * inc).dStudy;
    dValue12 = UIStudy(MinAggWidth + 12 * inc).dStudy;
    dValue13 = UIStudy(MinAggWidth + 13 * inc).dStudy;
    dValue14 = UIStudy(MinAggWidth + 14 * inc).dStudy;
    dValue15 = UIStudy(MinAggWidth + 15 * inc).dStudy;
    dValue = (dValue0 + dValue1 + dValue2 + dValue3 + dValue4 + dValue5 + dValue6 + dValue7 + dValue8 + dValue9 + dValue10 + dValue11 + dValue12 + dValue13 + dValue14 + dValue15) / 16;
    Candle = 0;

case HeikinAshiCandles:
    aValue0 = HAStudy(MinAggWidth + 0 * inc).aStudy;
    aValue1 = HAStudy(MinAggWidth + 1 * inc).aStudy;
    aValue2 = HAStudy(MinAggWidth + 2 * inc).aStudy;
    aValue3 = HAStudy(MinAggWidth + 3 * inc).aStudy;
    aValue4 = HAStudy(MinAggWidth + 4 * inc).aStudy;
    aValue5 = HAStudy(MinAggWidth + 5 * inc).aStudy;
    aValue6 = HAStudy(MinAggWidth + 6 * inc).aStudy;
    aValue7 = HAStudy(MinAggWidth + 7 * inc).aStudy;
    aValue8 = HAStudy(MinAggWidth + 8 * inc).aStudy;
    aValue9 = HAStudy(MinAggWidth + 9 * inc).aStudy;
    aValue10 = HAStudy(MinAggWidth + 10 * inc).aStudy;
    aValue11 = HAStudy(MinAggWidth + 11 * inc).aStudy;
    aValue12 = HAStudy(MinAggWidth + 12 * inc).aStudy;
    aValue13 = HAStudy(MinAggWidth + 13 * inc).aStudy;
    aValue14 = HAStudy(MinAggWidth + 14 * inc).aStudy;
    aValue15 = HAStudy(MinAggWidth + 15 * inc).aStudy;
    aValue = WildersSmoothing((aValue0 + aValue1 + aValue2 + aValue3 + aValue4 + aValue5 + aValue6 + aValue7 + aValue8 + aValue9 + aValue10 + aValue11 + aValue12 + aValue13 + aValue14 + aValue15) / 16, if (smLen * 0.5) < 1 then 1 else smLen * 0.5);
    n_aValue = Normalize(aValue);
    aValue_ROC = WildersSmoothing((aValue - aValue[1]), if smLen < 1 then 1 else smLen);
    n_aValue_ROC = Normalize(aValue_ROC);

    dValue0 = HAStudy(MinAggWidth + 0 * inc).dStudy;
    dValue1 = HAStudy(MinAggWidth + 1 * inc).dStudy;
    dValue2 = HAStudy(MinAggWidth + 2 * inc).dStudy;
    dValue3 = HAStudy(MinAggWidth + 3 * inc).dStudy;
    dValue4 = HAStudy(MinAggWidth + 4 * inc).dStudy;
    dValue5 = HAStudy(MinAggWidth + 5 * inc).dStudy;
    dValue6 = HAStudy(MinAggWidth + 6 * inc).dStudy;
    dValue7 = HAStudy(MinAggWidth + 7 * inc).dStudy;
    dValue8 = HAStudy(MinAggWidth + 8 * inc).dStudy;
    dValue9 = HAStudy(MinAggWidth + 9 * inc).dStudy;
    dValue10 = HAStudy(MinAggWidth + 10 * inc).dStudy;
    dValue11 = HAStudy(MinAggWidth + 11 * inc).dStudy;
    dValue12 = HAStudy(MinAggWidth + 12 * inc).dStudy;
    dValue13 = HAStudy(MinAggWidth + 13 * inc).dStudy;
    dValue14 = HAStudy(MinAggWidth + 14 * inc).dStudy;
    dValue15 = HAStudy(MinAggWidth + 15 * inc).dStudy;
    dValue = (dValue0 + dValue1 + dValue2 + dValue3 + dValue4 + dValue5 + dValue6 + dValue7 + dValue8 + dValue9 + dValue10 + dValue11 + dValue12 + dValue13 + dValue14 + dValue15) / 16;
    Candle = 1;
}

plot Hist_aValue = if !RateOfChange then n_aValue else n_aValue_ROC;
#Hist_aValue.hide();
Hist_aValue.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist_aValue.AssignValueColor(
if !RateOfChange
then
    if aValue > 0
    then
        if aValue > aValue[1]
        then
            if (aValue - aValue[1]) >= (aValue[1] - aValue[2])
            then GlobalColor("G1")
            else GlobalColor("G3")
        else
            if (aValue - aValue[1]) <= (aValue[1] - aValue[2])
            then GlobalColor("B1")
            else GlobalColor("B3")
    else
        if aValue < aValue[1]
        then
            if (aValue - aValue[1]) <= (aValue[1] - aValue[2])
            then GlobalColor("R1")
            else GlobalColor("R3")
        else
            if (aValue - aValue[1]) >= (aValue[1] - aValue[2])
            then GlobalColor("Y1")
            else GlobalColor("Y3")
else
    if aValue_ROC > 0
    then
        if aValue_ROC > aValue_ROC[1]
        then
            if (aValue_ROC - aValue_ROC[1]) >= (aValue_ROC[1] - aValue_ROC[2])
            then GlobalColor("G1")
            else GlobalColor("G3")
        else
            if (aValue_ROC - aValue_ROC[1]) <= (aValue_ROC[1] - aValue_ROC[2])
            then GlobalColor("B1")
            else GlobalColor("B3")
    else
        if aValue_ROC < aValue_ROC[1]
        then
            if (aValue_ROC - aValue_ROC[1]) <= (aValue_ROC[1] - aValue_ROC[2])
            then GlobalColor("R1")
            else GlobalColor("R3")
        else
            if (aValue_ROC - aValue_ROC[1]) >= (aValue_ROC[1] - aValue_ROC[2])
            then GlobalColor("Y1")
            else GlobalColor("Y3")
);

plot Tr_aValue = n_aValue;
#Tr_aValue.hide();
Tr_aValue.SetLineWeight(2);
Tr_aValue.AssignValueColor(
if aValue > 0
then
    if aValue > aValue[1]
    then
        if (aValue - aValue[1]) >= (aValue[1] - aValue[2])
        then GlobalColor("G1")
        else GlobalColor("G3")
    else
        if (aValue - aValue[1]) <= (aValue[1] - aValue[2])
        then GlobalColor("B1")
        else GlobalColor("B3")
else
    if aValue < aValue[1]
    then
        if (aValue - aValue[1]) <= (aValue[1] - aValue[2])
        then GlobalColor("R1")
        else GlobalColor("R3")
    else
        if (aValue - aValue[1]) >= (aValue[1] - aValue[2])
        then GlobalColor("Y1")
        else GlobalColor("Y3")
);

plot Tr_aValue_ROC = if RateOfChange then n_aValue_ROC else Double.NaN;
Tr_aValue_ROC.SetLineWeight(2);
Tr_aValue_ROC.AssignValueColor(
if n_aValue_ROC > 0
then
    if n_aValue_ROC > n_aValue_ROC[1]
    then
        if (n_aValue_ROC - n_aValue_ROC[1]) >= (n_aValue_ROC[1] - n_aValue_ROC[2])
        then GlobalColor("G1")
        else GlobalColor("G1")
    else
        if (n_aValue_ROC - n_aValue_ROC[1]) <= (n_aValue_ROC[1] - n_aValue_ROC[2])
        then GlobalColor("B3")
        else GlobalColor("B3")
else
    if n_aValue_ROC < n_aValue_ROC[1]
    then
        if (n_aValue_ROC - n_aValue_ROC[1]) <= (n_aValue_ROC[1] - n_aValue_ROC[2])
        then GlobalColor("R1")
        else GlobalColor("R1")
    else
        if (n_aValue_ROC - n_aValue_ROC[1]) >= (n_aValue_ROC[1] - n_aValue_ROC[2])
        then GlobalColor("Y1")
        else GlobalColor("Y1")
);

#AddCloud(n_aValue_ROC, 0, Color.DARK_GREEN, Color.DARK_RED);
#AddCloud(n_aValue, 0, Color.DARK_GREEN, Color.DARK_RED);

plot Zeroline = 0;
#Zeroline.hide();
Zeroline.SetLineWeight(5);
Zeroline.AssignValueColor(
if !RateOfChange
then
    if aValue > 0
        then
        if aValue > aValue[1]
        then
            if ( aValue - aValue[1]) >= (aValue[1] - aValue[2])
            then GlobalColor("G1")
            else GlobalColor("G1")
        else
            if (aValue - aValue[1]) <= (aValue[1] - aValue[2])
            then Color.BLACK  #GlobalColor("B1")
            else Color.BLACK  #GlobalColor("B3")
    else
        if aValue < aValue[1]
        then
            if (aValue - aValue[1]) <= (aValue[1] - aValue[2])
            then GlobalColor("R1")
            else GlobalColor("R1")
        else
            if (aValue - aValue[1]) >= (aValue[1] - aValue[2])
            then Color.BLACK  #GlobalColor("Y1")
            else Color.BLACK  #GlobalColor("Y3")
else
    if aValue_ROC > 0
    then
        if aValue_ROC > aValue_ROC[1]
        then
            if (aValue_ROC - aValue_ROC[1]) >= (aValue_ROC[1] - aValue_ROC[2])
            then GlobalColor("G1")
            else GlobalColor("G1")
        else
            if (aValue_ROC - aValue_ROC[1]) <= (aValue_ROC[1] - aValue_ROC[2])
            then Color.BLACK  #GlobalColor("B1")
            else Color.BLACK  #GlobalColor("B3")
    else
        if aValue_ROC < aValue_ROC[1]
        then
            if (aValue_ROC - aValue_ROC[1]) <= (aValue_ROC[1] - aValue_ROC[2])
            then GlobalColor("R1")
            else GlobalColor("R1")
        else
            if (aValue_ROC - aValue_ROC[1]) >= (aValue_ROC[1] - aValue_ROC[2])
            then Color.BLACK  #GlobalColor("Y1")
            else Color.BLACK  #GlobalColor("Y3")
);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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