Repaints The Multi-10x MTF Labels Indicator for ThinkorSwim

Repaints
if I have enough requests and anyone is interested, I can release a version that you can select up to 6 aggregation periods directly as an input, the benefit, it will allow you to display a higher aggregation than a 1 minute since you need to have the lowest aggregation chart active. if you don't trade a 1 minute, then you can select your lowest such as a 5 minute, then you can move to a 5 minute, 10, 30, 1HR, 4HR for input of the aggregation period directly as parameter. allowing you to move up from the default 1 MIN requirement to 5 MIN chart.

this style of indicator was really to allow a state view of all aggregation periods in one chart for regime analysis.
 
@diazlaz Now that you put in the line about regime analysis, I understand why it was built this way.
Suggest that your note about a state view be added to the header notes so that when someone gets perplexed like I did, the little light bulb goes off.
@tomsk thanks for the positive suggestions like putting the TF's in an input. It's that sort of thing that makes this a great community!
 
@markos After reading your recent comment about a TWO_WEEK aggregation, I thought about it for a bit and thought a user selectable choice might be the best approach.
 
@markos After reading your recent comment about a TWO_WEEK aggregation, I thought about it for a bit and thought a user selectable choice might be the best approach.
Yeah, I was thinking of adding a 10 day (2 weeks of trading). I can do that on my own when I have the time. Thanks for the idea follow up.
 
Hello everyone,

I had no idea this thread would gain so much traction! I like the idea of selecting 6 aggregation periods. How would you code it so that the label would be able to pick between "min" "DAY" "WEEK" etc.? In any case, just to show how it's done at Simpler, here is the picture
As you can see, there is one label multiplied 18 times, each time having been assigned a different aggregation period through input. This way you can see the chart at any time frame and the shorter time frame labels would simply turn off leaving the rest with higher time frames on. That's what happens on my charts and makes things very convenient. By the way, if anyone wants to actually see the chart with repainted bars please use the code in my first post (AssignColor should be the last line of it). Today (Tuesday), for a good period of time AAPL was green through all 18 time frames. I have never seen such strong conviction and momentum in a trend.

If anyone is interested in developing this code further (the indicator, not the label), the next thing would be to add dots onto candles/bars when the volume of the current bar is 50% over the 20 SMA of the volume bars. The dots would signify the strength of the momentum and trend. And then the other thing (maybe a different indicator) would be signal arrows up and down based on the break of low of the high bar that bumped into the top of the 21-period price channel (reversal arrow down), and the break of high of the low bar that bumped into the bottom of the 21-period price channel (reversal arrow up). This seems to be the most recent technique John Carter uses to trade. He went from $1M to $1.4 in his trading account in under a month (
)... Incredibly impressive. Just following the prevailing trend and letting the market give you as much money as it wants to. If anyone is interested in him explaining this further, I highly recommend this free video
 
I would love to see all of the above. I am happy to help with the code. My priorities would be the following
1. Getting the label to show on any time frame instead of having to be on 1 minute. If you are tackling this or have more details you have been thinking about in tackling this let me know. I am going to attempt this first but don't want to replicate effort or re-discover things you have already figured out.
2. Painting the bars - If you know this works and can tell me which lines need to be inserted where that would save me time. I see your assigncolor line but haven't tried just pasting it in the latest to see if it works yet.
3. Getting the volume dots. If you aren't going to tackle that I will see if I can find some time to look at that one. I think that should be fairly simple to do.
4. For reversal arrows I have been using TTMScalper alerts. They aren't the same for sure but they do offer a pretty good replacement without having to code or buy the Reversal Arrows and it is free in TOS. When it comes to all indicators it is somewhat hard to know for sure which are "better" than others. They will all get it wrong some amount of time. Whether the arrow fires off with three higher / lower bars or a bar that closes higher / lower than some previous bar may not make that much of a difference statistically. I am not sure how to discern that other than back testing or going with the guru like John. I am not sure it is worth the time to figure this one out. If we really think it is better it might be worth the $300 to just buy it.
 
You never know and thank you for posting. Never really was the idea to reverse a commercial available indicator or did nt realize that this was a sold trading strategy.

What attracted me to it, was the simplicity of trading with basic sma and ADX, pretty common open de facto standards and wasn't proprietary.

I will create a single timeframe version this morning and post the script so if you and the community can continue enhancing it. Some good simple ideas and maybe this community can shape it make it their own.

All in return just contribute your findings and observations. Everyone can learn and enhance their P&l, there is enough for everyone, and if you see values in John's work buy it 🙂
 
@billgt Note that TTM Scalper uses future bars to plot pivots. That's the reason why TTM Scalper looks so good. This is similar to my recent comment on Zig Zag High Low (on another thread). Both of them use future bars to confirm past conditions and hence is "never wrong". I've observed that it usually plots signals 3 bars late. Hence you might like to look into that before taking any live trades if you're using the TTM Scalper
 
Here you all go - looking forward to your creative ideas. Have a safe relaxing holiday week!

Ruby:
#Visual DMI (The 10x Bars) Community Edition for ThinkorSwim V1.0
#
#
#CREDITS
# John Carter's 10x bars, @sierioiza, @tomsk, @horserider, @markos
#
#CHANGELOG
# 2019.11.27 1.0 @diazlaz - Community Edition Release from Label 1.7
#
#DESCRIPTION
# For TSLA, we can see the 10X bars across various time frames,
# from the Weekly down to the 1-minute chart.  We can see at a
# glance that there is strong GREEN momentum across most time frames.
# Any short-term red sets up a buying opportunity back in the direction
# of the longer-term greens and vice versa.
#
#
#INSTRUCTIONS
# Set timeframe agg as input. Add as many to a chart.
#
#

declare upper;

#INPUTS
input length = 14; #DI+- length
input adxlength = 20; #ADX sideways length
input averageType = AverageType.WILDERS;
input showlabels = yes; #show labels
input agg = aggregationPeriod.FIVE_MIN;

#CORE
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.YELLOW);

#LABELS
#AddLabel(showlabels, "10X System Community V1.0", COLOR.CYAN);

# SINGLE AGGREGATION

def hiDiff = high(period = agg ) - high(period = agg )[1];
def loDiff = low(period = agg )[1] - low(period = agg );

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM =  if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def ATR = MovingAverage(averageType, TrueRange(high(period = agg ),
 close(period = agg), low(period = agg)), length);
def "DI+" = 100 * MovingAverage(averageType, plusDM, length) / ATR;
def "DI-" = 100 * MovingAverage(averageType, minusDM, length) / ATR;

def DX = if ("DI+" + "DI-" > 0) then 100 * AbsValue("DI+" - "DI-") / ("DI+" + "DI-") else 0;
def ADX = MovingAverage(averageType, DX, length);

def bullish = ("DI+" > "DI-") and (ADX > adxlength);
def bearish = ("DI+" < "DI-") and (ADX > adxlength);
def sideways = (ADX < adxlength);

def sState = if bullish then 100 else if bearish then -100 else 0;

AddLabel(showlabels, "x:" + (agg/1000/60) + " min", if IsNan(sState) then COLOR.DARK_GRAY else
 if sState == 100 then GlobalColor("Bullish") else
 if sState == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# END OF Visual DMI (The 10x Bars) Community Edition for ThinkorSwim
 
Thanks for letting us all know that. There may be some people reading this that are not aware of that. I use it as extra confirmation or as an indicator not to go in a particular direction sometimes if it is against me. Although, John does make a pretty compelling case for using it by itself in his book. I think it has merit on its own especially for swing trades but that is not how I use it. Thanks again!
 
Here is a partial fix that will show only the aggregations for the time frame you are on and higher. It is not 100% because I broke the stats. I don't really care about them so if you do then maybe you can provide a fix. I am sure there is a more eloquent way to do this but I just wanted it done so hopefully someone will find it useful. If you improve it please post it back.

I am going to work on the painting of the bars next and then tackle the volume. If someone else has done these please post.

Thanks!

Code:
#Visual DMI (The 10x Bars) MTF Labels for ThinkorSwim V1.6
#Last Updated on Monday, November 25 2019 at 09:51:52 PM
#
#CREDITS
# John Carter's 10x bars, @sierioiza, @tomsk, @horserider, @markos
#
#CHANGELOG
# 2019.11.25 1.0 @diazlaz - Updated Port
# 2019.11.25 1.1 @diazlaz - Added Month Time frame
# 2019.11.25 1.2 @diazlaz - Added additional timecheck on chart and instructions
# 2019.11.25 1.2 @diazlaz - Added additional aggregation periods (18 total)
# 2019.11.25 1.2 @diazlaz - Added additional periods 4MIN, 20MIN, 2DAYS, 4DAYS
# 2019.11.25 1.3 @diazlaz - Added adxlength and showlabels inputs
# 2019.11.25 1.4 @diazlaz - Added states and stats labels
# 2019.11.25 1.5 @diazlaz - Added fix for NaN when data is not available
#                           such as monthly for UBER due to recent IPO.
#                           colors Label as Dark Gray when no data is available.
#                           handles count of stats when error is encountered.
# 2019.11.25 1.6 @diazlaz - Added inputs for label display all aggregation periods
#                           default display all set to yes.
#                           Note:
#                            STATS still calc all periods. if this is a ask to filter
#                            based on displayed aggregation periods please let me know
#                            and will incorporate this request.
#
#DESCRIPTION
# For TSLA, we can see the 10X bars across various time frames,
# from the Weekly down to the 1-minute chart.  We can see at a
# glance that there is strong GREEN momentum across most time frames.
# Any short-term red sets up a buying opportunity back in the direction
# of the longer-term greens and vice versa.
#
#
#INSTRUCTIONS
# Set timeframe charts to 1 minute and 30 days.
#
#

#INPUTS
input length = 14; #DI+- length
input adxlength = 20; #ADX sideways length
input averageType = AverageType.WILDERS;
input showlabels = yes; #show labels
input showstats = yes; #show stats

input show1MIN = yes; #show ONE MINUTE label
input show2MIN = yes; #show TWO MINUTES label
input show3MIN = yes; #show THREE MINUTES label
input show4MIN = yes; #show FOUR MINUTES label
input show5MIN = yes; #show FIVE MINUTES label
input show10MIN = yes; #show TEN MINUTES label
input show15MIN = yes; #show FIFTEEN MINUTES label
input show20MIN = yes; #show TWENTY MINUTES label
input show30MIN = yes; #show THIRTY MINUTES label
input show1HOUR = yes; #show HOUR label
input show2HOUR = yes; #show TWO HOURS label
input show4HOUR = yes; #show FOUR HOURS label
input show1DAY = yes; #show ONE DAY label
input show2DAY = yes; #show TWO DAYS label
input show3DAY = yes; #show THREE DAYS label
input show4DAY = yes; #show FOUR DAYS label
input showWEEK = yes; #show ONE WEEK label
input showMONTH = yes; #show ONE MONTH label

#CORE
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.YELLOW);

#TIMEFRAME CHECK
def currentTimeFrame = getAggregationPeriod();
#AddLabel(showLabels, "TimeFrame: " + currentTimeFrame, COLOR.CYAN);
#assert(currentTimeFrame == AggregationPeriod.MIN, "ERROR: timeFrame needs to be 1 minute");

#LABELS
AddLabel(showlabels, "10X System V1.6", COLOR.CYAN);


# AGGREGATION 1 - ONE MINUTE


def aM1 = if currentTimeFrame <= aggregationPeriod.MIN then aggregationPeriod.MIN else currentTimeFrame;
def M1Available = if currentTimeFrame <= aggregationPeriod.MIN then yes else no;
def hiDiffM1 = high(period = aM1) - high(period = aM1)[1];
def loDiffM1 = low(period = aM1)[1] - low(period = aM1);

def plusDMM1 = if hiDiffM1 > loDiffM1 and hiDiffM1 > 0 then hiDiffM1 else 0;
def minusDMM1 =  if loDiffM1 > hiDiffM1 and loDiffM1 > 0 then loDiffM1 else 0;

def ATRM1 = MovingAverage(averageType, TrueRange(high(period = aM1), close(period = aM1), low(period = aM1)), length);
def "DI+M1" = 100 * MovingAverage(averageType, plusDMM1, length) / ATRM1;
def "DI-M1" = 100 * MovingAverage(averageType, minusDMM1, length) / ATRM1;

def DXM1 = if ("DI+M1" + "DI-M1" > 0) then 100 * AbsValue("DI+M1" - "DI-M1") / ("DI+M1" + "DI-M1") else 0;
def ADXM1 = MovingAverage(averageType, DXM1, length);

def bullishM1 = ("DI+M1" > "DI-M1") and (ADXM1 > adxlength);
def bearishM1 = ("DI+M1" < "DI-M1") and (ADXM1 > adxlength);
def sidewaysM1 = (ADXM1 < adxlength);

def sStateM1 = if bullishM1 then 100 else if bearishM1 then -100 else 0;
def sPOSM1 = if IsNan(sStateM1) then 0 else bullishM1;
def sNEGM1 = if IsNan(sStateM1) then 0 else bearishM1;
def sSIDM1 = if IsNan(sStateM1) then 0 else if sPOSM1 or sNEGM1 then 0 else sidewaysM1;

AddLabel(showlabels and show1MIN and M1Available, "1MIN", if IsNan(sStateM1) then COLOR.DARK_GRAY else
if sStateM1 == 100 then GlobalColor("Bullish") else
if sStateM1 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));



# AGGREGATION 2 - TWO MINUTES
def aM2 = if currentTimeFrame <= AggregationPeriod.TWO_MIN then AggregationPeriod.TWO_MIN else currentTimeFrame;
def M2Available = if currentTimeFrame <= aggregationPeriod.TWO_MIN then yes else no;
#def aM2 = aggregationPeriod.TWO_MIN;

def hiDiffM2 = high(period = aM2) - high(period = aM2)[1];
def loDiffM2 = low(period = aM2)[1] - low(period = aM2);

def plusDMM2 = if hiDiffM2 > loDiffM2 and hiDiffM2 > 0 then hiDiffM2 else 0;
def minusDMM2 =  if loDiffM2 > hiDiffM2 and loDiffM2 > 0 then loDiffM2 else 0;

def ATRM2 = MovingAverage(averageType, TrueRange(high(period = aM2), close(period = aM2), low(period = aM2)), length);
def "DI+M2" = 100 * MovingAverage(averageType, plusDMM2, length) / ATRM2;
def "DI-M2" = 100 * MovingAverage(averageType, minusDMM2, length) / ATRM2;

def DXM2 = if ("DI+M2" + "DI-M2" > 0) then 100 * AbsValue("DI+M2" - "DI-M2") / ("DI+M2" + "DI-M2") else 0;
def ADXM2 = MovingAverage(averageType, DXM2, length);

def bullishM2 = ("DI+M2" > "DI-M2") and (ADXM2 > adxlength);
def bearishM2 = ("DI+M2" < "DI-M2") and (ADXM2 > adxlength);
def sidewaysM2 = (ADXM2 < adxlength);

def sStateM2 = if bullishM2 then 100 else if bearishM2 then -100 else 0;
def sPOSM2 = if IsNan(sStateM2) then 0 else bullishM2;
def sNEGM2 = if IsNan(sStateM2) then 0 else bearishM2;
def sSIDM2 = if IsNan(sStateM2) then 0 else if sPOSM2 or sNEGM2 then 0 else sidewaysM2;

AddLabel(showlabels and show2MIN and M2Available, "2MIN", if IsNan(sStateM2) then COLOR.DARK_GRAY else
if sStateM2 == 100 then GlobalColor("Bullish") else
if sStateM2 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 3 - THREE MINUTES
def aM3 = if currentTimeFrame <= aggregationPeriod.THREE_MIN then aggregationPeriod.THREE_MIN else currentTimeFrame;
def M3Available = if currentTimeFrame <= aggregationPeriod.THREE_MIN then yes else no;
#def aM3 = aggregationPeriod.THREE_MIN;
def hiDiffM3 = high(period = aM3) - high(period = aM3)[1];
def loDiffM3 = low(period = aM3)[1] - low(period = aM3);

def plusDMM3 = if hiDiffM3 > loDiffM3 and hiDiffM3 > 0 then hiDiffM3 else 0;
def minusDMM3 =  if loDiffM3 > hiDiffM3 and loDiffM3 > 0 then loDiffM3 else 0;

def ATRM3 = MovingAverage(averageType, TrueRange(high(period = aM3), close(period = aM3), low(period = aM3)), length);
def "DI+M3" = 100 * MovingAverage(averageType, plusDMM3, length) / ATRM3;
def "DI-M3" = 100 * MovingAverage(averageType, minusDMM3, length) / ATRM3;

def DXM3 = if ("DI+M3" + "DI-M3" > 0) then 100 * AbsValue("DI+M3" - "DI-M3") / ("DI+M3" + "DI-M3") else 0;
def ADXM3 = MovingAverage(averageType, DXM3, length);

def bullishM3 = ("DI+M3" > "DI-M3") and (ADXM3 > adxlength);
def bearishM3 = ("DI+M3" < "DI-M3") and (ADXM3 > adxlength);
def sidewaysM3 = (ADXM3 < adxlength);

def sStateM3 = if bullishM3 then 100 else if bearishM3 then -100 else 0;
def sPOSM3 = if IsNan(sStateM3) then 0 else bullishM3;
def sNEGM3 = if IsNan(sStateM3) then 0 else bearishM3;
def sSIDM3 = if IsNan(sStateM3) then 0 else if sPOSM3 or sNEGM3 then 0 else sidewaysM3;

AddLabel(showlabels and show3MIN and M3Available, "3MIN", if IsNan(sStateM3) then COLOR.DARK_GRAY else
if sStateM3 == 100 then GlobalColor("Bullish") else
if sStateM3 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 4 - FOUR MINUTES
def aM4 = if currentTimeFrame <= aggregationPeriod.FOUR_MIN then aggregationPeriod.FOUR_MIN else currentTimeFrame;
def M4Available = if currentTimeFrame <= aggregationPeriod.FOUR_MIN then yes else no;
#def aM4 = aggregationPeriod.FOUR_MIN;
def hiDiffM4 = high(period = aM4) - high(period = aM4)[1];
def loDiffM4 = low(period = aM4)[1] - low(period = aM4);

def plusDMM4 = if hiDiffM4 > loDiffM4 and hiDiffM4 > 0 then hiDiffM4 else 0;
def minusDMM4 =  if loDiffM4 > hiDiffM4 and loDiffM4 > 0 then loDiffM4 else 0;

def ATRM4 = MovingAverage(averageType, TrueRange(high(period = aM4), close(period = aM4), low(period = aM4)), length);
def "DI+M4" = 100 * MovingAverage(averageType, plusDMM4, length) / ATRM4;
def "DI-M4" = 100 * MovingAverage(averageType, minusDMM4, length) / ATRM4;

def DXM4 = if ("DI+M4" + "DI-M4" > 0) then 100 * AbsValue("DI+M4" - "DI-M4") / ("DI+M4" + "DI-M4") else 0;
def ADXM4 = MovingAverage(averageType, DXM4, length);

def bullishM4 = ("DI+M4" > "DI-M4") and (ADXM4 > adxlength);
def bearishM4 = ("DI+M4" < "DI-M4") and (ADXM4 > adxlength);
def sidewaysM4 = (ADXM4 < adxlength);

def sStateM4 = if bullishM4 then 100 else if bearishM4 then -100 else 0;
def sPOSM4 = if IsNan(sStateM4) then 0 else bullishM4;
def sNEGM4 = if IsNan(sStateM4) then 0 else bearishM4;
def sSIDM4 = if IsNan(sStateM4) then 0 else if sPOSM4 or sNEGM4 then 0 else sidewaysM4;

AddLabel(showlabels and show4MIN and M4Available, "4MIN", if IsNan(sStateM4) then COLOR.DARK_GRAY else
if sStateM4 == 100 then GlobalColor("Bullish") else
if sStateM4 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 5 - FIVE MINUTES
def aM5 = if currentTimeFrame <= aggregationPeriod.FIVE_MIN then aggregationPeriod.FIVE_MIN else currentTimeFrame;
def M5Available = if currentTimeFrame <= aggregationPeriod.FIVE_MIN then yes else no;
#def aM5 = aggregationPeriod.FIVE_MIN;
def hiDiffM5 = high(period = aM5) - high(period = aM5)[1];
def loDiffM5 = low(period = aM5)[1] - low(period = aM5);

def plusDMM5 = if hiDiffM5 > loDiffM5 and hiDiffM5 > 0 then hiDiffM5 else 0;
def minusDMM5 =  if loDiffM5 > hiDiffM5 and loDiffM5 > 0 then loDiffM5 else 0;

def ATRM5 = MovingAverage(averageType, TrueRange(high(period = aM5), close(period = aM5), low(period = aM5)), length);
def "DI+M5" = 100 * MovingAverage(averageType, plusDMM5, length) / ATRM5;
def "DI-M5" = 100 * MovingAverage(averageType, minusDMM5, length) / ATRM5;

def DXM5 = if ("DI+M5" + "DI-M5" > 0) then 100 * AbsValue("DI+M5" - "DI-M5") / ("DI+M5" + "DI-M5") else 0;
def ADXM5 = MovingAverage(averageType, DXM5, length);

def bullishM5 = ("DI+M5" > "DI-M5") and (ADXM5 > adxlength);
def bearishM5 = ("DI+M5" < "DI-M5") and (ADXM5 > adxlength);
def sidewaysM5 = (ADXM5 < adxlength);

def sStateM5 = if bullishM5 then 100 else if bearishM5 then -100 else 0;
def sPOSM5 = if IsNan(sStateM5) then 0 else bullishM5;
def sNEGM5 = if IsNan(sStateM5) then 0 else bearishM5;
def sSIDM5 = if IsNan(sStateM5) then 0 else if sPOSM5 or sNEGM5 then 0 else sidewaysM5;

AddLabel(showlabels and show5MIN and M5Available, "5MIN", if IsNan(sStateM5) then COLOR.DARK_GRAY else
if sStateM5 == 100 then GlobalColor("Bullish") else
if sStateM5 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 6 - TEN MINUTES
def aM10 = if currentTimeFrame <= aggregationPeriod.TEN_MIN then aggregationPeriod.TEN_MIN else currentTimeFrame;
def M10Available = if currentTimeFrame <= aggregationPeriod.TEN_MIN then yes else no;
#def aM10 = aggregationPeriod.TEN_MIN;
def hiDiffM10 = high(period = aM10) - high(period = aM10)[1];
def loDiffM10 = low(period = aM10)[1] - low(period = aM10);

def plusDMM10 = if hiDiffM10 > loDiffM10 and hiDiffM10 > 0 then hiDiffM10 else 0;
def minusDMM10 =  if loDiffM10 > hiDiffM10 and loDiffM10 > 0 then loDiffM10 else 0;

def ATRM10 = MovingAverage(averageType, TrueRange(high(period = aM10), close(period = aM10), low(period = aM10)), length);
def "DI+M10" = 100 * MovingAverage(averageType, plusDMM10, length) / ATRM10;
def "DI-M10" = 100 * MovingAverage(averageType, minusDMM10, length) / ATRM10;

def DXM10 = if ("DI+M10" + "DI-M10" > 0) then 100 * AbsValue("DI+M10" - "DI-M10") / ("DI+M10" + "DI-M10") else 0;
def ADXM10 = MovingAverage(averageType, DXM10, length);

def bullishM10 = ("DI+M10" > "DI-M10") and (ADXM10 > adxlength);
def bearishM10 = ("DI+M10" < "DI-M10") and (ADXM10 > adxlength);
def sidewaysM10 = (ADXM10 < adxlength);

def sStateM10 = if bullishM10 then 100 else if bearishM10 then -100 else 0;
def sPOSM10 = if IsNan(sStateM10) then 0 else bullishM10;
def sNEGM10 = if IsNan(sStateM10) then 0 else bearishM10;
def sSIDM10 = if IsNan(sStateM10) then 0 else if sPOSM10 or sNEGM10 then 0 else sidewaysM10;

AddLabel(showlabels and show10MIN and M10Available, "10MIN", if IsNan(sStateM10) then COLOR.DARK_GRAY else
if sStateM10 == 100 then GlobalColor("Bullish") else
if sStateM10 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 7 - FIFTEEN MINUTES
def aM15 = if currentTimeFrame <= aggregationPeriod.FIFTEEN_MIN then aggregationPeriod.FIFTEEN_MIN else currentTimeFrame;
def M15Available = if currentTimeFrame <= aggregationPeriod.FIFTEEN_MIN then yes else no;
#def aM15 = aggregationPeriod.FIFTEEN_MIN;
def hiDiffM15 = high(period = aM15) - high(period = aM15)[1];
def loDiffM15 = low(period = aM15)[1] - low(period = aM15);

def plusDMM15 = if hiDiffM15 > loDiffM15 and hiDiffM15 > 0 then hiDiffM15 else 0;
def minusDMM15 =  if loDiffM15 > hiDiffM15 and loDiffM15 > 0 then loDiffM15 else 0;

def ATRM15 = MovingAverage(averageType, TrueRange(high(period = aM15), close(period = aM15), low(period = aM15)), length);
def "DI+M15" = 100 * MovingAverage(averageType, plusDMM15, length) / ATRM15;
def "DI-M15" = 100 * MovingAverage(averageType, minusDMM15, length) / ATRM15;

def DXM15 = if ("DI+M15" + "DI-M15" > 0) then 100 * AbsValue("DI+M15" - "DI-M15") / ("DI+M15" + "DI-M15") else 0;
def ADXM15 = MovingAverage(averageType, DXM15, length);

def bullishM15 = ("DI+M15" > "DI-M15") and (ADXM15 > adxlength);
def bearishM15 = ("DI+M15" < "DI-M15") and (ADXM15 > adxlength);
def sidewaysM15 = (ADXM15 < adxlength);

def sStateM15 = if bullishM15 then 100 else if bearishM15 then -100 else 0;
def sPOSM15 = if IsNan(sStateM15) then 0 else bullishM15;
def sNEGM15 = if IsNan(sStateM15) then 0 else bearishM15;
def sSIDM15 = if IsNan(sStateM15) then 0 else if sPOSM15 or sNEGM15 then 0 else sidewaysM15;

AddLabel(showlabels and show15MIN and M15Available, "15MIN", if IsNan(sStateM15) then COLOR.DARK_GRAY else
if sStateM15 == 100 then GlobalColor("Bullish") else
if sStateM15 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 8 - TWENTY MINUTES
def aM20 = if currentTimeFrame <= aggregationPeriod.TWENTY_MIN then aggregationPeriod.TWENTY_MIN else currentTimeFrame;
def M20Available = if currentTimeFrame <= aggregationPeriod.TWENTY_MIN then yes else no;
#def aM20 = aggregationPeriod.TWENTY_MIN;
def hiDiffM20 = high(period = aM20) - high(period = aM20)[1];
def loDiffM20 = low(period = aM20)[1] - low(period = aM20);

def plusDMM20 = if hiDiffM20 > loDiffM20 and hiDiffM20 > 0 then hiDiffM20 else 0;
def minusDMM20 =  if loDiffM20 > hiDiffM20 and loDiffM20 > 0 then loDiffM20 else 0;

def ATRM20 = MovingAverage(averageType, TrueRange(high(period = aM20), close(period = aM20), low(period = aM20)), length);
def "DI+M20" = 100 * MovingAverage(averageType, plusDMM20, length) / ATRM20;
def "DI-M20" = 100 * MovingAverage(averageType, minusDMM20, length) / ATRM20;

def DXM20 = if ("DI+M20" + "DI-M20" > 0) then 100 * AbsValue("DI+M20" - "DI-M20") / ("DI+M20" + "DI-M20") else 0;
def ADXM20 = MovingAverage(averageType, DXM20, length);

def bullishM20 = ("DI+M20" > "DI-M20") and (ADXM20 > adxlength);
def bearishM20 = ("DI+M20" < "DI-M20") and (ADXM20 > adxlength);
def sidewaysM20 = (ADXM20 < adxlength);

def sStateM20 = if bullishM20 then 100 else if bearishM20 then -100 else 0;
def sPOSM20 = if IsNan(sStateM20) then 0 else bullishM20;
def sNEGM20 = if IsNan(sStateM20) then 0 else bearishM20;
def sSIDM20 = if IsNan(sStateM20) then 0 else if sPOSM20 or sNEGM20 then 0 else sidewaysM20;

AddLabel(showlabels and show20MIN and M20Available, "20MIN", if IsNan(sStateM20) then COLOR.DARK_GRAY else
if sStateM20 == 100 then GlobalColor("Bullish") else
if sStateM20 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 9 - THIRTY MINUTES
def aM30 = if currentTimeFrame <= aggregationPeriod.THIRTY_MIN then aggregationPeriod.THIRTY_MIN else currentTimeFrame;
def M30Available = if currentTimeFrame <= aggregationPeriod.THIRTY_MIN then yes else no;
#def aM30 = aggregationPeriod.THIRTY_MIN;
def hiDiffM30 = high(period = aM30) - high(period = aM30)[1];
def loDiffM30 = low(period = aM30)[1] - low(period = aM30);

def plusDMM30 = if hiDiffM30 > loDiffM30 and hiDiffM30 > 0 then hiDiffM30 else 0;
def minusDMM30 =  if loDiffM30 > hiDiffM30 and loDiffM30 > 0 then loDiffM30 else 0;

def ATRM30 = MovingAverage(averageType, TrueRange(high(period = aM30), close(period = aM30), low(period = aM30)), length);
def "DI+M30" = 100 * MovingAverage(averageType, plusDMM30, length) / ATRM30;
def "DI-M30" = 100 * MovingAverage(averageType, minusDMM30, length) / ATRM30;

def DXM30 = if ("DI+M30" + "DI-M30" > 0) then 100 * AbsValue("DI+M30" - "DI-M30") / ("DI+M30" + "DI-M30") else 0;
def ADXM30 = MovingAverage(averageType, DXM30, length);

def bullishM30 = ("DI+M30" > "DI-M30") and (ADXM30 > adxlength);
def bearishM30 = ("DI+M30" < "DI-M30") and (ADXM30 > adxlength);
def sidewaysM30 = (ADXM30 < adxlength);

def sStateM30 = if bullishM30 then 100 else if bearishM30 then -100 else 0;
def sPOSM30 = if IsNan(sStateM30) then 0 else bullishM30;
def sNEGM30 = if IsNan(sStateM30) then 0 else bearishM30;
def sSIDM30 = if IsNan(sStateM30) then 0 else if sPOSM30 or sNEGM30 then 0 else sidewaysM30;

AddLabel(showlabels and show30MIN and M30Available, "30MIN", if IsNan(sStateM30) then COLOR.DARK_GRAY else
if sStateM30 == 100 then GlobalColor("Bullish") else
if sStateM30 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 10 - HOUR
def aH1 = if currentTimeFrame <= aggregationPeriod.HOUR then AggregationPeriod.HOUR else currentTimeFrame;
def H1Available = if currentTimeFrame <= aggregationPeriod.HOUR then yes else no;
#def aH1 = aggregationPeriod.HOUR;
def hiDiffH1 = high(period = aH1) - high(period = aH1)[1];
def loDiffH1 = low(period = aH1)[1] - low(period = aH1);

def plusDMH1 = if hiDiffH1 > loDiffH1 and hiDiffH1 > 0 then hiDiffH1 else 0;
def minusDMH1 =  if loDiffH1 > hiDiffH1 and loDiffH1 > 0 then loDiffH1 else 0;

def ATRH1 = MovingAverage(averageType, TrueRange(high(period = aH1), close(period = aH1), low(period = aH1)), length);
def "DI+H1" = 100 * MovingAverage(averageType, plusDMH1, length) / ATRH1;
def "DI-H1" = 100 * MovingAverage(averageType, minusDMH1, length) / ATRH1;

def DXH1 = if ("DI+H1" + "DI-H1" > 0) then 100 * AbsValue("DI+H1" - "DI-H1") / ("DI+H1" + "DI-H1") else 0;
def ADXH1 = MovingAverage(averageType, DXH1, length);

def bullishH1 = ("DI+H1" > "DI-H1") and (ADXH1 > adxlength);
def bearishH1 = ("DI+H1" < "DI-H1") and (ADXH1 > adxlength);
def sidewaysH1 = (ADXH1 < adxlength);

def sStateH1 = if bullishH1 then 100 else if bearishH1 then -100 else 0;
def sPOSH1 = if IsNan(sStateH1) then 0 else bullishH1;
def sNEGH1 = if IsNan(sStateH1) then 0 else bearishH1;
def sSIDH1 = if IsNan(sStateH1) then 0 else if sPOSH1 or sNEGH1 then 0 else sidewaysH1;

AddLabel(showlabels and show1HOUR and H1Available, "1HOUR", if IsNan(sStateH1) then COLOR.DARK_GRAY else
if sStateH1 == 100 then GlobalColor("Bullish") else
if sStateH1 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 11 - TWO HOURS
def aH2 = if currentTimeFrame <= aggregationPeriod.TWO_HOURS then aggregationPeriod.TWO_HOURS else currentTimeFrame;
def H2Available = if currentTimeFrame <= aggregationPeriod.TWO_HOURS then yes else no;
#def aH2 = aggregationPeriod.TWO_HOURS;
def hiDiffH2 = high(period = aH2) - high(period = aH2)[1];
def loDiffH2 = low(period = aH2)[1] - low(period = aH2);

def plusDMH2 = if hiDiffH2 > loDiffH2 and hiDiffH2 > 0 then hiDiffH2 else 0;
def minusDMH2 =  if loDiffH2 > hiDiffH2 and loDiffH2 > 0 then loDiffH2 else 0;

def ATRH2 = MovingAverage(averageType, TrueRange(high(period = aH2), close(period = aH2), low(period = aH2)), length);
def "DI+H2" = 100 * MovingAverage(averageType, plusDMH2, length) / ATRH2;
def "DI-H2" = 100 * MovingAverage(averageType, minusDMH2, length) / ATRH2;

def DXH2 = if ("DI+H2" + "DI-H2" > 0) then 100 * AbsValue("DI+H2" - "DI-H2") / ("DI+H2" + "DI-H2") else 0;
def ADXH2 = MovingAverage(averageType, DXH2, length);

def bullishH2 = ("DI+H2" > "DI-H2") and (ADXH2 > adxlength);
def bearishH2 = ("DI+H2" < "DI-H2") and (ADXH2 > adxlength);
def sidewaysH2 = (ADXH2 < adxlength);

def sStateH2 = if bullishH2 then 100 else if bearishH2 then -100 else 0;
def sPOSH2 = if IsNan(sStateH2) then 0 else bullishH2;
def sNEGH2 = if IsNan(sStateH2) then 0 else bearishH2;
def sSIDH2 = if IsNan(sStateH2) then 0 else if sPOSH2 or sNEGH2 then 0 else sidewaysH2;

AddLabel(showlabels and show2HOUR and H2Available, "2HOUR", if IsNan(sStateH2) then COLOR.DARK_GRAY else
if sStateH2 == 100 then GlobalColor("Bullish") else
if sStateH2 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 12 - FOUR HOURS
def aH4 = if currentTimeFrame <= aggregationPeriod.FOUR_HOURS then aggregationPeriod.FOUR_HOURS else currentTimeFrame;
def H4Available = if currentTimeFrame <= aggregationPeriod.FOUR_HOURS then yes else no;
#def aH4 = aggregationPeriod.FOUR_HOURS;
def hiDiffH4 = high(period = aH4) - high(period = aH4)[1];
def loDiffH4 = low(period = aH4)[1] - low(period = aH4);

def plusDMH4 = if hiDiffH4 > loDiffH4 and hiDiffH4 > 0 then hiDiffH4 else 0;
def minusDMH4 =  if loDiffH4 > hiDiffH4 and loDiffH4 > 0 then loDiffH4 else 0;

def ATRH4 = MovingAverage(averageType, TrueRange(high(period = aH4), close(period = aH4), low(period = aH4)), length);
def "DI+H4" = 100 * MovingAverage(averageType, plusDMH4, length) / ATRH4;
def "DI-H4" = 100 * MovingAverage(averageType, minusDMH4, length) / ATRH4;

def DXH4 = if ("DI+H4" + "DI-H4" > 0) then 100 * AbsValue("DI+H4" - "DI-H4") / ("DI+H4" + "DI-H4") else 0;
def ADXH4 = MovingAverage(averageType, DXH4, length);

def bullishH4 = ("DI+H4" > "DI-H4") and (ADXH4 > adxlength);
def bearishH4 = ("DI+H4" < "DI-H4") and (ADXH4 > adxlength);
def sidewaysH4 = (ADXH4 < adxlength);

def sStateH4 = if bullishH4 then 100 else if bearishH4 then -100 else 0;
def sPOSH4 = if IsNan(sStateH4) then 0 else bullishH4;
def sNEGH4 = if IsNan(sStateH4) then 0 else bearishH4;
def sSIDH4 = if IsNan(sStateH4) then 0 else if sPOSH4 or sNEGH4 then 0 else sidewaysH4;

AddLabel(showlabels and show4HOUR and H4Available, "4HOUR", if IsNan(sStateH4) then COLOR.DARK_GRAY else
if sStateH4 == 100 then GlobalColor("Bullish") else
if sStateH4 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 13 - ONE DAY
def aD1 = if currentTimeFrame <= aggregationPeriod.DAY then aggregationPeriod.DAY else currentTimeFrame;
def D1Available = if currentTimeFrame <= aggregationPeriod.DAY then yes else no;
#def aD1 = aggregationPeriod.DAY;
def hiDiffD1 = high(period = aD1) - high(period = aD1)[1];
def loDiffD1 = low(period = aD1)[1] - low(period = aD1);

def plusDMD1 = if hiDiffD1 > loDiffD1 and hiDiffD1 > 0 then hiDiffD1 else 0;
def minusDMD1 =  if loDiffD1 > hiDiffD1 and loDiffD1 > 0 then loDiffD1 else 0;

def ATRD1 = MovingAverage(averageType, TrueRange(high(period = aD1), close(period = aD1), low(period = aD1)), length);
def "DI+D1" = 100 * MovingAverage(averageType, plusDMD1, length) / ATRD1;
def "DI-D1" = 100 * MovingAverage(averageType, minusDMD1, length) / ATRD1;

def DXD1 = if ("DI+D1" + "DI-D1" > 0) then 100 * AbsValue("DI+D1" - "DI-D1") / ("DI+D1" + "DI-D1") else 0;
def ADXD1 = MovingAverage(averageType, DXD1, length);

def bullishD1 = ("DI+D1" > "DI-D1") and (ADXD1 > adxlength);
def bearishD1 = ("DI+D1" < "DI-D1") and (ADXD1 > adxlength);
def sidewaysD1 = (ADXD1 < adxlength);

def sStateD1 = if bullishD1 then 100 else if bearishD1 then -100 else 0;
def sPOSD1 = if IsNan(sStateD1) then 0 else bullishD1;
def sNEGD1 = if IsNan(sStateD1) then 0 else bearishD1;
def sSIDD1 = if IsNan(sStateD1) then 0 else if sPOSD1 or sNEGD1 then 0 else sidewaysD1;

AddLabel(showlabels and show1DAY and D1Available, "1DAY", if IsNan(sStateD1) then COLOR.DARK_GRAY else
if sStateD1 == 100 then GlobalColor("Bullish") else
if sStateD1 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 14 - TWO DAYS
def aD2 = if currentTimeFrame <= aggregationPeriod.TWO_DAYS then aggregationPeriod.TWO_DAYS else currentTimeFrame;
def D2Available = if currentTimeFrame <= aggregationPeriod.TWO_DAYS then yes else no;
#def aD2 = aggregationPeriod.TWO_DAYS;
def hiDiffD2 = high(period = aD2) - high(period = aD2)[1];
def loDiffD2 = low(period = aD2)[1] - low(period = aD2);

def plusDMD2 = if hiDiffD2 > loDiffD2 and hiDiffD2 > 0 then hiDiffD2 else 0;
def minusDMD2 =  if loDiffD2 > hiDiffD2 and loDiffD2 > 0 then loDiffD2 else 0;

def ATRD2 = MovingAverage(averageType, TrueRange(high(period = aD2), close(period = aD2), low(period = aD2)), length);
def "DI+D2" = 100 * MovingAverage(averageType, plusDMD2, length) / ATRD2;
def "DI-D2" = 100 * MovingAverage(averageType, minusDMD2, length) / ATRD2;

def DXD2 = if ("DI+D2" + "DI-D2" > 0) then 100 * AbsValue("DI+D2" - "DI-D2") / ("DI+D2" + "DI-D2") else 0;
def ADXD2 = MovingAverage(averageType, DXD2, length);

def bullishD2 = ("DI+D2" > "DI-D2") and (ADXD2 > adxlength);
def bearishD2 = ("DI+D2" < "DI-D2") and (ADXD2 > adxlength);
def sidewaysD2 = (ADXD2 < adxlength);

def sStateD2 = if bullishD2 then 100 else if bearishD2 then -100 else 0;
def sPOSD2 = if IsNan(sStateD2) then 0 else bullishD2;
def sNEGD2 = if IsNan(sStateD2) then 0 else bearishD2;
def sSIDD2 = if IsNan(sStateD2) then 0 else if sPOSD2 or sNEGD2 then 0 else sidewaysD2;

AddLabel(showlabels and show2DAY and D2Available, "2DAY", if IsNan(sStateD2) then COLOR.DARK_GRAY else
if sStateD2 == 100 then GlobalColor("Bullish") else
if sStateD2 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 15 - THREE DAYS
def aD3 = if currentTimeFrame <= aggregationPeriod.THREE_DAYS then aggregationPeriod.THREE_DAYS else currentTimeFrame;
def D3Available = if currentTimeFrame <= aggregationPeriod.THREE_DAYS then yes else no;
#def aD3 = aggregationPeriod.THREE_DAYS;
def hiDiffD3 = high(period = aD3) - high(period = aD3)[1];
def loDiffD3 = low(period = aD3)[1] - low(period = aD3);

def plusDMD3 = if hiDiffD3 > loDiffD3 and hiDiffD3 > 0 then hiDiffD3 else 0;
def minusDMD3 =  if loDiffD3 > hiDiffD3 and loDiffD3 > 0 then loDiffD3 else 0;

def ATRD3 = MovingAverage(averageType, TrueRange(high(period = aD3), close(period = aD3), low(period = aD3)), length);
def "DI+D3" = 100 * MovingAverage(averageType, plusDMD3, length) / ATRD3;
def "DI-D3" = 100 * MovingAverage(averageType, minusDMD3, length) / ATRD3;

def DXD3 = if ("DI+D3" + "DI-D3" > 0) then 100 * AbsValue("DI+D3" - "DI-D3") / ("DI+D3" + "DI-D3") else 0;
def ADXD3 = MovingAverage(averageType, DXD3, length);

def bullishD3 = ("DI+D3" > "DI-D3") and (ADXD3 > adxlength);
def bearishD3 = ("DI+D3" < "DI-D3") and (ADXD3 > adxlength);
def sidewaysD3 = (ADXD3 < adxlength);

def sStateD3 = if bullishD3 then 100 else if bearishD3 then -100 else 0;
def sPOSD3 = if IsNan(sStateD3) then 0 else bullishD3;
def sNEGD3 = if IsNan(sStateD3) then 0 else bearishD3;
def sSIDD3 = if IsNan(sStateD3) then 0 else if sPOSD3 or sNEGD3 then 0 else sidewaysD3;

AddLabel(showlabels and show3DAY and D3Available, "3DAY", if IsNan(sStateD3) then COLOR.DARK_GRAY else
if sStateD3 == 100 then GlobalColor("Bullish") else
if sStateD3 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 16 - FOUR DAYS
def aD4 = if currentTimeFrame <= aggregationPeriod.FOUR_DAYS then aggregationPeriod.FOUR_DAYS else currentTimeFrame;
def D4Available = if currentTimeFrame <= aggregationPeriod.FOUR_DAYS then yes else no;
#def aD4 = aggregationPeriod.FOUR_DAYS;
def hiDiffD4 = high(period = aD4) - high(period = aD4)[1];
def loDiffD4 = low(period = aD4)[1] - low(period = aD4);

def plusDMD4 = if hiDiffD4 > loDiffD4 and hiDiffD4 > 0 then hiDiffD4 else 0;
def minusDMD4 =  if loDiffD4 > hiDiffD4 and loDiffD4 > 0 then loDiffD4 else 0;

def ATRD4 = MovingAverage(averageType, TrueRange(high(period = aD4), close(period = aD4), low(period = aD4)), length);
def "DI+D4" = 100 * MovingAverage(averageType, plusDMD4, length) / ATRD4;
def "DI-D4" = 100 * MovingAverage(averageType, minusDMD4, length) / ATRD4;

def DXD4 = if ("DI+D4" + "DI-D4" > 0) then 100 * AbsValue("DI+D4" - "DI-D4") / ("DI+D4" + "DI-D4") else 0;
def ADXD4 = MovingAverage(averageType, DXD4, length);

def bullishD4 = ("DI+D4" > "DI-D4") and (ADXD4 > adxlength);
def bearishD4 = ("DI+D4" < "DI-D4") and (ADXD4 > adxlength);
def sidewaysD4 = (ADXD4 < adxlength);

def sStateD4 = if bullishD4 then 100 else if bearishD4 then -100 else 0;
def sPOSD4 = if IsNan(sStateD4) then 0 else bullishD4;
def sNEGD4 = if IsNan(sStateD4) then 0 else bearishD4;
def sSIDD4 = if IsNan(sStateD4) then 0 else if sPOSD4 or sNEGD4 then 0 else sidewaysD4;

AddLabel(showlabels and show4DAY and D4Available, "4DAY", if IsNan(sStateD4) then COLOR.DARK_GRAY else
if sStateD4 == 100 then GlobalColor("Bullish") else
if sStateD4 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 17 - ONE WEEK
def aW1 = if currentTimeFrame <= aggregationPeriod.WEEK then aggregationPeriod.WEEK else currentTimeFrame;
def W1Available = if currentTimeFrame <= aggregationPeriod.WEEK then yes else no;
#def aW1 = aggregationPeriod.WEEK;
def hiDiffW1 = high(period = aW1) - high(period = aW1)[1];
def loDiffW1 = low(period = aW1)[1] - low(period = aW1);

def plusDMW1 = if hiDiffW1 > loDiffW1 and hiDiffW1 > 0 then hiDiffW1 else 0;
def minusDMW1 =  if loDiffW1 > hiDiffW1 and loDiffW1 > 0 then loDiffW1 else 0;

def ATRW1 = MovingAverage(averageType, TrueRange(high(period = aW1), close(period = aW1), low(period = aW1)), length);
def "DI+W1" = 100 * MovingAverage(averageType, plusDMW1, length) / ATRW1;
def "DI-W1" = 100 * MovingAverage(averageType, minusDMW1, length) / ATRW1;

def DXW1 = if ("DI+W1" + "DI-W1" > 0) then 100 * AbsValue("DI+W1" - "DI-W1") / ("DI+W1" + "DI-W1") else 0;
def ADXW1 = MovingAverage(averageType, DXW1, length);

def bullishW1 = ("DI+W1" > "DI-W1") and (ADXW1 > adxlength);
def bearishW1 = ("DI+W1" < "DI-W1") and (ADXW1 > adxlength);
def sidewaysW1 = (ADXW1 < adxlength);

def sStateW1 = if bullishW1 then 100 else if bearishW1 then -100 else 0;
def sPOSW1 = if IsNan(sStateW1) then 0 else bullishW1;
def sNEGW1 = if IsNan(sStateW1) then 0 else bearishW1;
def sSIDW1 = if IsNan(sStateW1) then 0 else if sPOSW1 or sNEGW1 then 0 else sidewaysW1;

AddLabel(showlabels and showWEEK and W1Available, "WEEK", if IsNan(sStateW1) then COLOR.DARK_GRAY else
if sStateW1 == 100 then GlobalColor("Bullish") else
if sStateW1 == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));


# AGGREGATION 18 - ONE MONTH
def aMM = if currentTimeFrame <= aggregationPeriod.MONTH then aggregationPeriod.MONTH else currentTimeFrame;
def MMAvailable = if currentTimeFrame <= aggregationPeriod.MONTH then yes else no;
#def aMM = aggregationPeriod.MONTH;
def hiDiffMM = high(period = aMM) - high(period = aMM)[1];
def loDiffMM = low(period = aMM)[1] - low(period = aMM);

def plusDMMM = if hiDiffMM > loDiffMM and hiDiffMM > 0 then hiDiffMM else 0;
def minusDMMM =  if loDiffMM > hiDiffMM and loDiffMM > 0 then loDiffMM else 0;

def ATRMM = MovingAverage(averageType, TrueRange(high(period = aMM), close(period = aMM), low(period = aMM)), length);
def "DI+MM" = 100 * MovingAverage(averageType, plusDMMM, length) / ATRMM;
def "DI-MM" = 100 * MovingAverage(averageType, minusDMMM, length) / ATRMM;

def DXMM = if ("DI+MM" + "DI-MM" > 0) then 100 * AbsValue("DI+MM" - "DI-MM") / ("DI+MM" + "DI-MM") else 0;
def ADXMM = MovingAverage(averageType, DXMM, length);

def bullishMM = ("DI+MM" > "DI-MM") and (ADXMM > adxlength);
def bearishMM = ("DI+MM" < "DI-MM") and (ADXMM > adxlength);
def sidewaysMM = (ADXMM < adxlength);

def sStateMM = if bullishMM then 100 else if bearishMM then -100 else 0;
def sPOSMM = if IsNan(sStateMM) then 0 else bullishMM;
def sNEGMM = if IsNan(sStateMM) then 0 else bearishMM;
def sSIDMM = if IsNan(sStateMM) then 0 else if sPOSMM or sNEGMM then 0 else sidewaysMM;

AddLabel(showlabels and showMONTH and MMAvailable, "MONTH", if IsNan(sStateMM) then COLOR.DARK_GRAY else
if sStateMM == 100 then GlobalColor("Bullish") else
if sStateMM == -100 then GlobalColor("Bearish")
else GlobalColor("Neutral"));

#STATS
def sPOS = sPOSM1 + sPOSM2 + sPOSM3 + sPOSM4 + sPOSM5 + sPOSM10 + sPOSM15 +
sPOSM20 + sPOSM30 + sPOSH1 + sPOSH2 + sPOSH4 + sPOSD1 + sPOSD2 + sPOSD3 +
sPOSD4 + sPOSW1 + sPOSMM;

def sNEG = sNEGM1 + sNEGM2 + sNEGM3 + sNEGM4 + sNEGM5 + sNEGM10 + sNEGM15 +
sNEGM20 + sNEGM30 + sNEGH1 + sNEGH2 + sNEGH4 + sNEGD1 + sNEGD2 + sNEGD3 +
sNEGD4 + sNEGW1 + sNEGMM;

def sSID = sSIDM1 + sSIDM2 + sSIDM3 + sSIDM4 + sSIDM5 + sSIDM10 + sSIDM15 +
sSIDM20 + sSIDM30 + sSIDH1 + sSIDH2 + sSIDH4 + sSIDD1 + sSIDD2 + sSIDD3 +
sSIDD4 + sSIDW1 + sSIDMM;

def sTOL = sPOS + sNEG + sSID;

AddLabel (showstats, "Bullish: " + sPOS + " (" +
  AsPercent(Round(sPOS / sTOL, 2)) + ")", GlobalColor("Bullish"));

AddLabel (showstats, "Bearish: " + sNEG + " (" +
  AsPercent(Round(sNEG / sTOL, 2)) + ")", GlobalColor("Bearish"));

AddLabel (showstats, "Neutral: " + sSID + " (" +
  AsPercent(Round(sSID / sTOL, 2)) + ")", GlobalColor("Neutral"));


# END OF Visual DMI (The 10x Bars) MTF Labels for ThinkorSwim
 
Very good @billgt one little thing. Please edit your post with the changes in the changelog at the script top. Very important for continuity. Thanks!
 
Very good @billgt one little thing. Please edit your post with the changes in the changelog at the script top. Very important for continuity. Thanks!
Hi @billgt - great fix! - ty - I'm going to merge the changes with master repository, update the changelog, increment the version number and repost.
 
Very good @billgt one little thing. Please edit your post with the changes in the changelog at the script top. Very important for continuity. Thanks!

I wasn't sure I should do that here since this was kind of an interim change. Maybe I should have wait and posted only once I fixed everything? What is the norm? Thanks!
 
thanks @billgt. Updated to include your recommendations and addressed the stats calcs to work across higher timeframes as well.

Ruby:
#Visual DMI (The 10x Bars) MTF Labels for ThinkorSwim V1.7
#Last Updated on Wednesday, November 27 2019 at 04:18:47 PM
#
#CREDITS
# John Carter's 10x bars, @sierioiza, @tomsk, @horserider, @markos, @billgt
#
#CHANGELOG
# 2019.11.25 1.0 @diazlaz - Updated Port
# 2019.11.25 1.1 @diazlaz - Added Month Time frame
# 2019.11.25 1.2 @diazlaz - Added additional timecheck on chart and instructions
# 2019.11.25 1.2 @diazlaz - Added additional aggregation periods (18 total)
# 2019.11.25 1.2 @diazlaz - Added additional periods 4MIN, 20MIN, 2DAYS, 4DAYS
# 2019.11.25 1.3 @diazlaz - Added adxlength and showlabels inputs
# 2019.11.25 1.4 @diazlaz - Added states and stats labels
# 2019.11.25 1.5 @diazlaz - Added fix for NaN when data is not available
#                           such as monthly for UBER due to recent IPO.
#                           colors Label as Dark Gray when no data is available.
#                           handles count of stats when error is encountered.
# 2019.11.25 1.6 @diazlaz - Added inputs for label display all aggregation periods
#                           default display all set to yes.
#                           Note:
#                            STATS still calc all periods. if this is a ask to filter
#                            based on displayed aggregation periods please let me know
#                            and will incorporate this request.
# 2019.11.27 1.7 @diazlaz - Incorporated custom stats to support custom aggregations
#                @billgt  - Incorporated logic to allow for initial higher aggregations
#                           and label filters for lower timeframes.
#
#DESCRIPTION
# For TSLA, we can see the 10X bars across various time frames,
# from the Weekly down to the 1-minute chart.  We can see at a
# glance that there is strong GREEN momentum across most time frames.
# Any short-term red sets up a buying opportunity back in the direction
# of the longer-term greens and vice versa.
#
#
#INSTRUCTIONS
# Recommended timeframe chart setup:  1 minute and 30 days.
# Lables will adjust to highest timeframe and filter lower time frames
#
#

#INPUTS
input length = 14; #DI+- length
input adxlength = 20; #ADX sideways length
input averageType = AverageType.WILDERS;
input showlabels = yes; #show labels
input showstats = yes; #show stats

input show1MIN = yes; #show ONE MINUTE label
input show2MIN = yes; #show TWO MINUTES label
input show3MIN = yes; #show THREE MINUTES label
input show4MIN = yes; #show FOUR MINUTES label
input show5MIN = yes; #show FIVE MINUTES label
input show10MIN = yes; #show TEN MINUTES label
input show15MIN = yes; #show FIFTEEN MINUTES label
input show20MIN = yes; #show TWENTY MINUTES label
input show30MIN = yes; #show THIRTY MINUTES label
input show1HOUR = yes; #show HOUR label
input show2HOUR = yes; #show TWO HOURS label
input show4HOUR = yes; #show FOUR HOURS label
input show1DAY = yes; #show ONE DAY label
input show2DAY = yes; #show TWO DAYS label
input show3DAY = yes; #show THREE DAYS label
input show4DAY = yes; #show FOUR DAYS label
input showWEEK = yes; #show ONE WEEK label
input showMONTH = yes; #show ONE MONTH label

#CORE
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.YELLOW);

#TIMEFRAME CHECK
def currentTimeFrame = getAggregationPeriod();
#assert(currentTimeFrame == AggregationPeriod.MIN, "ERROR: timeFrame needs to be 1 minute");

#LABELS
AddLabel(showlabels, "10X System V1.7", COLOR.CYAN);


# AGGREGATION 1 - ONE MINUTE
def aM1 = if currentTimeFrame <= aggregationPeriod.MIN then aggregationPeriod.MIN else currentTimeFrame;
def availableM1 = currentTimeFrame <= aggregationPeriod.MIN;
def hiDiffM1 = high(period = aM1) - high(period = aM1)[1];
def loDiffM1 = low(period = aM1)[1] - low(period = aM1);

def plusDMM1 = if hiDiffM1 > loDiffM1 and hiDiffM1 > 0 then hiDiffM1 else 0;
def minusDMM1 =  if loDiffM1 > hiDiffM1 and loDiffM1 > 0 then loDiffM1 else 0;

def ATRM1 = MovingAverage(averageType, TrueRange(high(period = aM1), close(period = aM1), low(period = aM1)), length);
def "DI+M1" = 100 * MovingAverage(averageType, plusDMM1, length) / ATRM1;
def "DI-M1" = 100 * MovingAverage(averageType, minusDMM1, length) / ATRM1;

def DXM1 = if ("DI+M1" + "DI-M1" > 0) then 100 * AbsValue("DI+M1" - "DI-M1") / ("DI+M1" + "DI-M1") else 0;
def ADXM1 = MovingAverage(averageType, DXM1, length);

def bullishM1 = ("DI+M1" > "DI-M1") and (ADXM1 > adxlength);
def bearishM1 = ("DI+M1" < "DI-M1") and (ADXM1 > adxlength);
def sidewaysM1 = (ADXM1 < adxlength);

def sStateM1 =  if !availableM1 then Double.NaN else if bullishM1 then 100 else if bearishM1 then -100 else 0;
def sPOSM1 = if IsNan(sStateM1) then 0 else bullishM1;
def sNEGM1 = if IsNan(sStateM1) then 0 else bearishM1;
def sSIDM1 = if IsNan(sStateM1) then 0 else if sPOSM1 or sNEGM1 then 0 else sidewaysM1;

AddLabel(showlabels and show1MIN and availableM1, "1MIN", if IsNan(sStateM1) then COLOR.DARK_GRAY else
 if sStateM1 == 100 then GlobalColor("Bullish") else
 if sStateM1 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 2 - TWO MINUTES
def aM2 = if currentTimeFrame <= aggregationPeriod.TWO_MIN then aggregationPeriod.TWO_MIN else currentTimeFrame;
def availableM2 = currentTimeFrame <= aggregationPeriod.TWO_MIN;
def hiDiffM2 = high(period = aM2) - high(period = aM2)[1];
def loDiffM2 = low(period = aM2)[1] - low(period = aM2);

def plusDMM2 = if hiDiffM2 > loDiffM2 and hiDiffM2 > 0 then hiDiffM2 else 0;
def minusDMM2 =  if loDiffM2 > hiDiffM2 and loDiffM2 > 0 then loDiffM2 else 0;

def ATRM2 = MovingAverage(averageType, TrueRange(high(period = aM2), close(period = aM2), low(period = aM2)), length);
def "DI+M2" = 100 * MovingAverage(averageType, plusDMM2, length) / ATRM2;
def "DI-M2" = 100 * MovingAverage(averageType, minusDMM2, length) / ATRM2;

def DXM2 = if ("DI+M2" + "DI-M2" > 0) then 100 * AbsValue("DI+M2" - "DI-M2") / ("DI+M2" + "DI-M2") else 0;
def ADXM2 = MovingAverage(averageType, DXM2, length);

def bullishM2 = ("DI+M2" > "DI-M2") and (ADXM2 > adxlength);
def bearishM2 = ("DI+M2" < "DI-M2") and (ADXM2 > adxlength);
def sidewaysM2 = (ADXM2 < adxlength);

def sStateM2 =  if !availableM2 then Double.NaN else if bullishM2 then 100 else if bearishM2 then -100 else 0;
def sPOSM2 = if IsNan(sStateM2) then 0 else bullishM2;
def sNEGM2 = if IsNan(sStateM2) then 0 else bearishM2;
def sSIDM2 = if IsNan(sStateM2) then 0 else if sPOSM2 or sNEGM2 then 0 else sidewaysM2;

AddLabel(showlabels and show2MIN and availableM2, "2MIN", if IsNan(sStateM2) then COLOR.DARK_GRAY else
 if sStateM2 == 100 then GlobalColor("Bullish") else
 if sStateM2 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 3 - THREE MINUTES
def aM3 = if currentTimeFrame <= aggregationPeriod.THREE_MIN then aggregationPeriod.THREE_MIN else currentTimeFrame;
def availableM3 = currentTimeFrame <= aggregationPeriod.THREE_MIN;
def hiDiffM3 = high(period = aM3) - high(period = aM3)[1];
def loDiffM3 = low(period = aM3)[1] - low(period = aM3);

def plusDMM3 = if hiDiffM3 > loDiffM3 and hiDiffM3 > 0 then hiDiffM3 else 0;
def minusDMM3 =  if loDiffM3 > hiDiffM3 and loDiffM3 > 0 then loDiffM3 else 0;

def ATRM3 = MovingAverage(averageType, TrueRange(high(period = aM3), close(period = aM3), low(period = aM3)), length);
def "DI+M3" = 100 * MovingAverage(averageType, plusDMM3, length) / ATRM3;
def "DI-M3" = 100 * MovingAverage(averageType, minusDMM3, length) / ATRM3;

def DXM3 = if ("DI+M3" + "DI-M3" > 0) then 100 * AbsValue("DI+M3" - "DI-M3") / ("DI+M3" + "DI-M3") else 0;
def ADXM3 = MovingAverage(averageType, DXM3, length);

def bullishM3 = ("DI+M3" > "DI-M3") and (ADXM3 > adxlength);
def bearishM3 = ("DI+M3" < "DI-M3") and (ADXM3 > adxlength);
def sidewaysM3 = (ADXM3 < adxlength);

def sStateM3 =  if !availableM3 then Double.NaN else if bullishM3 then 100 else if bearishM3 then -100 else 0;
def sPOSM3 = if IsNan(sStateM3) then 0 else bullishM3;
def sNEGM3 = if IsNan(sStateM3) then 0 else bearishM3;
def sSIDM3 = if IsNan(sStateM3) then 0 else if sPOSM3 or sNEGM3 then 0 else sidewaysM3;

AddLabel(showlabels and show3MIN and availableM3, "3MIN", if IsNan(sStateM3) then COLOR.DARK_GRAY else
 if sStateM3 == 100 then GlobalColor("Bullish") else
 if sStateM3 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 4 - FOUR MINUTES
def aM4 = if currentTimeFrame <= aggregationPeriod.FOUR_MIN then aggregationPeriod.FOUR_MIN else currentTimeFrame;
def availableM4 = currentTimeFrame <= aggregationPeriod.FOUR_MIN;
def hiDiffM4 = high(period = aM4) - high(period = aM4)[1];
def loDiffM4 = low(period = aM4)[1] - low(period = aM4);

def plusDMM4 = if hiDiffM4 > loDiffM4 and hiDiffM4 > 0 then hiDiffM4 else 0;
def minusDMM4 =  if loDiffM4 > hiDiffM4 and loDiffM4 > 0 then loDiffM4 else 0;

def ATRM4 = MovingAverage(averageType, TrueRange(high(period = aM4), close(period = aM4), low(period = aM4)), length);
def "DI+M4" = 100 * MovingAverage(averageType, plusDMM4, length) / ATRM4;
def "DI-M4" = 100 * MovingAverage(averageType, minusDMM4, length) / ATRM4;

def DXM4 = if ("DI+M4" + "DI-M4" > 0) then 100 * AbsValue("DI+M4" - "DI-M4") / ("DI+M4" + "DI-M4") else 0;
def ADXM4 = MovingAverage(averageType, DXM4, length);

def bullishM4 = ("DI+M4" > "DI-M4") and (ADXM4 > adxlength);
def bearishM4 = ("DI+M4" < "DI-M4") and (ADXM4 > adxlength);
def sidewaysM4 = (ADXM4 < adxlength);

def sStateM4 =  if !availableM4 then Double.NaN else if bullishM4 then 100 else if bearishM4 then -100 else 0;
def sPOSM4 = if IsNan(sStateM4) then 0 else bullishM4;
def sNEGM4 = if IsNan(sStateM4) then 0 else bearishM4;
def sSIDM4 = if IsNan(sStateM4) then 0 else if sPOSM4 or sNEGM4 then 0 else sidewaysM4;

AddLabel(showlabels and show4MIN and availableM4, "4MIN", if IsNan(sStateM4) then COLOR.DARK_GRAY else
 if sStateM4 == 100 then GlobalColor("Bullish") else
 if sStateM4 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 5 - FIVE MINUTES
def aM5 = if currentTimeFrame <= aggregationPeriod.FIVE_MIN then aggregationPeriod.FIVE_MIN else currentTimeFrame;
def availableM5 = currentTimeFrame <= aggregationPeriod.FIVE_MIN;
def hiDiffM5 = high(period = aM5) - high(period = aM5)[1];
def loDiffM5 = low(period = aM5)[1] - low(period = aM5);

def plusDMM5 = if hiDiffM5 > loDiffM5 and hiDiffM5 > 0 then hiDiffM5 else 0;
def minusDMM5 =  if loDiffM5 > hiDiffM5 and loDiffM5 > 0 then loDiffM5 else 0;

def ATRM5 = MovingAverage(averageType, TrueRange(high(period = aM5), close(period = aM5), low(period = aM5)), length);
def "DI+M5" = 100 * MovingAverage(averageType, plusDMM5, length) / ATRM5;
def "DI-M5" = 100 * MovingAverage(averageType, minusDMM5, length) / ATRM5;

def DXM5 = if ("DI+M5" + "DI-M5" > 0) then 100 * AbsValue("DI+M5" - "DI-M5") / ("DI+M5" + "DI-M5") else 0;
def ADXM5 = MovingAverage(averageType, DXM5, length);

def bullishM5 = ("DI+M5" > "DI-M5") and (ADXM5 > adxlength);
def bearishM5 = ("DI+M5" < "DI-M5") and (ADXM5 > adxlength);
def sidewaysM5 = (ADXM5 < adxlength);

def sStateM5 =  if !availableM5 then Double.NaN else if bullishM5 then 100 else if bearishM5 then -100 else 0;
def sPOSM5 = if IsNan(sStateM5) then 0 else bullishM5;
def sNEGM5 = if IsNan(sStateM5) then 0 else bearishM5;
def sSIDM5 = if IsNan(sStateM5) then 0 else if sPOSM5 or sNEGM5 then 0 else sidewaysM5;

AddLabel(showlabels and show5MIN and availableM5, "5MIN", if IsNan(sStateM5) then COLOR.DARK_GRAY else
 if sStateM5 == 100 then GlobalColor("Bullish") else
 if sStateM5 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 6 - TEN MINUTES
def aM10 = if currentTimeFrame <= aggregationPeriod.TEN_MIN then aggregationPeriod.TEN_MIN else currentTimeFrame;
def availableM10 = currentTimeFrame <= aggregationPeriod.TEN_MIN;
def hiDiffM10 = high(period = aM10) - high(period = aM10)[1];
def loDiffM10 = low(period = aM10)[1] - low(period = aM10);

def plusDMM10 = if hiDiffM10 > loDiffM10 and hiDiffM10 > 0 then hiDiffM10 else 0;
def minusDMM10 =  if loDiffM10 > hiDiffM10 and loDiffM10 > 0 then loDiffM10 else 0;

def ATRM10 = MovingAverage(averageType, TrueRange(high(period = aM10), close(period = aM10), low(period = aM10)), length);
def "DI+M10" = 100 * MovingAverage(averageType, plusDMM10, length) / ATRM10;
def "DI-M10" = 100 * MovingAverage(averageType, minusDMM10, length) / ATRM10;

def DXM10 = if ("DI+M10" + "DI-M10" > 0) then 100 * AbsValue("DI+M10" - "DI-M10") / ("DI+M10" + "DI-M10") else 0;
def ADXM10 = MovingAverage(averageType, DXM10, length);

def bullishM10 = ("DI+M10" > "DI-M10") and (ADXM10 > adxlength);
def bearishM10 = ("DI+M10" < "DI-M10") and (ADXM10 > adxlength);
def sidewaysM10 = (ADXM10 < adxlength);

def sStateM10 =  if !availableM10 then Double.NaN else if bullishM10 then 100 else if bearishM10 then -100 else 0;
def sPOSM10 = if IsNan(sStateM10) then 0 else bullishM10;
def sNEGM10 = if IsNan(sStateM10) then 0 else bearishM10;
def sSIDM10 = if IsNan(sStateM10) then 0 else if sPOSM10 or sNEGM10 then 0 else sidewaysM10;

AddLabel(showlabels and show10MIN and availableM10, "10MIN", if IsNan(sStateM10) then COLOR.DARK_GRAY else
 if sStateM10 == 100 then GlobalColor("Bullish") else
 if sStateM10 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 7 - FIFTEEN MINUTES
def aM15 = if currentTimeFrame <= aggregationPeriod.FIFTEEN_MIN then aggregationPeriod.FIFTEEN_MIN else currentTimeFrame;
def availableM15 = currentTimeFrame <= aggregationPeriod.FIFTEEN_MIN;
def hiDiffM15 = high(period = aM15) - high(period = aM15)[1];
def loDiffM15 = low(period = aM15)[1] - low(period = aM15);

def plusDMM15 = if hiDiffM15 > loDiffM15 and hiDiffM15 > 0 then hiDiffM15 else 0;
def minusDMM15 =  if loDiffM15 > hiDiffM15 and loDiffM15 > 0 then loDiffM15 else 0;

def ATRM15 = MovingAverage(averageType, TrueRange(high(period = aM15), close(period = aM15), low(period = aM15)), length);
def "DI+M15" = 100 * MovingAverage(averageType, plusDMM15, length) / ATRM15;
def "DI-M15" = 100 * MovingAverage(averageType, minusDMM15, length) / ATRM15;

def DXM15 = if ("DI+M15" + "DI-M15" > 0) then 100 * AbsValue("DI+M15" - "DI-M15") / ("DI+M15" + "DI-M15") else 0;
def ADXM15 = MovingAverage(averageType, DXM15, length);

def bullishM15 = ("DI+M15" > "DI-M15") and (ADXM15 > adxlength);
def bearishM15 = ("DI+M15" < "DI-M15") and (ADXM15 > adxlength);
def sidewaysM15 = (ADXM15 < adxlength);

def sStateM15 =  if !availableM15 then Double.NaN else if bullishM15 then 100 else if bearishM15 then -100 else 0;
def sPOSM15 = if IsNan(sStateM15) then 0 else bullishM15;
def sNEGM15 = if IsNan(sStateM15) then 0 else bearishM15;
def sSIDM15 = if IsNan(sStateM15) then 0 else if sPOSM15 or sNEGM15 then 0 else sidewaysM15;

AddLabel(showlabels and show15MIN and availableM15, "15MIN", if IsNan(sStateM15) then COLOR.DARK_GRAY else
 if sStateM15 == 100 then GlobalColor("Bullish") else
 if sStateM15 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 8 - TWENTY MINUTES
def aM20 = if currentTimeFrame <= aggregationPeriod.TWENTY_MIN then aggregationPeriod.TWENTY_MIN else currentTimeFrame;
def availableM20 = currentTimeFrame <= aggregationPeriod.TWENTY_MIN;
def hiDiffM20 = high(period = aM20) - high(period = aM20)[1];
def loDiffM20 = low(period = aM20)[1] - low(period = aM20);

def plusDMM20 = if hiDiffM20 > loDiffM20 and hiDiffM20 > 0 then hiDiffM20 else 0;
def minusDMM20 =  if loDiffM20 > hiDiffM20 and loDiffM20 > 0 then loDiffM20 else 0;

def ATRM20 = MovingAverage(averageType, TrueRange(high(period = aM20), close(period = aM20), low(period = aM20)), length);
def "DI+M20" = 100 * MovingAverage(averageType, plusDMM20, length) / ATRM20;
def "DI-M20" = 100 * MovingAverage(averageType, minusDMM20, length) / ATRM20;

def DXM20 = if ("DI+M20" + "DI-M20" > 0) then 100 * AbsValue("DI+M20" - "DI-M20") / ("DI+M20" + "DI-M20") else 0;
def ADXM20 = MovingAverage(averageType, DXM20, length);

def bullishM20 = ("DI+M20" > "DI-M20") and (ADXM20 > adxlength);
def bearishM20 = ("DI+M20" < "DI-M20") and (ADXM20 > adxlength);
def sidewaysM20 = (ADXM20 < adxlength);

def sStateM20 =  if !availableM20 then Double.NaN else if bullishM20 then 100 else if bearishM20 then -100 else 0;
def sPOSM20 = if IsNan(sStateM20) then 0 else bullishM20;
def sNEGM20 = if IsNan(sStateM20) then 0 else bearishM20;
def sSIDM20 = if IsNan(sStateM20) then 0 else if sPOSM20 or sNEGM20 then 0 else sidewaysM20;

AddLabel(showlabels and show20MIN and availableM20, "20MIN", if IsNan(sStateM20) then COLOR.DARK_GRAY else
 if sStateM20 == 100 then GlobalColor("Bullish") else
 if sStateM20 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 9 - THIRTY MINUTES
def aM30 = if currentTimeFrame <= aggregationPeriod.THIRTY_MIN then aggregationPeriod.THIRTY_MIN else currentTimeFrame;
def availableM30 = currentTimeFrame <= aggregationPeriod.THIRTY_MIN;
def hiDiffM30 = high(period = aM30) - high(period = aM30)[1];
def loDiffM30 = low(period = aM30)[1] - low(period = aM30);

def plusDMM30 = if hiDiffM30 > loDiffM30 and hiDiffM30 > 0 then hiDiffM30 else 0;
def minusDMM30 =  if loDiffM30 > hiDiffM30 and loDiffM30 > 0 then loDiffM30 else 0;

def ATRM30 = MovingAverage(averageType, TrueRange(high(period = aM30), close(period = aM30), low(period = aM30)), length);
def "DI+M30" = 100 * MovingAverage(averageType, plusDMM30, length) / ATRM30;
def "DI-M30" = 100 * MovingAverage(averageType, minusDMM30, length) / ATRM30;

def DXM30 = if ("DI+M30" + "DI-M30" > 0) then 100 * AbsValue("DI+M30" - "DI-M30") / ("DI+M30" + "DI-M30") else 0;
def ADXM30 = MovingAverage(averageType, DXM30, length);

def bullishM30 = ("DI+M30" > "DI-M30") and (ADXM30 > adxlength);
def bearishM30 = ("DI+M30" < "DI-M30") and (ADXM30 > adxlength);
def sidewaysM30 = (ADXM30 < adxlength);

def sStateM30 =  if !availableM30 then Double.NaN else if bullishM30 then 100 else if bearishM30 then -100 else 0;
def sPOSM30 = if IsNan(sStateM30) then 0 else bullishM30;
def sNEGM30 = if IsNan(sStateM30) then 0 else bearishM30;
def sSIDM30 = if IsNan(sStateM30) then 0 else if sPOSM30 or sNEGM30 then 0 else sidewaysM30;

AddLabel(showlabels and show30MIN and availableM30, "30MIN", if IsNan(sStateM30) then COLOR.DARK_GRAY else
 if sStateM30 == 100 then GlobalColor("Bullish") else
 if sStateM30 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 10 - HOUR
def aH1 = if currentTimeFrame <= aggregationPeriod.HOUR then aggregationPeriod.HOUR else currentTimeFrame;
def availableH1 = currentTimeFrame <= aggregationPeriod.HOUR;
def hiDiffH1 = high(period = aH1) - high(period = aH1)[1];
def loDiffH1 = low(period = aH1)[1] - low(period = aH1);

def plusDMH1 = if hiDiffH1 > loDiffH1 and hiDiffH1 > 0 then hiDiffH1 else 0;
def minusDMH1 =  if loDiffH1 > hiDiffH1 and loDiffH1 > 0 then loDiffH1 else 0;

def ATRH1 = MovingAverage(averageType, TrueRange(high(period = aH1), close(period = aH1), low(period = aH1)), length);
def "DI+H1" = 100 * MovingAverage(averageType, plusDMH1, length) / ATRH1;
def "DI-H1" = 100 * MovingAverage(averageType, minusDMH1, length) / ATRH1;

def DXH1 = if ("DI+H1" + "DI-H1" > 0) then 100 * AbsValue("DI+H1" - "DI-H1") / ("DI+H1" + "DI-H1") else 0;
def ADXH1 = MovingAverage(averageType, DXH1, length);

def bullishH1 = ("DI+H1" > "DI-H1") and (ADXH1 > adxlength);
def bearishH1 = ("DI+H1" < "DI-H1") and (ADXH1 > adxlength);
def sidewaysH1 = (ADXH1 < adxlength);

def sStateH1 =  if !availableH1 then Double.NaN else if bullishH1 then 100 else if bearishH1 then -100 else 0;
def sPOSH1 = if IsNan(sStateH1) then 0 else bullishH1;
def sNEGH1 = if IsNan(sStateH1) then 0 else bearishH1;
def sSIDH1 = if IsNan(sStateH1) then 0 else if sPOSH1 or sNEGH1 then 0 else sidewaysH1;

AddLabel(showlabels and show1HOUR and availableH1, "1HOUR", if IsNan(sStateH1) then COLOR.DARK_GRAY else
 if sStateH1 == 100 then GlobalColor("Bullish") else
 if sStateH1 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 11 - TWO HOURS
def aH2 = if currentTimeFrame <= aggregationPeriod.TWO_HOURS then aggregationPeriod.TWO_HOURS else currentTimeFrame;
def availableH2 = currentTimeFrame <= aggregationPeriod.TWO_HOURS;
def hiDiffH2 = high(period = aH2) - high(period = aH2)[1];
def loDiffH2 = low(period = aH2)[1] - low(period = aH2);

def plusDMH2 = if hiDiffH2 > loDiffH2 and hiDiffH2 > 0 then hiDiffH2 else 0;
def minusDMH2 =  if loDiffH2 > hiDiffH2 and loDiffH2 > 0 then loDiffH2 else 0;

def ATRH2 = MovingAverage(averageType, TrueRange(high(period = aH2), close(period = aH2), low(period = aH2)), length);
def "DI+H2" = 100 * MovingAverage(averageType, plusDMH2, length) / ATRH2;
def "DI-H2" = 100 * MovingAverage(averageType, minusDMH2, length) / ATRH2;

def DXH2 = if ("DI+H2" + "DI-H2" > 0) then 100 * AbsValue("DI+H2" - "DI-H2") / ("DI+H2" + "DI-H2") else 0;
def ADXH2 = MovingAverage(averageType, DXH2, length);

def bullishH2 = ("DI+H2" > "DI-H2") and (ADXH2 > adxlength);
def bearishH2 = ("DI+H2" < "DI-H2") and (ADXH2 > adxlength);
def sidewaysH2 = (ADXH2 < adxlength);

def sStateH2 =  if !availableH2 then Double.NaN else if bullishH2 then 100 else if bearishH2 then -100 else 0;
def sPOSH2 = if IsNan(sStateH2) then 0 else bullishH2;
def sNEGH2 = if IsNan(sStateH2) then 0 else bearishH2;
def sSIDH2 = if IsNan(sStateH2) then 0 else if sPOSH2 or sNEGH2 then 0 else sidewaysH2;

AddLabel(showlabels and show2HOUR and availableH2, "2HOUR", if IsNan(sStateH2) then COLOR.DARK_GRAY else
 if sStateH2 == 100 then GlobalColor("Bullish") else
 if sStateH2 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 12 - FOUR HOURS
def aH4 = if currentTimeFrame <= aggregationPeriod.FOUR_HOURS then aggregationPeriod.FOUR_HOURS else currentTimeFrame;
def availableH4 = currentTimeFrame <= aggregationPeriod.FOUR_HOURS;
def hiDiffH4 = high(period = aH4) - high(period = aH4)[1];
def loDiffH4 = low(period = aH4)[1] - low(period = aH4);

def plusDMH4 = if hiDiffH4 > loDiffH4 and hiDiffH4 > 0 then hiDiffH4 else 0;
def minusDMH4 =  if loDiffH4 > hiDiffH4 and loDiffH4 > 0 then loDiffH4 else 0;

def ATRH4 = MovingAverage(averageType, TrueRange(high(period = aH4), close(period = aH4), low(period = aH4)), length);
def "DI+H4" = 100 * MovingAverage(averageType, plusDMH4, length) / ATRH4;
def "DI-H4" = 100 * MovingAverage(averageType, minusDMH4, length) / ATRH4;

def DXH4 = if ("DI+H4" + "DI-H4" > 0) then 100 * AbsValue("DI+H4" - "DI-H4") / ("DI+H4" + "DI-H4") else 0;
def ADXH4 = MovingAverage(averageType, DXH4, length);

def bullishH4 = ("DI+H4" > "DI-H4") and (ADXH4 > adxlength);
def bearishH4 = ("DI+H4" < "DI-H4") and (ADXH4 > adxlength);
def sidewaysH4 = (ADXH4 < adxlength);

def sStateH4 =  if !availableH4 then Double.NaN else if bullishH4 then 100 else if bearishH4 then -100 else 0;
def sPOSH4 = if IsNan(sStateH4) then 0 else bullishH4;
def sNEGH4 = if IsNan(sStateH4) then 0 else bearishH4;
def sSIDH4 = if IsNan(sStateH4) then 0 else if sPOSH4 or sNEGH4 then 0 else sidewaysH4;

AddLabel(showlabels and show4HOUR and availableH4, "4HOUR", if IsNan(sStateH4) then COLOR.DARK_GRAY else
 if sStateH4 == 100 then GlobalColor("Bullish") else
 if sStateH4 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 13 - ONE DAY
def aD1 = if currentTimeFrame <= aggregationPeriod.DAY then aggregationPeriod.DAY else currentTimeFrame;
def availableD1 = currentTimeFrame <= aggregationPeriod.DAY;
def hiDiffD1 = high(period = aD1) - high(period = aD1)[1];
def loDiffD1 = low(period = aD1)[1] - low(period = aD1);

def plusDMD1 = if hiDiffD1 > loDiffD1 and hiDiffD1 > 0 then hiDiffD1 else 0;
def minusDMD1 =  if loDiffD1 > hiDiffD1 and loDiffD1 > 0 then loDiffD1 else 0;

def ATRD1 = MovingAverage(averageType, TrueRange(high(period = aD1), close(period = aD1), low(period = aD1)), length);
def "DI+D1" = 100 * MovingAverage(averageType, plusDMD1, length) / ATRD1;
def "DI-D1" = 100 * MovingAverage(averageType, minusDMD1, length) / ATRD1;

def DXD1 = if ("DI+D1" + "DI-D1" > 0) then 100 * AbsValue("DI+D1" - "DI-D1") / ("DI+D1" + "DI-D1") else 0;
def ADXD1 = MovingAverage(averageType, DXD1, length);

def bullishD1 = ("DI+D1" > "DI-D1") and (ADXD1 > adxlength);
def bearishD1 = ("DI+D1" < "DI-D1") and (ADXD1 > adxlength);
def sidewaysD1 = (ADXD1 < adxlength);

def sStateD1 =  if !availableD1 then Double.NaN else if bullishD1 then 100 else if bearishD1 then -100 else 0;
def sPOSD1 = if IsNan(sStateD1) then 0 else bullishD1;
def sNEGD1 = if IsNan(sStateD1) then 0 else bearishD1;
def sSIDD1 = if IsNan(sStateD1) then 0 else if sPOSD1 or sNEGD1 then 0 else sidewaysD1;

AddLabel(showlabels and show1DAY and availableD1, "1DAY", if IsNan(sStateD1) then COLOR.DARK_GRAY else
 if sStateD1 == 100 then GlobalColor("Bullish") else
 if sStateD1 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 14 - TWO DAYS
def aD2 = if currentTimeFrame <= aggregationPeriod.TWO_DAYS then aggregationPeriod.TWO_DAYS else currentTimeFrame;
def availableD2 = currentTimeFrame <= aggregationPeriod.TWO_DAYS;
def hiDiffD2 = high(period = aD2) - high(period = aD2)[1];
def loDiffD2 = low(period = aD2)[1] - low(period = aD2);

def plusDMD2 = if hiDiffD2 > loDiffD2 and hiDiffD2 > 0 then hiDiffD2 else 0;
def minusDMD2 =  if loDiffD2 > hiDiffD2 and loDiffD2 > 0 then loDiffD2 else 0;

def ATRD2 = MovingAverage(averageType, TrueRange(high(period = aD2), close(period = aD2), low(period = aD2)), length);
def "DI+D2" = 100 * MovingAverage(averageType, plusDMD2, length) / ATRD2;
def "DI-D2" = 100 * MovingAverage(averageType, minusDMD2, length) / ATRD2;

def DXD2 = if ("DI+D2" + "DI-D2" > 0) then 100 * AbsValue("DI+D2" - "DI-D2") / ("DI+D2" + "DI-D2") else 0;
def ADXD2 = MovingAverage(averageType, DXD2, length);

def bullishD2 = ("DI+D2" > "DI-D2") and (ADXD2 > adxlength);
def bearishD2 = ("DI+D2" < "DI-D2") and (ADXD2 > adxlength);
def sidewaysD2 = (ADXD2 < adxlength);

def sStateD2 =  if !availableD2 then Double.NaN else if bullishD2 then 100 else if bearishD2 then -100 else 0;
def sPOSD2 = if IsNan(sStateD2) then 0 else bullishD2;
def sNEGD2 = if IsNan(sStateD2) then 0 else bearishD2;
def sSIDD2 = if IsNan(sStateD2) then 0 else if sPOSD2 or sNEGD2 then 0 else sidewaysD2;

AddLabel(showlabels and show2DAY and availableD2, "2DAY", if IsNan(sStateD2) then COLOR.DARK_GRAY else
 if sStateD2 == 100 then GlobalColor("Bullish") else
 if sStateD2 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 15 - THREE DAYS
def aD3 = if currentTimeFrame <= aggregationPeriod.THREE_DAYS then aggregationPeriod.THREE_DAYS else currentTimeFrame;
def availableD3 = currentTimeFrame <= aggregationPeriod.THREE_DAYS;
def hiDiffD3 = high(period = aD3) - high(period = aD3)[1];
def loDiffD3 = low(period = aD3)[1] - low(period = aD3);

def plusDMD3 = if hiDiffD3 > loDiffD3 and hiDiffD3 > 0 then hiDiffD3 else 0;
def minusDMD3 =  if loDiffD3 > hiDiffD3 and loDiffD3 > 0 then loDiffD3 else 0;

def ATRD3 = MovingAverage(averageType, TrueRange(high(period = aD3), close(period = aD3), low(period = aD3)), length);
def "DI+D3" = 100 * MovingAverage(averageType, plusDMD3, length) / ATRD3;
def "DI-D3" = 100 * MovingAverage(averageType, minusDMD3, length) / ATRD3;

def DXD3 = if ("DI+D3" + "DI-D3" > 0) then 100 * AbsValue("DI+D3" - "DI-D3") / ("DI+D3" + "DI-D3") else 0;
def ADXD3 = MovingAverage(averageType, DXD3, length);

def bullishD3 = ("DI+D3" > "DI-D3") and (ADXD3 > adxlength);
def bearishD3 = ("DI+D3" < "DI-D3") and (ADXD3 > adxlength);
def sidewaysD3 = (ADXD3 < adxlength);

def sStateD3 =  if !availableD3 then Double.NaN else if bullishD3 then 100 else if bearishD3 then -100 else 0;
def sPOSD3 = if IsNan(sStateD3) then 0 else bullishD3;
def sNEGD3 = if IsNan(sStateD3) then 0 else bearishD3;
def sSIDD3 = if IsNan(sStateD3) then 0 else if sPOSD3 or sNEGD3 then 0 else sidewaysD3;

AddLabel(showlabels and show3DAY and availableD3, "3DAY", if IsNan(sStateD3) then COLOR.DARK_GRAY else
 if sStateD3 == 100 then GlobalColor("Bullish") else
 if sStateD3 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 16 - FOUR DAYS
def aD4 = if currentTimeFrame <= aggregationPeriod.FOUR_DAYS then aggregationPeriod.FOUR_DAYS else currentTimeFrame;
def availableD4 = currentTimeFrame <= aggregationPeriod.FOUR_DAYS;
def hiDiffD4 = high(period = aD4) - high(period = aD4)[1];
def loDiffD4 = low(period = aD4)[1] - low(period = aD4);

def plusDMD4 = if hiDiffD4 > loDiffD4 and hiDiffD4 > 0 then hiDiffD4 else 0;
def minusDMD4 =  if loDiffD4 > hiDiffD4 and loDiffD4 > 0 then loDiffD4 else 0;

def ATRD4 = MovingAverage(averageType, TrueRange(high(period = aD4), close(period = aD4), low(period = aD4)), length);
def "DI+D4" = 100 * MovingAverage(averageType, plusDMD4, length) / ATRD4;
def "DI-D4" = 100 * MovingAverage(averageType, minusDMD4, length) / ATRD4;

def DXD4 = if ("DI+D4" + "DI-D4" > 0) then 100 * AbsValue("DI+D4" - "DI-D4") / ("DI+D4" + "DI-D4") else 0;
def ADXD4 = MovingAverage(averageType, DXD4, length);

def bullishD4 = ("DI+D4" > "DI-D4") and (ADXD4 > adxlength);
def bearishD4 = ("DI+D4" < "DI-D4") and (ADXD4 > adxlength);
def sidewaysD4 = (ADXD4 < adxlength);

def sStateD4 =  if !availableD4 then Double.NaN else if bullishD4 then 100 else if bearishD4 then -100 else 0;
def sPOSD4 = if IsNan(sStateD4) then 0 else bullishD4;
def sNEGD4 = if IsNan(sStateD4) then 0 else bearishD4;
def sSIDD4 = if IsNan(sStateD4) then 0 else if sPOSD4 or sNEGD4 then 0 else sidewaysD4;

AddLabel(showlabels and show4DAY and availableD4, "4DAY", if IsNan(sStateD4) then COLOR.DARK_GRAY else
 if sStateD4 == 100 then GlobalColor("Bullish") else
 if sStateD4 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 17 - ONE WEEK
def aW1 = if currentTimeFrame <= aggregationPeriod.WEEK then aggregationPeriod.WEEK else currentTimeFrame;
def availableW1 = currentTimeFrame <= aggregationPeriod.WEEK;
def hiDiffW1 = high(period = aW1) - high(period = aW1)[1];
def loDiffW1 = low(period = aW1)[1] - low(period = aW1);

def plusDMW1 = if hiDiffW1 > loDiffW1 and hiDiffW1 > 0 then hiDiffW1 else 0;
def minusDMW1 =  if loDiffW1 > hiDiffW1 and loDiffW1 > 0 then loDiffW1 else 0;

def ATRW1 = MovingAverage(averageType, TrueRange(high(period = aW1), close(period = aW1), low(period = aW1)), length);
def "DI+W1" = 100 * MovingAverage(averageType, plusDMW1, length) / ATRW1;
def "DI-W1" = 100 * MovingAverage(averageType, minusDMW1, length) / ATRW1;

def DXW1 = if ("DI+W1" + "DI-W1" > 0) then 100 * AbsValue("DI+W1" - "DI-W1") / ("DI+W1" + "DI-W1") else 0;
def ADXW1 = MovingAverage(averageType, DXW1, length);

def bullishW1 = ("DI+W1" > "DI-W1") and (ADXW1 > adxlength);
def bearishW1 = ("DI+W1" < "DI-W1") and (ADXW1 > adxlength);
def sidewaysW1 = (ADXW1 < adxlength);

def sStateW1 =  if !availableW1 then Double.NaN else if bullishW1 then 100 else if bearishW1 then -100 else 0;
def sPOSW1 = if IsNan(sStateW1) then 0 else bullishW1;
def sNEGW1 = if IsNan(sStateW1) then 0 else bearishW1;
def sSIDW1 = if IsNan(sStateW1) then 0 else if sPOSW1 or sNEGW1 then 0 else sidewaysW1;

AddLabel(showlabels and showWEEK and availableW1, "WEEK", if IsNan(sStateW1) then COLOR.DARK_GRAY else
 if sStateW1 == 100 then GlobalColor("Bullish") else
 if sStateW1 == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));


# AGGREGATION 18 - ONE MONTH
def aMM = if currentTimeFrame <= aggregationPeriod.MONTH then aggregationPeriod.MONTH else currentTimeFrame;
def availableMM = currentTimeFrame <= aggregationPeriod.MONTH;
def hiDiffMM = high(period = aMM) - high(period = aMM)[1];
def loDiffMM = low(period = aMM)[1] - low(period = aMM);

def plusDMMM = if hiDiffMM > loDiffMM and hiDiffMM > 0 then hiDiffMM else 0;
def minusDMMM =  if loDiffMM > hiDiffMM and loDiffMM > 0 then loDiffMM else 0;

def ATRMM = MovingAverage(averageType, TrueRange(high(period = aMM), close(period = aMM), low(period = aMM)), length);
def "DI+MM" = 100 * MovingAverage(averageType, plusDMMM, length) / ATRMM;
def "DI-MM" = 100 * MovingAverage(averageType, minusDMMM, length) / ATRMM;

def DXMM = if ("DI+MM" + "DI-MM" > 0) then 100 * AbsValue("DI+MM" - "DI-MM") / ("DI+MM" + "DI-MM") else 0;
def ADXMM = MovingAverage(averageType, DXMM, length);

def bullishMM = ("DI+MM" > "DI-MM") and (ADXMM > adxlength);
def bearishMM = ("DI+MM" < "DI-MM") and (ADXMM > adxlength);
def sidewaysMM = (ADXMM < adxlength);

def sStateMM =  if !availableMM then Double.NaN else if bullishMM then 100 else if bearishMM then -100 else 0;
def sPOSMM = if IsNan(sStateMM) then 0 else bullishMM;
def sNEGMM = if IsNan(sStateMM) then 0 else bearishMM;
def sSIDMM = if IsNan(sStateMM) then 0 else if sPOSMM or sNEGMM then 0 else sidewaysMM;

AddLabel(showlabels and showMONTH and availableMM, "MONTH", if IsNan(sStateMM) then COLOR.DARK_GRAY else
 if sStateMM == 100 then GlobalColor("Bullish") else
 if sStateMM == -100 then GlobalColor("Bearish")
 else GlobalColor("Neutral"));

#STATS
def sPOS = sPOSM1 + sPOSM2 + sPOSM3 + sPOSM4 + sPOSM5 + sPOSM10 + sPOSM15 +
 sPOSM20 + sPOSM30 + sPOSH1 + sPOSH2 + sPOSH4 + sPOSD1 + sPOSD2 + sPOSD3 +
 sPOSD4 + sPOSW1 + sPOSMM;

def sNEG = sNEGM1 + sNEGM2 + sNEGM3 + sNEGM4 + sNEGM5 + sNEGM10 + sNEGM15 +
 sNEGM20 + sNEGM30 + sNEGH1 + sNEGH2 + sNEGH4 + sNEGD1 + sNEGD2 + sNEGD3 +
 sNEGD4 + sNEGW1 + sNEGMM;

def sSID = sSIDM1 + sSIDM2 + sSIDM3 + sSIDM4 + sSIDM5 + sSIDM10 + sSIDM15 +
 sSIDM20 + sSIDM30 + sSIDH1 + sSIDH2 + sSIDH4 + sSIDD1 + sSIDD2 + sSIDD3 +
 sSIDD4 + sSIDW1 + sSIDMM;

def sTOL = sPOS + sNEG + sSID;

AddLabel (showstats, "Bullish: " + sPOS + " (" +
  AsPercent(Round(sPOS / sTOL, 2)) + ")", GlobalColor("Bullish"));

AddLabel (showstats, "Bearish: " + sNEG + " (" +
  AsPercent(Round(sNEG / sTOL, 2)) + ")", GlobalColor("Bearish"));

AddLabel (showstats, "Neutral: " + sSID + " (" +
  AsPercent(Round(sSID / sTOL, 2)) + ")", GlobalColor("Neutral"));


# END OF Visual DMI (The 10x Bars) MTF Labels for ThinkorSwim
 
Is there a way to make this work for whatever candle you're scrolling on in the past? Could help backtest it.
 

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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