# Tea 2.0 - Market Cycle Indicator

#### farresa

##### New member
VIP
There are generally 4 phases to a full market cycle, at least the way I was taught. Accumulation Phase, Mark up(Acceleration) Phase, Distribution Phase, and Mark down(de-acceleration) Phase. I recently came across an indicator that does a pretty good job of identifying the phases of a market but I need it altered for how I want to use it and don't have the knowledge or skills to do it myself. Here is the code for those who may want to use it as well as alter it.

Code:
``````# TEA 2.0 - TOS version - 2015-06-04
# From Andrew Falde's work - LessThanRandom.com
# Converted from TradeStation to TOS by John Chernicky

#Hint: TEA 2.0 by Andrew Falde at LessThanRandom.com

declare lower;
input Period = 21; # Bars for Price Analysis
#Hint Period: Period in number of bars.
def Price = close; # Use closing price for calculaltion
input Author = "Andrew Falde - LessThanRandom.com";

# Expansion Calculation
def ATR = reference ATR(Period, averageType = AverageType.SIMPLE);
def StdDev = StDev(data = Price, length = Period);
def squeeze = (ATR * .75) - StdDev;
def Expansion = If (squeeze < 0, 1, 0);

# Linear Regression
def lowest = Lowest(low[1], Period);
def highest = Highest(high[1], Period);
def EMA = ExpAverage(Price, Period);
def Resolve = Price - ((highest + lowest) / 2 + EMA) / 2;
def Trendline = LinearRegCurve(0, Period, Resolve);

# Trend Calculation
# 1 - Accumulation
# 2 - Mark Up
# 3 - Distribution
# 4 - Mark Down
# 0 - No Trend
def Trend = if Trendline <= 0 and Trendline > Trendline[1] then 1 else (
if Trendline > 0 and Trendline > Trendline[1] then 2 else (
if Trendline > 0 and Trendline < Trendline[1] then 3 else (
if Trendline <= 0 and Trendline < Trendline[1] then 4 else (
Double.NaN))));

plot TEA =
(if Trend == 1 then -1
else (if Trend == 2 then 1
else (if Trend == 3 then 1
else (if Trend == 4 then -1 else Double.NaN
))));

plot Consolidated = (if Expansion == 0 then 0 else Double.NaN);

TEA.AssignValueColor
(if Trend == 1 then Color.DARK_RED
else (if Trend == 2 then Color.GREEN
else (if Trend == 3 then Color.DARK_GREEN
else (if Trend == 4 then Color.RED else Color.DARK_GRAY
))));

TEA.SetPaintingStrategy(PaintingStrategy.POINTS);
TEA.SetLineWeight(4);
#TEA.HideTitle();
TEA.HideBubble();

Consolidated.AssignValueColor(Color.BLUE);
Consolidated.SetPaintingStrategy(PaintingStrategy.POINTS);
Consolidated.SetLineWeight(4);
#Consolidated.HideTitle();
Consolidated.HideBubble();

I found it at https://www.smbtraining.com/blog/tea-2-0-indicator

This script terms it trend calculations! It is a lower study which is a pain at least for me. I would like to see the points(dots) for phases 1 accumulation and markup be under the price bars offset a little bit and the distribution and markdown phases be points(dots) above the price bars offset a little bit. The consolidation I don't need so I could comment that out. I can also change the colors in the code so that is no problem but I have tried for 2 days to alter this code and I have always come right back to square one. If anyone will help it is much appreciated.

#### young_and_dumb

##### New member
VIP
Having issues with the code- but haven't had my coffee yet-can you post a TOS share link with what you have working right now?
Cheers

#### RickAns

##### Active member
Interesting indicator, thanks for posting. I do not have a dot plotting solution on the main chart for you at the moment. But I do have a temporary solution so you do not have to keep referencing a lower panel.

Labels on the main chart if interested. Reference out the declare lower line and add in at the end of the code. Uncheck the show plots for TEA and Consolidated from setup. As you said you are comfortable changing the colors about. I changed the dark red on Accumulation to orange for my easy at a glance color separation.

Code:
``````AddLabel(yes, if Trend == 1 then "Accumulation" else "", Color.Orange);
AddLabel(yes, if Trend == 2 then "Mark Up" else "", Color.Green);
AddLabel(yes, if Trend == 3 then "Distribution" else "", Color.Dark_Green);
AddLabel(yes, if Trend == 4 then "Market Down" else "", Color.Red);
AddLabel(yes, if Expansion == 0 then "Volatility Consolidation" else "", Color.Blue);``````

I found you can use Boolean_Arrow_Up or Boolean_Wedge_Up in addition to arrow / wedge_down to plot on the main chart above / below the price bar. Using a Boolean Point places a point on the close of the bar which does not sound like what you are after. Still need to remark out the declare lower.

Something like:

Code:
``````plot Accum = Trend == 1;
Accum.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Accum.AssignValueColor(Color.Orange);``````

Not ideal, but the best I have to offer at the moment. Maybe someone else chime in with a better solution.

Last edited:

#### farresa

##### New member
VIP
@young_and_dumb Here is the share link from smb site that this came from. http://tos.mx/DUZDmM This will be the same as what I copied and posted above unless I missed something in that process. I am not a coder so what I download is what works for me. I spent 2 days trying to hack at this and cobble something together but could get nothing to work. Therefore I had to request some help. Thank you for what your trying to do! Much appreciated!!!!

@RickAns Thanks for your efforts I will try and see if I can get the arrow/wedge up and down to work for me. Much appreciated !!!

#### henry1224

##### Active member
VIP
Here is TEA combined with Trend ADvisor Diamond Phase. If you set the APC input to 1, you will paint the bars for the Trend Advisor, set the APC input to 2 you will paint the bars to the TEA Indicator. The Trend Advisor are in Histogram, TEA are set as points.

Code:
``````Declare Lower;
Input Length1 = 50;
Input Length2 = 200;
input Period = 21; # Bars for Price Analysis TEA
Input APC = 0;
Def Price= Close;
Def ML1=Average(Price,Length1);
Def ML2=Average(Price,Length2);
Plot RecP = If (ML1 < ML2 AND Price < ML2 AND Price > ML1) then 1 else 0;
Plot WarnP = If(ML1 > ML2 AND Price > ML2 AND Price < ML1) then -1 Else 0;
Plot AcumP = If(ML1 < ML2 AND Price > ML2 AND Price > ML1) Then 2 Else 0;
Plot DispP = If(ML1 > ML2 AND Price < ML2 AND Price < ML1) then -2 else 0;
Plot BullP = If(ML1 > ML2 AND Price > ML2 AND Price > ML1) then 3 else 0;
Plot BearP = If(ML1 < ML2 AND Price < ML2 AND Price < ML1)then -3 else 0;
RecP.SetPaintingStrategy(PaintingStrategy.Histogram);
RecP.SetDefaultColor(Color.Light_Green);
WarnP.SetPaintingStrategy(PaintingStrategy.Histogram);
WarnP.SetDefaultColor(Color.Orange);
AcumP.SetPaintingStrategy(PaintingStrategy.Histogram);
AcumP.SetDefaultColor(Color. Green);
DispP.SetPaintingStrategy(PaintingStrategy.Histogram);
DispP.SetDefaultColor(Color.Red);
BullP.SetPaintingStrategy(PaintingStrategy.Histogram);
BullP.SetDefaultColor(Color.Dark_Green);
BearP.SetPaintingStrategy(PaintingStrategy.Histogram);
BearP.SetDefaultColor(Color.Dark_Red);
Plot Zeroline=0;
ZeroLine.SetDefaultColor(GetColor(7));
# Expansion Calculation
def ATR = reference ATR(Period, averageType = AverageType.SIMPLE);
def StdDev = StDev(data = Price, length = Period);
def squeeze = (ATR * .75) - StdDev;
def Expansion = If (squeeze < 0, 1, 0);

# Linear Regression
def lowest = Lowest(low[1], Period);
def highest = Highest(high[1], Period);
def EMA = ExpAverage(Price, Period);
def Resolve = Price - ((highest + lowest) / 2 + EMA) / 2;
def Trendline = LinearRegCurve(0, Period, Resolve);

# Trend Caclulation
# 1 - Accumulation
# 2 - Mark Up
# 3 - Distribution
# 4 - Mark Down
# 0 - No Trend
def Trend = if Trendline <= 0 and Trendline > Trendline[1] then 1 else (
if Trendline > 0 and Trendline > Trendline[1] then 2 else (
if Trendline > 0 and Trendline < Trendline[1] then 3 else (
if Trendline <= 0 and Trendline < Trendline[1] then 4 else (
Double.NaN))));

plot TEA =
(if Trend == 1 then -4
else (if Trend == 2 then 4
else (if Trend == 3 then 4
else (if Trend == 4 then -4 else Double.NaN
))));

plot Consolidated = (if Expansion == 0 then 0 else Double.NaN);

TEA.AssignValueColor
(if Trend == 1 then Color.DARK_RED
else (if Trend == 2 then Color.GREEN
else (if Trend == 3 then Color.DARK_GREEN
else (if Trend == 4 then Color.RED else Color.DARK_GRAY
))));

TEA.SetPaintingStrategy(PaintingStrategy.POINTS);
TEA.SetLineWeight(4);
#TEA.HideTitle();
TEA.HideBubble();

Consolidated.AssignValueColor(Color.BLUE);
Consolidated.SetPaintingStrategy(PaintingStrategy.POINTS);
Consolidated.SetLineWeight(4);
#Consolidated.HideTitle();
Consolidated.HideBubble();
AssignPriceColor( if APC == 1 and RecP == 1 then Color.Light_Green else if APC == 1 and WarnP == -1 then Color.Orange else if APC == 1 and AcumP == 2 then Color.Green else if APC == 1 and DispP == -2 then Color.Red else if APC ==1 and BullP ==3 then Color.Dark_Green else if  apc == 1 and BearP == -3 then Color.DarK_Red  Else if APC ==2 and Trend == 1 then Color.Dark_Red else if APC == 2 and Trend == 2 then color.Green else if APC==2 and Trend == 3 then Color.Dark_Green else if APC ==2 and Trend ==4 then Color.Red else Color.Current);``````

#### farresa

##### New member
VIP
@henry1224 I was thinking that there might be something more that needed to be added to better qualify the plots for the TEA. This might be it, looking forward to seeing it on a chart. Thank you!!

@cabe1332 I will put this on a chart this evening as well. Got some work to do! Thank you, much appreciated!!!

Going to be a busy evening!!!

#### henry1224

##### Active member
VIP
@henry1224 I was thinking that there might be something more that needed to be added to better qualify the plots for the TEA. This might be it, looking forward to seeing it on a chart. Thank you!!

@cabe1332 I will put this on a chart this evening as well. Got some work to do! Thank you, much appreciated!!!

Going to be a busy evening!!!
TEA & Trend Advisor both show Market Phases. Trend Advisor uses the Close, 50 SMA & 200 SMA to determine which phase we are in. Tea shows contraction "Blue Dots" along the zero line.

I added the 2 indicators together and spaced the TEA lines. I then added the ability to paint the bars.

#### cabe1332

##### Active member
@henry1224 I was thinking that there might be something more that needed to be added to better qualify the plots for the TEA. This might be it, looking forward to seeing it on a chart. Thank you!!

@cabe1332 I will put this on a chart this evening as well. Got some work to do! Thank you, much appreciated!!!

Going to be a busy evening!!!

Hey @farresa, how did the code work for you?

#### henry1224

##### Active member
VIP
Try this

Code:
``````#From the book New Trading Dimensions by Bill Willams, PhD
#Coded by Henry Z Kaczmarczyk 01/2021
# TEA 2.0 - TOS version - 2015-06-04
# From Andrew Falde's work - LessThanRandom.com
# Converted from TradeStation to TOS by John Chernicky
#Hint: TEA 2.0 by Andrew Falde at LessThanRandom.com
#Trend Advisor Diamond Phase by Chuck Dukas , Coded by Henry Z Kaczmarczyk
#Trend Advisor Line 1 is current Time Frame. Line 2 is next higher Time Frame. Line 3 is second higher time frame.
#Trend Advisor is shown as Squares Compares Close to the 50 & 200 SMA
#Recovery Phase is Light Green
#Warning Phase is Orange
#Accumulation Phase is Green
#Dispersition Phase is Red
#Bullish Phase is Dark_Green
#Bearish Phase is Dark_Red
#TEA v 2.0 are shown as Points on lines 0,5 TEAB First Higher Time frame Lines 6, TEAC second higher Time frame Lines 7
#Consolidation is shown as Blue Points on the zero line
# Trend Caclulation
# 1 - Accumulation color Dark_Red
# 2 - Mark Up Color Green
# 3 - Distribution Color Dark_Green
# 4 - Mark Down Color Red
# 0 - No Trend
# Bill Williams Zone Bars are shown as Triangles in 3 Different Time Frames
#Green Triangles show when the Awesome Oscillator & AccelerationBands Osc are Bullish
#Red Triangles show when the Awesome Oscillator & AccelerationBands Osc are Bearish
#Blue Triangles show when the Awesome Oscillator & AccelerationBands Osc are Neutral
#Line 9 is then current Time Frame, Line 10 is then next higher time frame, Line 11 is the second higher Time Frame
#SquatBars are shown as Squares on Lines 13,14,15. Line 10 is the currentRatio Time Frame, Line 13 is the next Higher Time Frame, Line 14 is the secondsFromTime Higher Time Frame.
#GreenBars are green and are Bullish
#Squat Bars are Blue and show trend reversal at the end of Trends
#Fade Bars are Red and are Bearish
#FakeBars are Orange
#APC = 1 thru 3 will paint bars for Trend Advisor
#APC = 5 thru 7 will paint bars for TEA v2.0
#APC = 9 thru 11 will paint bars for Zone Bars
#APC = 13 thru 15 will Paint Bars for Squat Bars
Declare Lower;
DefineGlobalColor("GreenZone",Color.Green);
DefineGlobalColor("RedZone",Color.Red);
DefineGlobalColor("Neutral",Color.Blue);
DefineGlobalColor("Greenbar", Color.Green);
DefineGlobalColor("Squatbar", Color.Blue);
DefineGlobalColor("Fakebar", Color.Orange);
DefineGlobalColor("Zero", Color.Gray);
input agg1 = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.THIRTY_MIN;
input agg3 = AggregationPeriod.HOUR;
Input apc = 5;
Input DotSize = 3;
Input Length1 = 50;
Input Length2 = 200;
input Period = 21; # Bars for Price Analysis TEA
Def Price1 = HL2(Period = agg1);
Def Price2 = HL2(Period = agg2);
Def Price3 = HL2(Period = agg3);
Def Vol1 = Volume(Period = agg1);
Def Vol2 = Volume(Period = agg2);
Def Vol3 = Volume(Period = agg3);
Def H1 = High(Period = agg1);
Def H2 = High(Period = agg2);
Def H3 = High(Period = agg3);
Def L1 = Low(Period = agg1);
Def L2 = Low(Period = agg2);
Def L3 = Low(Period = agg3);
Def C1 = Close(Period = agg1);
Def C2 = Close(Period = agg2);
Def C3 = Close(Period = agg3);

Def ML1=Average(C1,Length1);
Def ML2=Average(C1,Length2);
Def BML1=Average(C2,Length1);
Def BML2=Average(C2,Length2);
Def CML1=Average(C3,Length1);
Def CML2=Average(C3,Length2);
Plot RecP = If (ML1 < ML2 AND C1 < ML2 AND C1 > ML1) then 1 else Double.Nan;
Plot WarnP = If(ML1 > ML2 AND C1 > ML2 AND C1 < ML1) then 1 Else Double.Nan;
Plot AcumP = If(ML1 < ML2 AND C1 > ML2 AND C1 > ML1) Then 1 Else Double.Nan;
Plot DispP = If(ML1 > ML2 AND C1 < ML2 AND C1 < ML1) then 1 else Double.Nan;
Plot BullP = If(ML1 > ML2 AND C1 > ML2 AND C1 > ML1) then 1 else Double.Nan;
Plot BearP = If(ML1 < ML2 AND C1 < ML2 AND C1 < ML1) then 1 else Double.Nan;
RecP.SetPaintingStrategy(PaintingStrategy.Squares);
RecP.SetDefaultColor(Color.Light_Green);
RecP.SetLineWeight(DotSize);
WarnP.SetPaintingStrategy(PaintingStrategy.Squares);
WarnP.SetDefaultColor(Color.Orange);
WarnP.SetLineWeight(DotSize);
AcumP.SetPaintingStrategy(PaintingStrategy.Squares);
AcumP.SetDefaultColor(Color. Green);
AcumP.SetLineWeight(DotSize);
DispP.SetPaintingStrategy(PaintingStrategy.Squares);
DispP.SetDefaultColor(Color.Red);
DispP.SetLineWeight(DotSize);
BullP.SetPaintingStrategy(PaintingStrategy.Squares);
BullP.SetDefaultColor(Color.Dark_Green);
BullP.SetLineWeight(DotSize);
BearP.SetPaintingStrategy(PaintingStrategy.Squares);
BearP.SetDefaultColor(Color.Dark_Red);
BearP.SetLineWeight(DotSize);

Plot RecPB = If (BML1 < BML2 AND C2 < BML2 AND C2 > BML1) then 2 else Double.Nan;
Plot WarnPB = If(BML1 > BML2 AND C2 > BML2 AND C2 < BML1) then 2 Else Double.Nan;
Plot AcumPB = If(BML1 < BML2 AND C2 > BML2 AND C2 > BML1) Then 2 Else Double.Nan;
Plot DispPB = If(BML1 > BML2 AND C2 < BML2 AND C2 < BML1) then 2 else Double.Nan;
Plot BullPB = If(BML1 > BML2 AND C2 > BML2 AND C2 > BML1) then 2 else Double.Nan;
Plot BearPB = If(BML1 < BML2 AND C2 < BML2 AND C2 < BML1) then 2 else Double.Nan;
RecPB.SetPaintingStrategy(PaintingStrategy.Squares);
RecPB.SetDefaultColor(Color.Light_Green);
RecPB.SetLineWeight(DotSize);
WarnPB.SetPaintingStrategy(PaintingStrategy.Squares);
WarnPB.SetDefaultColor(Color.Orange);
WarnPB.SetLineWeight(DotSize);
AcumPB.SetPaintingStrategy(PaintingStrategy.Squares);
AcumPB.SetDefaultColor(Color. Green);
AcumPB.SetLineWeight(DotSize);
DispPB.SetPaintingStrategy(PaintingStrategy.Squares);
DispPB.SetDefaultColor(Color.Red);
DispPB.SetLineWeight(DotSize);
BullPB.SetPaintingStrategy(PaintingStrategy.Squares);
BullPB.SetDefaultColor(Color.Dark_Green);
BullPB.SetLineWeight(DotSize);
BearPB.SetPaintingStrategy(PaintingStrategy.Squares);
BearPB.SetDefaultColor(Color.Dark_Red);
BearPb.SetLineWeight(DotSize);

Plot RecPC = If (CML1 < CML2 AND C3 < CML2 AND C3 > CML1) then 3 else Double.Nan;
Plot WarnPC = If(CML1 > CML2 AND C3 > BML2 AND C3 < CML1) then 3 Else Double.Nan;
Plot AcumPC = If(CML1 < CML2 AND C3 > BML2 AND C3 > CML1) Then 3 Else Double.Nan;
Plot DispPC = If(CML1 > CML2 AND C3 < BML2 AND C3 < CML1) then 3 else Double.Nan;
Plot BullPC = If(CML1 > CML2 AND C3 > BML2 AND C3 > CML1) then 3 else Double.Nan;
Plot BearPC = If(CML1 < CML2 AND C3 < BML2 AND C3 < CML1) then 3 else Double.Nan;
RecPC.SetPaintingStrategy(PaintingStrategy.Squares);
RecPC.SetDefaultColor(Color.Light_Green);
RecPC.SetLineWeight(DotSize);
WarnPC.SetPaintingStrategy(PaintingStrategy.Squares);
WarnPC.SetDefaultColor(Color.Orange);
WarnPC.SetLineWeight(DotSize);
AcumPC.SetPaintingStrategy(PaintingStrategy.Squares);
AcumPC.SetDefaultColor(Color. Green);
AcumPc.SetLineWeight(DotSize);
DispPC.SetPaintingStrategy(PaintingStrategy.Squares);
DispPC.SetDefaultColor(Color.Red);
DispPC.SetLineWeight(DotSize);
BullPC.SetPaintingStrategy(PaintingStrategy.Squares);
BullPC.SetDefaultColor(Color.Dark_Green);
BullPC.SetLineWeight(DotSize);
BearPC.SetPaintingStrategy(PaintingStrategy.Squares);
BearPC.SetDefaultColor(Color.Dark_Red);
BearPC.SetLineWeight(DotSize);
Plot Zeroline=0;
ZeroLine.SetDefaultColor(GetColor(7));
# Expansion Calculation
def ATR = reference ATR(Period, averageType = AverageType.SIMPLE);
def StdDev = StDev(data = Close, length = Period);
def squeeze = (ATR * .75) - StdDev;
def Expansion = If (squeeze < 0, 1, 0);

# Linear Regression

def lowest = Lowest(L1[1], Period);
def lowestB = Lowest(L2[1], Period);
def lowestC = Lowest(L3[1], Period);
def highest = Highest(H1[1], Period);
def highestB = Highest(H2[1], Period);
def highestC = Highest(H3[1], Period);
def EMA = ExpAverage(C1, Period);
def EMAB = ExpAverage(C2, Period);
def EMAC = ExpAverage(C3, Period);
def Resolve = C1 - ((highest + lowest) / 2 + EMA) / 2;
def ResolveB = C2 - ((highestB + lowestB) / 2 + EMAB) / 2;
def ResolveC = C3 - ((highestC + lowestC) / 2 + EMAC) / 2;
def Trendline = LinearRegCurve(0, Period, Resolve);
def TrendlineB = LinearRegCurve(0, Period, ResolveB);
def TrendlineC = LinearRegCurve(0, Period, ResolveC);

# Trend Caclulation
# 1 - Accumulation
# 2 - Mark Up
# 3 - Distribution
# 4 - Mark Down
# 0 - No Trend
def Trend = if Trendline <= 0 and Trendline > Trendline[1] then 1 else (
if Trendline > 0 and Trendline > Trendline[1] then 2 else (
if Trendline > 0 and Trendline < Trendline[1] then 3 else (
if Trendline <= 0 and Trendline < Trendline[1] then 4 else (
Double.NaN))));
def TrendB = if TrendlineB <= 0 and TrendlineB > TrendlineB[1] then 1 else (
if TrendlineB > 0 and TrendlineB > TrendlineB[1] then 2 else (
if TrendlineB > 0 and TrendlineB < TrendlineB[1] then 3 else (
if TrendlineB <= 0 and TrendlineB < TrendlineB[1] then 4 else (
Double.NaN))));
def TrendC = if TrendlineC <= 0 and TrendlineC > TrendlineC[1] then 1 else (
if TrendlineC > 0 and TrendlineC > TrendlineC[1] then 2 else (
if TrendlineC > 0 and TrendlineC < TrendlineC[1] then 3 else (
if TrendlineC <= 0 and TrendlineC < TrendlineC[1] then 4 else (
Double.NaN))));

plot TEA =
(if Trend == 1 then 5
else (if Trend == 2 then 5
else (if Trend == 3 then 5
else (if Trend == 4 then 5 else Double.NaN
))));

plot TEAB =
(if TrendB == 1 then 6
else (if TrendB == 2 then 6
else (if TrendB == 3 then 6
else (if TrendB == 4 then 6 else Double.NaN
))));

plot TEAC =
(if TrendC == 1 then 7
else (if TrendC == 2 then 7
else (if TrendC == 3 then 7
else (if TrendC == 4 then 7 else Double.NaN
))));

plot Consolidated = (if Expansion == 0 then 0 else Double.NaN);

TEA.AssignValueColor
(if Trend == 1 then Color.DARK_RED
else (if Trend == 2 then Color.GREEN
else (if Trend == 3 then Color.DARK_GREEN
else (if Trend == 4 then Color.RED else Color.DARK_GRAY
))));

TEA.SetPaintingStrategy(PaintingStrategy.POINTS);
TEA.SetLineWeight(4);
#TEA.HideTitle();
TEA.HideBubble();

TEAB.AssignValueColor
(if TrendB == 1 then Color.DARK_RED
else (if TrendB == 2 then Color.GREEN
else (if TrendB == 3 then Color.DARK_GREEN
else (if TrendB == 4 then Color.RED else Color.DARK_GRAY
))));

TEAB.SetPaintingStrategy(PaintingStrategy.POINTS);
TEAB.SetLineWeight(4);
#TEAB.HideTitle();
TEAB.HideBubble();

TEAC.AssignValueColor
(if TrendC == 1 then Color.DARK_RED
else (if TrendC == 2 then Color.GREEN
else (if TrendC == 3 then Color.DARK_GREEN
else (if TrendC == 4 then Color.RED else Color.DARK_GRAY
))));

TEAC.SetPaintingStrategy(PaintingStrategy.POINTS);
TEAC.SetLineWeight(4);
#TEAC.HideTitle();
TEAC.HideBubble();

Consolidated.AssignValueColor(Color.BLUE);
Consolidated.SetPaintingStrategy(PaintingStrategy.POINTS);
Consolidated.SetLineWeight(4);
#Consolidated.HideTitle();
Consolidated.HideBubble();

def AO1 = Average(Price1,5) - Average(Price1,34);
def AO2 = Average(Price2,5) - Average(Price2,34);
def AO3 = Average(Price3,5) - Average(Price3,34);
def AC1 = AO1 - Average(AO1,5);
def AC2 = AO2 - Average(AO2,5);
def AC3 = AO3 - Average(AO3,5);
def GZone1 = if AO1 > AO1[1] and AC1 > AC1[1] then 1 else 0;
def RZone1 = if AO1 < AO1[1] and AC1 < AC1[1] then 1 else 0;
def GZone2 = if AO2 > AO2[1] and AC2 > AC2[1] then 1 else 0;
def RZone2 = if AO2 < AO2[1] and AC2 < AC2[1] then 1 else 0;
def GZone3 = if AO3 > AO3[1] and AC3 > AC3[1] then 1 else 0;
def RZone3 = if AO3 < AO3[1] and AC3 < AC3[1] then 1 else 0;
def mfiA = if Vol1 > 0 then (H1 – L1) / Vol1 * 100 else 0;
def mfiB = if Vol2 > 0 then (H2 – L2) / Vol2 * 100 else 0;
def mfiC = if Vol3 > 0 then (H3 – L3) / Vol3 * 100 else 0;
def Con1A = if Vol1[1] > Vol1[2] then 1 else 0;
def Con2A = if mfiA[1] > mfiA[2] then 1 else 0;
def Con1B = if Vol2[1] > Vol2[2] then 1 else 0;
def Con2B = if mfiB[1] > mfiB[2] then 1 else 0;
def Con1C = if Vol3[1] > Vol3[2] then 1 else 0;
def Con2C = if mfiC[1] > mfiC[2] then 1 else 0;
def BW1a= if Con1A == 1 and Con2A == 1 then 1 else 0;
def BW2a= if Con1A == 1 and Con2A == 0 then 2 else 0;
def BW3a= if Con1A == 0 and Con2A == 0 then 3 else 0;
def BW4a= if Con1A == 0 and Con2A == 1 then 4 else 0;
def SBa = (BW1a + BW2a + BW3a + BW4a);
def BW1b= if Con1B == 1 and Con2B == 1 then 1 else 0;
def BW2b= if Con1B == 1 and Con2B == 0 then 2 else 0;
def BW3b= if Con1B == 0 and Con2B == 0 then 3 else 0;
def BW4b= if Con1B == 0 and Con2B == 1 then 4 else 0;
def SBb = (BW1b + BW2b + BW3b + BW4b);
def BW1c= if Con1C == 1 and Con2C == 1 then 1 else 0;
def BW2c= if Con1C == 1 and Con2C == 0 then 2 else 0;
def BW3c= if Con1C == 0 and Con2C == 0 then 3 else 0;
def BW4c= if Con1C == 0 and Con2C == 1 then 4 else 0;
def SBc = (BW1c + BW2c + BW3c + BW4c);

Plot Dot9 = 9;
Dot9.SetpaintingStrategy(PaintingStrategy.Triangles);
Dot9.SetLineWeight(DotSize);
Dot9.AssignValueColor( if GZone1 == 1 then GlobalColor("GreenZone") else if RZone1 == 1 then GlobalColor("RedZone") else GlobalColor("Neutral"));
Plot Dot10 = 10;
Dot10.SetpaintingStrategy(PaintingStrategy.Triangles);
Dot10.SetLineWeight(DotSize);
Dot10.AssignValueColor( if GZone2 == 1 then GlobalColor("GreenZone") else if RZone2 == 1 then GlobalColor("RedZone") else GlobalColor("Neutral"));
Plot Dot11 = 11;
Dot11.SetpaintingStrategy(PaintingStrategy.Triangles);
Dot11.SetLineWeight(DotSize);
Dot11.AssignValueColor( if GZone3 == 1 then GlobalColor("GreenZone") else if RZone3 == 1 then GlobalColor("RedZone") else GlobalColor("Neutral"));
Plot Dot13 =13;
Dot13.SetpaintingStrategy(PaintingStrategy.Squares);
Dot13.SetLineWeight(3);
Dot13.assignValueColor(if SBa == 1 then GlobalColor("Greenbar") else if SBa == 2 then GlobalColor("Squatbar") else if SBa == 3 then GlobalColor("Fadebar") else if SBa == 4 then GlobalColor("Fakebar") else GlobalColor("Zero"));
Plot Dot14 =14;
Dot14.SetpaintingStrategy(PaintingStrategy.Squares);
Dot14.SetLineWeight(4);
Dot14.assignValueColor(if SBb == 1 then GlobalColor("Greenbar") else if SBb == 2 then GlobalColor("Squatbar") else if SBb == 3 then GlobalColor("Fadebar") else if SBb == 4 then GlobalColor("Fakebar") else GlobalColor("Zero"));
Plot Dot15 =15;
Dot15.SetpaintingStrategy(PaintingStrategy.Squares);
Dot15.SetLineWeight(5);
Dot15.assignValueColor(if SBc == 1 then GlobalColor("Greenbar") else if SBc == 2 then GlobalColor("Squatbar") else if SBc == 3 then GlobalColor("Fadebar") else if SBc == 4 then GlobalColor("Fakebar") else GlobalColor("Zero"));

AssignPriceColor( if APC == 1 and RecP == 1 then Color.Light_Green else if APC == 1 and WarnP == 1 then Color.Orange else if APC == 1 and AcumP == 1 then Color.Green else if APC == 1 and DispP == 1 then Color.Red else if APC ==1 and BullP ==1 then Color.Dark_Green else if  apc == 1 and BearP == 1 then Color.DarK_Red  Else
if APC == 2 and RecP == 1 then Color.Light_Green else if APC == 2 and WarnP == 2 then Color.Orange else if APC == 2 and AcumP == 2 then Color.Green else if APC == 2 and DispP == 2 then Color.Red else if APC ==2 and BullP ==2 then Color.Dark_Green else if  apc == 2 and BearP == 2 then Color.DarK_Red Else if  APC == 3 and RecP == 3 then Color.Light_Green else if APC == 3 and WarnP == 3 then Color.Orange else if APC == 3 and AcumP == 3 then Color.Green else if APC == 3 and DispP == 3 then Color.Red else if APC ==3 and BullP ==3 then Color.Dark_Green else if  apc == 3 and BearP == 3 then Color.DarK_Red  Else if APC ==5 and Trend == 1 then Color.Dark_Red else if APC == 5 and Trend == 2 then color.Green else if APC==5 and Trend == 3 then Color.Dark_Green else if APC ==5 and Trend ==4 then Color.Red else if APC ==6 and TrendB == 1 then Color.Dark_Red else if APC == 6 and TrendB == 2 then color.Green else if APC==6 and TrendB == 3 then Color.Dark_Green else if APC ==6 and TrendB ==4 then Color.Red else if APC ==7 and TrendC == 1 then Color.Dark_Red else if APC == 7 and TrendC == 2 then color.Green else if APC==7 and TrendC == 3 then Color.Dark_Green else if APC ==7 and TrendC ==4 then Color.Red else if apc == 9 and GZone1 == 1 then GlobalColor("GreenZone") else if apc == 9 and RZone1 == 1 then GlobalColor("RedZone") else if apc ==9 and GZone1 == 0 and RZone1 == 0 then GlobalColor("Neutral") else if apc == 10 and GZone2 == 1 then GlobalColor("GreenZone") else if apc == 10 and RZone2 == 1 then GlobalColor("RedZone") else if apc == 10 and Gzone2 ==0 and RZone2 == 0 then GlobalColor("Neutral") else if apc == 11 and GZone3 == 1 then GlobalColor("GreenZone") else if  apc == 11 and RZone3 == 1 then GlobalColor("RedZone") else if apc == 11 and Gzone3 ==0 and RZone3 ==0 then GlobalColor("Neutral") else if apc == 13 and SBa == 1 then GlobalColor(“Greenbar”) else if APC == 13 and SBa == 2 then GlobalColor(“Squatbar”) else if apc == 13 and SBa == 3 then GlobalColor(“Fadebar”) else if apc == 13 and SBa == 4 then GlobalColor(“Fakebar”) else if apc == 14 and SBb == 1 then GlobalColor(“Greenbar”) else if APC == 14 and SBb == 2 then GlobalColor(“Squatbar”) else if apc == 14 and SBb == 3 then GlobalColor(“Fadebar”) else if apc == 14 and SBb == 4 then GlobalColor(“Fakebar”)else if apc == 15 and SBc == 1 then GlobalColor(“Greenbar”) else if APC == 15 and SBc == 2 then GlobalColor(“Squatbar”) else if apc == 15 and SBc == 3 then GlobalColor(“Fadebar”) else if apc ==15 and SBc == 4 then GlobalColor(“Fakebar”) else Color.current);``````

#### cabe1332

##### Active member
Try this

Code:
``````#From the book New Trading Dimensions by Bill Willams, PhD
#Coded by Henry Z Kaczmarczyk 01/2021
# TEA 2.0 - TOS version - 2015-06-04
# From Andrew Falde's work - LessThanRandom.com
# Converted from TradeStation to TOS by John Chernicky
#Hint: TEA 2.0 by Andrew Falde at LessThanRandom.com
#Trend Advisor Diamond Phase by Chuck Dukas , Coded by Henry Z Kaczmarczyk
#Trend Advisor Line 1 is current Time Frame. Line 2 is next higher Time Frame. Line 3 is second higher time frame.
#Trend Advisor is shown as Squares Compares Close to the 50 & 200 SMA
#Recovery Phase is Light Green
#Warning Phase is Orange
#Accumulation Phase is Green
#Dispersition Phase is Red
#Bullish Phase is Dark_Green
#Bearish Phase is Dark_Red
#TEA v 2.0 are shown as Points on lines 0,5 TEAB First Higher Time frame Lines 6, TEAC second higher Time frame Lines 7
#Consolidation is shown as Blue Points on the zero line
# Trend Caclulation
# 1 - Accumulation color Dark_Red
# 2 - Mark Up Color Green
# 3 - Distribution Color Dark_Green
# 4 - Mark Down Color Red
# 0 - No Trend
# Bill Williams Zone Bars are shown as Triangles in 3 Different Time Frames
#Green Triangles show when the Awesome Oscillator & AccelerationBands Osc are Bullish
#Red Triangles show when the Awesome Oscillator & AccelerationBands Osc are Bearish
#Blue Triangles show when the Awesome Oscillator & AccelerationBands Osc are Neutral
#Line 9 is then current Time Frame, Line 10 is then next higher time frame, Line 11 is the second higher Time Frame
#SquatBars are shown as Squares on Lines 13,14,15. Line 10 is the currentRatio Time Frame, Line 13 is the next Higher Time Frame, Line 14 is the secondsFromTime Higher Time Frame.
#GreenBars are green and are Bullish
#Squat Bars are Blue and show trend reversal at the end of Trends
#Fade Bars are Red and are Bearish
#FakeBars are Orange
#APC = 1 thru 3 will paint bars for Trend Advisor
#APC = 5 thru 7 will paint bars for TEA v2.0
#APC = 9 thru 11 will paint bars for Zone Bars
#APC = 13 thru 15 will Paint Bars for Squat Bars
Declare Lower;
DefineGlobalColor("GreenZone",Color.Green);
DefineGlobalColor("RedZone",Color.Red);
DefineGlobalColor("Neutral",Color.Blue);
DefineGlobalColor("Greenbar", Color.Green);
DefineGlobalColor("Squatbar", Color.Blue);
DefineGlobalColor("Fakebar", Color.Orange);
DefineGlobalColor("Zero", Color.Gray);
input agg1 = AggregationPeriod.FIVE_MIN;
input agg2 = AggregationPeriod.THIRTY_MIN;
input agg3 = AggregationPeriod.HOUR;
Input apc = 5;
Input DotSize = 3;
Input Length1 = 50;
Input Length2 = 200;
input Period = 21; # Bars for Price Analysis TEA
Def Price1 = HL2(Period = agg1);
Def Price2 = HL2(Period = agg2);
Def Price3 = HL2(Period = agg3);
Def Vol1 = Volume(Period = agg1);
Def Vol2 = Volume(Period = agg2);
Def Vol3 = Volume(Period = agg3);
Def H1 = High(Period = agg1);
Def H2 = High(Period = agg2);
Def H3 = High(Period = agg3);
Def L1 = Low(Period = agg1);
Def L2 = Low(Period = agg2);
Def L3 = Low(Period = agg3);
Def C1 = Close(Period = agg1);
Def C2 = Close(Period = agg2);
Def C3 = Close(Period = agg3);

Def ML1=Average(C1,Length1);
Def ML2=Average(C1,Length2);
Def BML1=Average(C2,Length1);
Def BML2=Average(C2,Length2);
Def CML1=Average(C3,Length1);
Def CML2=Average(C3,Length2);
Plot RecP = If (ML1 < ML2 AND C1 < ML2 AND C1 > ML1) then 1 else Double.Nan;
Plot WarnP = If(ML1 > ML2 AND C1 > ML2 AND C1 < ML1) then 1 Else Double.Nan;
Plot AcumP = If(ML1 < ML2 AND C1 > ML2 AND C1 > ML1) Then 1 Else Double.Nan;
Plot DispP = If(ML1 > ML2 AND C1 < ML2 AND C1 < ML1) then 1 else Double.Nan;
Plot BullP = If(ML1 > ML2 AND C1 > ML2 AND C1 > ML1) then 1 else Double.Nan;
Plot BearP = If(ML1 < ML2 AND C1 < ML2 AND C1 < ML1) then 1 else Double.Nan;
RecP.SetPaintingStrategy(PaintingStrategy.Squares);
RecP.SetDefaultColor(Color.Light_Green);
RecP.SetLineWeight(DotSize);
WarnP.SetPaintingStrategy(PaintingStrategy.Squares);
WarnP.SetDefaultColor(Color.Orange);
WarnP.SetLineWeight(DotSize);
AcumP.SetPaintingStrategy(PaintingStrategy.Squares);
AcumP.SetDefaultColor(Color. Green);
AcumP.SetLineWeight(DotSize);
DispP.SetPaintingStrategy(PaintingStrategy.Squares);
DispP.SetDefaultColor(Color.Red);
DispP.SetLineWeight(DotSize);
BullP.SetPaintingStrategy(PaintingStrategy.Squares);
BullP.SetDefaultColor(Color.Dark_Green);
BullP.SetLineWeight(DotSize);
BearP.SetPaintingStrategy(PaintingStrategy.Squares);
BearP.SetDefaultColor(Color.Dark_Red);
BearP.SetLineWeight(DotSize);

Plot RecPB = If (BML1 < BML2 AND C2 < BML2 AND C2 > BML1) then 2 else Double.Nan;
Plot WarnPB = If(BML1 > BML2 AND C2 > BML2 AND C2 < BML1) then 2 Else Double.Nan;
Plot AcumPB = If(BML1 < BML2 AND C2 > BML2 AND C2 > BML1) Then 2 Else Double.Nan;
Plot DispPB = If(BML1 > BML2 AND C2 < BML2 AND C2 < BML1) then 2 else Double.Nan;
Plot BullPB = If(BML1 > BML2 AND C2 > BML2 AND C2 > BML1) then 2 else Double.Nan;
Plot BearPB = If(BML1 < BML2 AND C2 < BML2 AND C2 < BML1) then 2 else Double.Nan;
RecPB.SetPaintingStrategy(PaintingStrategy.Squares);
RecPB.SetDefaultColor(Color.Light_Green);
RecPB.SetLineWeight(DotSize);
WarnPB.SetPaintingStrategy(PaintingStrategy.Squares);
WarnPB.SetDefaultColor(Color.Orange);
WarnPB.SetLineWeight(DotSize);
AcumPB.SetPaintingStrategy(PaintingStrategy.Squares);
AcumPB.SetDefaultColor(Color. Green);
AcumPB.SetLineWeight(DotSize);
DispPB.SetPaintingStrategy(PaintingStrategy.Squares);
DispPB.SetDefaultColor(Color.Red);
DispPB.SetLineWeight(DotSize);
BullPB.SetPaintingStrategy(PaintingStrategy.Squares);
BullPB.SetDefaultColor(Color.Dark_Green);
BullPB.SetLineWeight(DotSize);
BearPB.SetPaintingStrategy(PaintingStrategy.Squares);
BearPB.SetDefaultColor(Color.Dark_Red);
BearPb.SetLineWeight(DotSize);

Plot RecPC = If (CML1 < CML2 AND C3 < CML2 AND C3 > CML1) then 3 else Double.Nan;
Plot WarnPC = If(CML1 > CML2 AND C3 > BML2 AND C3 < CML1) then 3 Else Double.Nan;
Plot AcumPC = If(CML1 < CML2 AND C3 > BML2 AND C3 > CML1) Then 3 Else Double.Nan;
Plot DispPC = If(CML1 > CML2 AND C3 < BML2 AND C3 < CML1) then 3 else Double.Nan;
Plot BullPC = If(CML1 > CML2 AND C3 > BML2 AND C3 > CML1) then 3 else Double.Nan;
Plot BearPC = If(CML1 < CML2 AND C3 < BML2 AND C3 < CML1) then 3 else Double.Nan;
RecPC.SetPaintingStrategy(PaintingStrategy.Squares);
RecPC.SetDefaultColor(Color.Light_Green);
RecPC.SetLineWeight(DotSize);
WarnPC.SetPaintingStrategy(PaintingStrategy.Squares);
WarnPC.SetDefaultColor(Color.Orange);
WarnPC.SetLineWeight(DotSize);
AcumPC.SetPaintingStrategy(PaintingStrategy.Squares);
AcumPC.SetDefaultColor(Color. Green);
AcumPc.SetLineWeight(DotSize);
DispPC.SetPaintingStrategy(PaintingStrategy.Squares);
DispPC.SetDefaultColor(Color.Red);
DispPC.SetLineWeight(DotSize);
BullPC.SetPaintingStrategy(PaintingStrategy.Squares);
BullPC.SetDefaultColor(Color.Dark_Green);
BullPC.SetLineWeight(DotSize);
BearPC.SetPaintingStrategy(PaintingStrategy.Squares);
BearPC.SetDefaultColor(Color.Dark_Red);
BearPC.SetLineWeight(DotSize);
Plot Zeroline=0;
ZeroLine.SetDefaultColor(GetColor(7));
# Expansion Calculation
def ATR = reference ATR(Period, averageType = AverageType.SIMPLE);
def StdDev = StDev(data = Close, length = Period);
def squeeze = (ATR * .75) - StdDev;
def Expansion = If (squeeze < 0, 1, 0);

# Linear Regression

def lowest = Lowest(L1[1], Period);
def lowestB = Lowest(L2[1], Period);
def lowestC = Lowest(L3[1], Period);
def highest = Highest(H1[1], Period);
def highestB = Highest(H2[1], Period);
def highestC = Highest(H3[1], Period);
def EMA = ExpAverage(C1, Period);
def EMAB = ExpAverage(C2, Period);
def EMAC = ExpAverage(C3, Period);
def Resolve = C1 - ((highest + lowest) / 2 + EMA) / 2;
def ResolveB = C2 - ((highestB + lowestB) / 2 + EMAB) / 2;
def ResolveC = C3 - ((highestC + lowestC) / 2 + EMAC) / 2;
def Trendline = LinearRegCurve(0, Period, Resolve);
def TrendlineB = LinearRegCurve(0, Period, ResolveB);
def TrendlineC = LinearRegCurve(0, Period, ResolveC);

# Trend Caclulation
# 1 - Accumulation
# 2 - Mark Up
# 3 - Distribution
# 4 - Mark Down
# 0 - No Trend
def Trend = if Trendline <= 0 and Trendline > Trendline[1] then 1 else (
if Trendline > 0 and Trendline > Trendline[1] then 2 else (
if Trendline > 0 and Trendline < Trendline[1] then 3 else (
if Trendline <= 0 and Trendline < Trendline[1] then 4 else (
Double.NaN))));
def TrendB = if TrendlineB <= 0 and TrendlineB > TrendlineB[1] then 1 else (
if TrendlineB > 0 and TrendlineB > TrendlineB[1] then 2 else (
if TrendlineB > 0 and TrendlineB < TrendlineB[1] then 3 else (
if TrendlineB <= 0 and TrendlineB < TrendlineB[1] then 4 else (
Double.NaN))));
def TrendC = if TrendlineC <= 0 and TrendlineC > TrendlineC[1] then 1 else (
if TrendlineC > 0 and TrendlineC > TrendlineC[1] then 2 else (
if TrendlineC > 0 and TrendlineC < TrendlineC[1] then 3 else (
if TrendlineC <= 0 and TrendlineC < TrendlineC[1] then 4 else (
Double.NaN))));

plot TEA =
(if Trend == 1 then 5
else (if Trend == 2 then 5
else (if Trend == 3 then 5
else (if Trend == 4 then 5 else Double.NaN
))));

plot TEAB =
(if TrendB == 1 then 6
else (if TrendB == 2 then 6
else (if TrendB == 3 then 6
else (if TrendB == 4 then 6 else Double.NaN
))));

plot TEAC =
(if TrendC == 1 then 7
else (if TrendC == 2 then 7
else (if TrendC == 3 then 7
else (if TrendC == 4 then 7 else Double.NaN
))));

plot Consolidated = (if Expansion == 0 then 0 else Double.NaN);

TEA.AssignValueColor
(if Trend == 1 then Color.DARK_RED
else (if Trend == 2 then Color.GREEN
else (if Trend == 3 then Color.DARK_GREEN
else (if Trend == 4 then Color.RED else Color.DARK_GRAY
))));

TEA.SetPaintingStrategy(PaintingStrategy.POINTS);
TEA.SetLineWeight(4);
#TEA.HideTitle();
TEA.HideBubble();

TEAB.AssignValueColor
(if TrendB == 1 then Color.DARK_RED
else (if TrendB == 2 then Color.GREEN
else (if TrendB == 3 then Color.DARK_GREEN
else (if TrendB == 4 then Color.RED else Color.DARK_GRAY
))));

TEAB.SetPaintingStrategy(PaintingStrategy.POINTS);
TEAB.SetLineWeight(4);
#TEAB.HideTitle();
TEAB.HideBubble();

TEAC.AssignValueColor
(if TrendC == 1 then Color.DARK_RED
else (if TrendC == 2 then Color.GREEN
else (if TrendC == 3 then Color.DARK_GREEN
else (if TrendC == 4 then Color.RED else Color.DARK_GRAY
))));

TEAC.SetPaintingStrategy(PaintingStrategy.POINTS);
TEAC.SetLineWeight(4);
#TEAC.HideTitle();
TEAC.HideBubble();

Consolidated.AssignValueColor(Color.BLUE);
Consolidated.SetPaintingStrategy(PaintingStrategy.POINTS);
Consolidated.SetLineWeight(4);
#Consolidated.HideTitle();
Consolidated.HideBubble();

def AO1 = Average(Price1,5) - Average(Price1,34);
def AO2 = Average(Price2,5) - Average(Price2,34);
def AO3 = Average(Price3,5) - Average(Price3,34);
def AC1 = AO1 - Average(AO1,5);
def AC2 = AO2 - Average(AO2,5);
def AC3 = AO3 - Average(AO3,5);
def GZone1 = if AO1 > AO1[1] and AC1 > AC1[1] then 1 else 0;
def RZone1 = if AO1 < AO1[1] and AC1 < AC1[1] then 1 else 0;
def GZone2 = if AO2 > AO2[1] and AC2 > AC2[1] then 1 else 0;
def RZone2 = if AO2 < AO2[1] and AC2 < AC2[1] then 1 else 0;
def GZone3 = if AO3 > AO3[1] and AC3 > AC3[1] then 1 else 0;
def RZone3 = if AO3 < AO3[1] and AC3 < AC3[1] then 1 else 0;
def mfiA = if Vol1 > 0 then (H1 – L1) / Vol1 * 100 else 0;
def mfiB = if Vol2 > 0 then (H2 – L2) / Vol2 * 100 else 0;
def mfiC = if Vol3 > 0 then (H3 – L3) / Vol3 * 100 else 0;
def Con1A = if Vol1[1] > Vol1[2] then 1 else 0;
def Con2A = if mfiA[1] > mfiA[2] then 1 else 0;
def Con1B = if Vol2[1] > Vol2[2] then 1 else 0;
def Con2B = if mfiB[1] > mfiB[2] then 1 else 0;
def Con1C = if Vol3[1] > Vol3[2] then 1 else 0;
def Con2C = if mfiC[1] > mfiC[2] then 1 else 0;
def BW1a= if Con1A == 1 and Con2A == 1 then 1 else 0;
def BW2a= if Con1A == 1 and Con2A == 0 then 2 else 0;
def BW3a= if Con1A == 0 and Con2A == 0 then 3 else 0;
def BW4a= if Con1A == 0 and Con2A == 1 then 4 else 0;
def SBa = (BW1a + BW2a + BW3a + BW4a);
def BW1b= if Con1B == 1 and Con2B == 1 then 1 else 0;
def BW2b= if Con1B == 1 and Con2B == 0 then 2 else 0;
def BW3b= if Con1B == 0 and Con2B == 0 then 3 else 0;
def BW4b= if Con1B == 0 and Con2B == 1 then 4 else 0;
def SBb = (BW1b + BW2b + BW3b + BW4b);
def BW1c= if Con1C == 1 and Con2C == 1 then 1 else 0;
def BW2c= if Con1C == 1 and Con2C == 0 then 2 else 0;
def BW3c= if Con1C == 0 and Con2C == 0 then 3 else 0;
def BW4c= if Con1C == 0 and Con2C == 1 then 4 else 0;
def SBc = (BW1c + BW2c + BW3c + BW4c);

Plot Dot9 = 9;
Dot9.SetpaintingStrategy(PaintingStrategy.Triangles);
Dot9.SetLineWeight(DotSize);
Dot9.AssignValueColor( if GZone1 == 1 then GlobalColor("GreenZone") else if RZone1 == 1 then GlobalColor("RedZone") else GlobalColor("Neutral"));
Plot Dot10 = 10;
Dot10.SetpaintingStrategy(PaintingStrategy.Triangles);
Dot10.SetLineWeight(DotSize);
Dot10.AssignValueColor( if GZone2 == 1 then GlobalColor("GreenZone") else if RZone2 == 1 then GlobalColor("RedZone") else GlobalColor("Neutral"));
Plot Dot11 = 11;
Dot11.SetpaintingStrategy(PaintingStrategy.Triangles);
Dot11.SetLineWeight(DotSize);
Dot11.AssignValueColor( if GZone3 == 1 then GlobalColor("GreenZone") else if RZone3 == 1 then GlobalColor("RedZone") else GlobalColor("Neutral"));
Plot Dot13 =13;
Dot13.SetpaintingStrategy(PaintingStrategy.Squares);
Dot13.SetLineWeight(3);
Dot13.assignValueColor(if SBa == 1 then GlobalColor("Greenbar") else if SBa == 2 then GlobalColor("Squatbar") else if SBa == 3 then GlobalColor("Fadebar") else if SBa == 4 then GlobalColor("Fakebar") else GlobalColor("Zero"));
Plot Dot14 =14;
Dot14.SetpaintingStrategy(PaintingStrategy.Squares);
Dot14.SetLineWeight(4);
Dot14.assignValueColor(if SBb == 1 then GlobalColor("Greenbar") else if SBb == 2 then GlobalColor("Squatbar") else if SBb == 3 then GlobalColor("Fadebar") else if SBb == 4 then GlobalColor("Fakebar") else GlobalColor("Zero"));
Plot Dot15 =15;
Dot15.SetpaintingStrategy(PaintingStrategy.Squares);
Dot15.SetLineWeight(5);
Dot15.assignValueColor(if SBc == 1 then GlobalColor("Greenbar") else if SBc == 2 then GlobalColor("Squatbar") else if SBc == 3 then GlobalColor("Fadebar") else if SBc == 4 then GlobalColor("Fakebar") else GlobalColor("Zero"));

AssignPriceColor( if APC == 1 and RecP == 1 then Color.Light_Green else if APC == 1 and WarnP == 1 then Color.Orange else if APC == 1 and AcumP == 1 then Color.Green else if APC == 1 and DispP == 1 then Color.Red else if APC ==1 and BullP ==1 then Color.Dark_Green else if  apc == 1 and BearP == 1 then Color.DarK_Red  Else
if APC == 2 and RecP == 1 then Color.Light_Green else if APC == 2 and WarnP == 2 then Color.Orange else if APC == 2 and AcumP == 2 then Color.Green else if APC == 2 and DispP == 2 then Color.Red else if APC ==2 and BullP ==2 then Color.Dark_Green else if  apc == 2 and BearP == 2 then Color.DarK_Red Else if  APC == 3 and RecP == 3 then Color.Light_Green else if APC == 3 and WarnP == 3 then Color.Orange else if APC == 3 and AcumP == 3 then Color.Green else if APC == 3 and DispP == 3 then Color.Red else if APC ==3 and BullP ==3 then Color.Dark_Green else if  apc == 3 and BearP == 3 then Color.DarK_Red  Else if APC ==5 and Trend == 1 then Color.Dark_Red else if APC == 5 and Trend == 2 then color.Green else if APC==5 and Trend == 3 then Color.Dark_Green else if APC ==5 and Trend ==4 then Color.Red else if APC ==6 and TrendB == 1 then Color.Dark_Red else if APC == 6 and TrendB == 2 then color.Green else if APC==6 and TrendB == 3 then Color.Dark_Green else if APC ==6 and TrendB ==4 then Color.Red else if APC ==7 and TrendC == 1 then Color.Dark_Red else if APC == 7 and TrendC == 2 then color.Green else if APC==7 and TrendC == 3 then Color.Dark_Green else if APC ==7 and TrendC ==4 then Color.Red else if apc == 9 and GZone1 == 1 then GlobalColor("GreenZone") else if apc == 9 and RZone1 == 1 then GlobalColor("RedZone") else if apc ==9 and GZone1 == 0 and RZone1 == 0 then GlobalColor("Neutral") else if apc == 10 and GZone2 == 1 then GlobalColor("GreenZone") else if apc == 10 and RZone2 == 1 then GlobalColor("RedZone") else if apc == 10 and Gzone2 ==0 and RZone2 == 0 then GlobalColor("Neutral") else if apc == 11 and GZone3 == 1 then GlobalColor("GreenZone") else if  apc == 11 and RZone3 == 1 then GlobalColor("RedZone") else if apc == 11 and Gzone3 ==0 and RZone3 ==0 then GlobalColor("Neutral") else if apc == 13 and SBa == 1 then GlobalColor(“Greenbar”) else if APC == 13 and SBa == 2 then GlobalColor(“Squatbar”) else if apc == 13 and SBa == 3 then GlobalColor(“Fadebar”) else if apc == 13 and SBa == 4 then GlobalColor(“Fakebar”) else if apc == 14 and SBb == 1 then GlobalColor(“Greenbar”) else if APC == 14 and SBb == 2 then GlobalColor(“Squatbar”) else if apc == 14 and SBb == 3 then GlobalColor(“Fadebar”) else if apc == 14 and SBb == 4 then GlobalColor(“Fakebar”)else if apc == 15 and SBc == 1 then GlobalColor(“Greenbar”) else if APC == 15 and SBc == 2 then GlobalColor(“Squatbar”) else if apc == 15 and SBc == 3 then GlobalColor(“Fadebar”) else if apc ==15 and SBc == 4 then GlobalColor(“Fakebar”) else Color.current);``````
Hi @henry1224, would you be so kind to attached a screenshots what this code look like, please? Thanks.

##### New member
VIP
I cannot take credit for the below but i am not sure where i found this : it was free but has worked for me and only uses the VMA. not sure if its even really helpful.

input ChartBubblesOn = No;

input price = close;
input length = 10;

def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = sum(tmp1, length);
def d4 = sum(tmp2, length);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;
def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price
);
plot VMA = asd;
VMA.setDefaultColor(GetColor(0));

def vwma8 = sum(volume * close, 8) / sum(volume, 8);
def vwma21 = sum(volume * close, 21) / sum(volume, 21);
def vwma34 = sum(volume * close, 34) / sum(volume, 34);

def bullish = if vwma8 > vwma21 and vwma21 > vwma34 then 1 else 0;
def bearish = if vwma8 < vwma21 and vwma21 < vwma34 then 1 else 0;
def distribution = if !bullish and !bearish then 1 else 0;

AddLabel(yes, if bullish then "Acceleration" else if bearish then "Deceleration" else if close>=VMA then "Accumulation" else "Distribution", if bullish then color.green else if bearish then color.red else if close >=VMA then color.yellow else color.orange);

VMA.AssignValueColor(if bearish and close<= VMA then color.red
else if bullish and close >= VMA then color.green
else color.gray);

def accumulationToAcceleration = if (bullish and close>=VMA) then 1 else 0;
AddChartBubble(ChartBubblesOn and accumulationToAcceleration and !accumulationToAcceleration[1], close, "Entering Acceleration", color.green);

def distributionToDeceleration = if (bearish and close <= VMA) then 1 else 0;
AddChartBubble(ChartBubblesOn and distributionToDeceleration and !distributionToDeceleration[1], close, "Entering Deceleration", color.red);

#### henry1224

##### Active member
VIP
Hi @henry1224, would you be so kind to attached a screenshots what this code look like, please? Thanks.

Thank you. Wow.

#### zotz

##### New member
VIP
Hi @henry1224 , your "HK APC Cycles" indicator, is it can be shared?
Thank you

#### farresa

##### New member
VIP
@cabe1332

I had to go to the original code but it worked well, thank you!
Sorry it took so long to get back to you. Not on here everyday.

#### cabe1332

##### Active member
@cabe1332

I had to go to the original code but it worked well, thank you!
Sorry it took so long to get back to you. Not on here everyday.

cabe1332

#### cristalarc

##### New member
VIP
Hello!
Does somebody know how to set the first code (TEA) shared on this thread as a scanner?
I'm trying to find a way for the scanner to identify when an accumulation or mark up has popped up in the last "X" period.
I see it in the code defined as the Trend value, but can't seem to make it work to detect for that value.

Edit: or if you happen to have any other suggestions of studies to scan for accumulation, would also welcome them!

VIP