Confirmation Candles Indicator For ThinkorSwim

Thanks again HODL, I tried the Big 7 Single Agg in some non time based charts. No luck. The error mentions that the secondary agg is not valid be it 2000 (in a 2000t tick chart) or 0 in a Renko chart. The Big 4 seems good to go in tick and renko which is weird, so I was wondering if there is a block of code I should comment out or delete in order to make the Big 7 compatible. Thanks again!
 
Last edited:
Thanks again HODL, I tried the Big 7 Single Agg in some non time based charts. No luck. The error mentions that the secondary agg is not valid be it 2000 (in a 2000t tick chart) or 0 in a Renko chart. The Big 4 seems good to go in tick and renko which is weird, so I was wondering if there is a block of code I should comment out or delete in order to make the Big 7 compatible. Thanks again!
hmm interesting. I personally do not use non time based charts but ill look into it.
 
Thanks again HODL, I tried the Big 7 Single Agg in some non time based charts. No luck. The error mentions that the secondary agg is not valid be it 2000 (in a 2000t tick chart) or 0 in a Renko chart. The Big 4 seems good to go in tick and renko which is weird, so I was wondering if there is a block of code I should comment out or delete in order to make the Big 7 compatible. Thanks again!
Change the secondary aggregation to daily will eliminate the error.
But also significantly change the results.

@HODL-Lay-HE-hoo! would also like to get rid of the secondary aggregation to make it not repaint.
But it serves a very necessary purpose of confirming signal.
Removing it will subject you to all the false signals common to all oscillators.
For this reason, this particular indicator cannot be re-configured for tick charts.

This indicator should be used on your middle timeframe of your three-timeframe analysis:
https://usethinkscript.com/threads/...ay-trading-for-thinkorswim.12209/#post-104699

Then use price action on your tick chart to confirm entry:
https://usethinkscript.com/threads/price-action-toolbox-for-thinkorswim.10747/
 
Last edited:
For those of you trying out the Confirmation Candles, here is version 4. OB and OS confirmation levels have now been included (white arrows and adjustable confirmation levels), as well as labels for "Look To Buy" "Look To Sell" zones (shaded green/red), Mean Reversion and Breakout. Magenta points are reversal alert. I have included a Keltner Channel as well, with an easily adjustable factorK. Looking forward to feedback. Enjoy!
View attachment 10460
View attachment 10461

Code:
#Confirmation Candles V.4
#Created 04/15/2021 by Topher84
#Select the level of agreement among the 14 indicators included.
#Changed 04/19/2021 to V.3 - Removed ChaikinOsc and replaced with STARCBands. Added squeeze alert.
#Changed 04/20/2021 to V.4 - Added Keltner Channel, Labels, and Buy and Sell Zones. Mean Reversion and Breakout Labels added. Reversal_Alert points added.

#Keltner Channel
declare upper;
def displace = 0;
input factorK = 2.0;
input lengthK = 20;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift = factorK * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), lengthK);
def averageK = MovingAverage(averageType, price, lengthK);
def AvgK = averageK[-displace];
def Upper_BandK = averageK[-displace] + shift[-displace];
def Lower_BandK = averageK[-displace] - shift[-displace];

def conditionKup = price >= Upper_BandK;
def conditionKdown = price <= Lower_BandK;

#MACD with Price
def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
input MACD_AverageType = {SMA, default EMA};
def MACDLevel = 0.0;

def fastEMA = ExpAverage(price, fastLength);
def slowEMA = ExpAverage(price, slowLength);
def Value;
def Avg;
switch (MACD_AverageType) {
case SMA:
    Value = Average(price, fastLength) - Average(price, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = fastEMA - slowEMA;
    Avg = ExpAverage(Value, MACDLength);}
def Diff = Value - Avg;
def Level = MACDLevel;

def condition1 = Value[1] <= Value;

#RSI
def RSI_length = 14;
def RSI_AverageType = AverageType.WILDERS;
def RSI_OB = 70;
def RSI_OS = 30;

def NetChgAvg = MovingAverage(RSI_AverageType, price - price[1], RSI_length);
def TotChgAvg = MovingAverage(RSI_AverageType, AbsValue(price - price[1]), RSI_length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

def condition2 = (RSI[3] < RSI) is true or (RSI >= 80) is true;
def conditionRSI_OB = RSI > RSI_OB;
def conditionRSI_OS = RSI < RSI_OS;

#MFI
def MFI_Length = 14;
def MFIover_Sold = 20;
def MFIover_Bought = 80;
def movingAvgLength = 1;
def MoneyFlowIndex = Average(moneyflow(high, close, low, volume, MFI_Length), movingAvgLength);
def MFIOverBought = MFIover_Bought;
def MFIOverSold = MFIover_Sold;

def condition3 = (MoneyFlowIndex[2] < MoneyFlowIndex) is true or (MoneyFlowIndex > 85) is true;
def conditionMFI_OB = MoneyFlowIndex > MFIover_Bought;
def conditionMFI_OS = MoneyFlowIndex < MFIover_Sold;

#Forecast
def na = Double.NaN;
def MidLine = 50;
def Momentum = MarketForecast().Momentum;
def NearT =  MarketForecast().NearTerm;
def Intermed = MarketForecast().Intermediate;
def FOB = 80;
def FOS = 20;
def upperLine = 110;

def condition4 = (Intermed[1] <= Intermed) and (NearT >= MidLine);
def conditionFOB = Intermed > FOB;
def conditionFOS = Intermed < FOS;

#Pivot Signals
def n = 20;
def ticks = 2.0;
def bnOK = barNumber() > n;
def isHigher = fold i = 1 to n + 1 with p = 1 while p do high > GetValue(high, -i);
def HH = if bnOK and isHigher and high == Highest(high, n)then high else Double.NaN;
def isLower = fold j = 1 to n + 1 with q = 1 while q do low < GetValue(low, -j);
def LL = if bnOK and isLower and low == Lowest(low, n) then low else Double.NaN;
def PivH = if HH > 0 then HH else Double.NaN;
def PivL = if LL > 0 then LL else Double.NaN;

def UpPivotLow = !isNaN(PivL);
#UpPivotLow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#UpPivotLow.SetLineWeight(4);
#UpPivotLow.SetDefaultColor(Color.GREEN);

def DownPivotHigh = !isNaN(PivH);
#DownPivotHigh.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#DownPivotHigh.SetLineWeight(4);
#DownPivotHigh.SetDefaultColor(Color.RED);

def condition5 = !isNaN(PivL);

#EMA_1
def EMA_length = 12;
def AvgExp = ExpAverage(price[-displace], EMA_length);

def condition6 = (price >= AvgExp) and (AvgExp[2] <= AvgExp);

#EMA_2
def EMA_2length = 20;
def displace2 = 0;
def AvgExp2 = ExpAverage(price[-displace2], EMA_2length);

def condition7 = (price >= AvgExp2) and (AvgExp[2] <= AvgExp);

#DMI Oscillator
def DMI_length = 5;#Typically set to 10
input DMI_averageType = AverageType.WILDERS;
def diPlus = DMI(DMI_length, DMI_averageType)."DI+";
def diMinus = DMI(DMI_length, DMI_averageType)."DI-";
def Osc = diPlus - diMinus;
def Hist = Osc;
def ZeroLine = 0;

def condition8 = Osc >= zeroline;

#Trend_Periods
def TP_fastLength = 3;#Typically 7
def TP_slowLength = 4;#Typically 15
def Periods = sign(ExpAverage(close, TP_fastLength) - ExpAverage(close, TP_slowLength));

def condition9 = Periods > 0;

#Polarized Fractal Efficiency
def PFE_length = 5;#Typically 10
def smoothingLength = 2.5;#Typically 5
def PFE_diff = close - close[PFE_length - 1];
def val = 100 * Sqrt(Sqr(PFE_diff) + Sqr(PFE_length)) / sum(Sqrt(1 + Sqr(close - close[1])), PFE_length - 1);
def PFE = ExpAverage(if PFE_diff > 0 then val else -val, smoothingLength);
def UpperLevel = 50;
def LowerLevel = -50;

def condition10 = PFE > 0;
def conditionPFE_OB = PFE > UpperLevel;
def conditionPFE_OS = PFE < LowerLevel;

#Bollinger Bands PercentB
input BBPB_averageType = AverageType.Simple;
def BBPB_length = 5;#Typically 20
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
def BBPB_OB = 100;
def BBPB_OS = 0;
def upperBand = BollingerBands(price, displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType).LowerBand;
def PercentB = (price - lowerBand) / (upperBand - lowerBand) * 100;
def HalfLine = 50;
def UnitLine = 100;

def condition11 = PercentB > HalfLine;
def conditionBBPB_OB = PercentB > BBPB_OB;
def conditionBBPB_OS = PercentB < BBPB_OS;

#STARC Bands
def ATR_length = 15;
def SMA_lengthS = 6;
def multiplier_factor = 1.5;
def valS = Average(price, SMA_lengthS);
def average_true_range = Average(TrueRange(high, close, low), length = ATR_length);
def Upper_BandS = valS[-displace] + multiplier_factor * average_true_range[-displace];
def Middle_BandS = valS[-displace];
def Lower_BandS = valS[-displace] - multiplier_factor * average_true_range[-displace];

def condition12 = (Upper_BandS[1] <= Upper_BandS) and (Lower_BandS[1] <= Lower_BandS);

#Klinger Histogram
def Klinger_Length = 8;
def KVOsc = KlingerOscillator(Klinger_Length).KVOsc;
def KVOH = KVOsc - Average(KVOsc, Klinger_Length);
def condition13 = (KVOH > 0) and (KVOsc[1] <= KVOsc);

#Projection Oscillator
def ProjectionOsc_length = 9;#Typically 10
def MaxBound = HighestWeighted(high, ProjectionOsc_length, LinearRegressionSlope(price=high, length=ProjectionOsc_length));
def MinBound = LowestWeighted(low, ProjectionOsc_length, LinearRegressionSlope(price=low, length=ProjectionOsc_length));
def ProjectionOsc_diff = MaxBound - MinBound;
def PROSC = if ProjectionOsc_diff != 0 then 100 * (close - MinBound) / ProjectionOsc_diff else 0;
def PROSC_OB = 80;
def PROSC_OS = 20;

def condition14 = PROSC > 50;
def conditionPROSC_OB = PROSC > PROSC_OB;
def conditionPROSC_OS = PROSC < PROSC_OS;

#Trend Confirmation Calculator
#Confirmation_Factor range 1-15.
input coloredCandlesOn = yes;
input Confirmation_Factor = 7;
#Use for testing conditions individually. Remove # from line below and change Confirmation_Factor to 1.
#def Agreement_Level = condition1;
def Agreement_Level = condition1 + condition2 + condition3 + condition4 + condition5 + condition6 + condition7 + condition8 + condition9 + condition10 + condition11 + condition12 + condition13 + condition14 + conditionKup;

def conditionChannel1 = Upper_BandK > price;
def conditionChannel2 = Lower_BandK < price;

def UP = if conditionChannel1 and conditionChannel2 then Agreement_Level >= Confirmation_Factor else 0;
def DOWN = if conditionChannel1 and conditionChannel2 then Agreement_Level <= Confirmation_Factor else 0;

AssignPriceColor(if coloredCandlesOn and UP or conditionKup then Color.LIGHT_GREEN else if coloredCandlesOn and DOWN or conditionkdown then Color.RED else Color.YELLOW);

#Additional Signals

#OB/OS Signal
input Confirmation_OB = 4;
def Agreement_OB = conditionRSI_OB + conditionMFI_OB + conditionFOB + conditionPFE_OB + conditionBBPB_OB + conditionPROSC_OB;

input Confirmation_OS = 4;
def Agreement_OS = conditionRSI_OS + conditionMFI_OS + conditionFOS + conditionPFE_OS + conditionBBPB_OS + conditionPROSC_OS;

plot OB_Signal = Agreement_OB crosses below Confirmation_OB;
OB_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
OB_Signal.SetLineWeight(1);
OB_Signal.SetDefaultColor(Color.WHITE);

plot OS_Signal = Agreement_OS crosses below Confirmation_OS;
OS_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
OS_Signal.SetLineWeight(1);
OS_Signal.SetDefaultColor(Color.WHITE);

def DOWN_OB = Agreement_OB >= Confirmation_OB;
def UP_OS = Agreement_OS >= Confirmation_OS;

def OS_Buy = UP_OS;
def OB_Sell = DOWN_OB;
def neutral = Agreement_OB < Confirmation_OB and Agreement_OS < Confirmation_OS;

#AddVerticalLine (OS_Buy and !OS_Buy[1], close, Color.GREEN, Curve.SHORT_DASH);
#AddVerticalLine (Neutral and !neutral[1], close, Color.Gray, Curve.SHORT_DASH);
#AddVerticalLine (OB_Sell and OB_Sell and !OB_Sell[1], close, Color.RED, Curve.SHORT_DASH);

def Buy_Opportnity = if OS_Buy then Double.POSITIVE_INFINITY else Double.NEGATIVE_INFINITY;
AddCloud(Buy_Opportnity, Neutral, Color.LIGHT_GREEN, Color.LIGHT_RED);
def Sell_Opportnity = if OB_Sell then Double.POSITIVE_INFINITY else Double.NEGATIVE_INFINITY;
AddCloud(Sell_Opportnity, Neutral, Color.LIGHT_RED, Color.LIGHT_RED);

#Squeeze Alert
def length = 20;
def BulgeLength = 150;
def SqueezeLength = 150;
def upperBandBB = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).UpperBand;
def lowerBandBB = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).LowerBand;
def midLineBB = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).MidLine;
def Bandwidth = (upperBandBB - lowerBandBB) / midLineBB * 100;
def Bulge = Highest(Bandwidth, BulgeLength);
def Squeeze = Lowest(Bandwidth, SqueezeLength);

plot Squeeze_Alert = bandwidth <= squeeze;
Squeeze_Alert.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Squeeze_Alert.SetLineWeight(3);
Squeeze_Alert.SetDefaultColor(Color.YELLOW);

#Trend Signals
plot UPSignal = Agreement_Level crosses above Confirmation_Factor;
UPSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UPSignal.SetLineWeight(1);
UPSignal.SetDefaultColor(Color.GREEN);

plot DOWNSignal = Agreement_Level crosses below Confirmation_Factor;
DOWNSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DOWNSignal.SetLineWeight(1);
DOWNSIGNAL.SetDefaultColor(Color.RED);

def conditionMR = (Upper_BandS[1] > Upper_BandS) and (Lower_BandS[1] > Lower_BandS);
plot Reversal_Alert = conditionMR and price>= Middle_BandS;
Reversal_Alert.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Reversal_Alert.SetLineWeight(3);
Reversal_Alert.SetDefaultColor(Color.MAGENTA);

#Labels
def Buy = UP_OS;
def Sell = DOWN_OB;
AddLabel(yes, "Look_To_Buy", if Buy then Color.GREEN else Color.GRAY);
AddLabel(yes, "Look_To_Sell", if Sell then Color.RED else Color.GRAY);

def MomentumUP = Agreement_Level[1] < Agreement_Level;
def MomentumDOWN = Agreement_Level[1] > Agreement_Level;
AddLabel(yes, "Increasing Momentum", if MomentumUP then Color.Green else Color.GRAY);
AddLabel(yes, "Decreasing Momentum", if MomentumDOWN then Color.RED else Color.GRAY);


AddLabel(yes, "MEAN REVERSION", if conditionMR then Color.RED else Color.GRAY);
def conditionBO = (Upper_BandS[1] < Upper_BandS) and (Lower_BandS[1] < Lower_BandS);
AddLabel(yes, "BREAKOUT", if conditionBO then Color.GREEN else Color.GRAY);

def Squeeze_Signal = Squeeze_Alert;
AddLabel(yes, "SQUEEZE ALERT", if Squeeze_Signal then Color.YELLOW else Color.GRAY);

I
 
Last edited:
Y7zZDZc.png


Good people... C3_BIG_Spark_MAX... (+TS_V9 signals only) Has arrived!
(single aggregation)
  • Added the Big7 candle coloring, labels, and consolidated a few variables
  • TS_V9 signals and Big7 signals can be shown via settings (no p&l calculation which unfortunately means the levels for the averages and stops are not included)
  • Removed inputs that most users do not change
  • Added label to indicate when price is within "x" of a "key level" which is colored the same as the level is represents - "Near Key Level" :
    • Key level OB = Color.Orange
    • Key level OS = Color.Light_Green
  • Added label to indicate a high potential for bounce - "Bounce Incoming!"

https://usethinkscript.com/threads/...-all-be-all-for-thinkorswim.15257/post-130315

Q2svhxd.png
 
Last edited:
Updated EMAD Range V1000

Updated calculation to plot arrows

EMAD Range (newest variant "V1000") - http://tos.mx/5jmDs9c

2k8hZIM.png


Code:
#EMAD Range by @ Christopher84
#EMAD V1000 - added arrow conditions - histogram - and color conditions HODL

#DECLARATIONS
declare lower;


#USER INPUTS
input showHLLH = no;
input showHowToLabel = yes;
input ShowColorCodeLabel = no;
input showtestlabels = no;
input showEMACloud = yes;
input showBubbles = no;
input showTripleExh = yes;
input showehlers = no;
input showMAD = no;
input showverticalline = yes;
input bandLength = 100;
input bandLength2 = 100;
input ELlength = 34;
Input LengtH_MAD = 4;
input fastLength = 10;
input slowLength = 35;
input lengthBAD = 3;
input smoothLength = 12;
input smoothLength2 = 14;
input ATRPeriod = 5;
input ATRFactor = 2.0;
input length_3x = 1000;
input priceType = close;
input emadLineWeight = 2;
input averageType = AverageType.WILDERS;
input averageType_Sq = AverageType.SIMPLE;
input firstTrade_Sq = {default long, short};
input trailType = {default modified, unmodified};
input firstTrade = {default long, short};
input filterBounceArrows = 1;
input filter_3x = 50;
input Control_3x = 3;
input crossabovebelowzero = 20;
input bandlengthbottom2 = 3;
input Lookback = 20;
input cloudlinelook = 20;
input LHHL_Lookback = 1;
input Steplookback = 10;
input filterZeroline = 20;
input topbanddownlookback = 1;
input bottombanduplookback = 1;
input SqueezeLook = 5;
input alert4lookback = 21;
input PreviousStepsDown = 2;
input PreviousStepsUp = 2;
input alert4control = 2;
input tradeDaytimeOnly = yes; #hint tradeDaytimeOnly: (IntraDay Only) Only perform trades during hours stated
input OpenTime = 0730; #hint OpenTime: Opening time of market
input CloseTime = 1800; #hint CloseTime: Closing time of market

def bn = barnumber();
def Begin = SecondsFromTime(OpenTime);
def End = SecondsTillTime(CloseTime);
def isIntraDay = if GetAggregationPeriod() > 14400000 or GetAggregationPeriod() == 0 then 0 else 1;
def MarketOpen = if !tradeDaytimeOnly or !isIntraDay then 1 else if tradeDaytimeOnly and isIntraDay and Begin > 0 and End > 0 then 1 else 0;

#GLOBAL COLOR DEFINITIONS
DefineGlobalColor("Green", CreateColor(0, 155, 0));
DefineGlobalColor("Red", CreateColor(225, 105, 105));
DefineGlobalColor("Gray", CreateColor(192, 192, 192));
DefineGlobalColor("Yellow", CreateColor(231, 190, 0));

## UPPER EMAD LINE
def fastExpAvg = ExpAverage(priceType, fastLength);
def slowExpAvg = ExpAverage(priceType, slowLength);
def EMAD = (priceType - fastExpAvg);
def EMAD2 = (priceType - slowExpAvg);
def EMADAvg = (EMAD + EMAD2) / 2;
def upperEMADLine = ExpAverage(EMADAvg, smoothLength);
## LOWER EMAD LINE
def emadOpen = (upperEMADLine + upperEMADLine[1]) / 2;
def emadHigh = Max(upperEMADLine, upperEMADLine[1]);
def emadLow = Min(upperEMADLine, upperEMADLine[1]);
def emadClose = upperEMADLine;
def bottom = Min(emadClose[1], emadLow);
def tr = TrueRange(emadHigh, emadClose, emadLow);
def ptr = tr / (bottom + tr / 2);
def APTR = MovingAverage(averageType, ptr, smoothLength2);
def upperBand = emadClose[1] + (APTR * emadOpen);
def lowerBand = emadClose[1] - (APTR * emadOpen);
def lowerEMADLine = (upperBand + lowerBand) / 2;
## TOP AND BOTTOM BANDS
def zeroLineData = if IsNaN(close) then Double.NaN else 0;
def EMADSUp = upperEMADLine > zeroLineData;
def EMADSDown = upperEMADLine < zeroLineData;
def EMADdown = (lowerEMADLine > upperEMADLine);
def EMADup = (upperEMADLine >= lowerEMADLine);
def topBand = Highest(lowerEMADLine, bandLength);
def bottomBand = Lowest(lowerEMADLine, bandLength);
def zerolinedatacondition = if (zerolinedata > topBand) then topBand else if (zerolinedata < bottomBand) then bottomBand else 0;
## Master
def masteremadline = (upperEMADLine + lowerEMADLine) / 2;
## BAND DIRECTION (USED ONLY FOR COLORING - NOT USED FOR PLOTS)
def topBandStepDown = if topBand < topBand[1] then 1 else 0;
def topBandStepUp = if topBand > topBand[1] then 1 else 0;
def bottomBandStepDown = if bottomBand < bottomBand[1] then 1 else 0;
def bottomBandStepUp = if bottomBand > bottomBand[1] then 1 else 0;
def bothBandsDown = bottomBandStepDown and topBandStepDown;
def bothBandsUp = bottomBandStepUp and topBandStepUp;
def bullBias = (bottomBand > zeroLineData);
def bearBias = (topBand < zeroLineData);
## BUBBLE CALCULATIONS (USED ONLY FOR BUBBLES)
def midBand = (upperBand + lowerBand) / 2;
def crossesUp = if (midBand[1] > upperEMADLine[1])and(midBand < upperEMADLine) then 1 else 0;
def crossesDown = if (upperEMADLine[1] > midBand[1])and(upperEMADLine < midBand) then 1 else 0;
def valueUp = if crossesUp then midBand else 0;
def valueDown = if crossesDown then midBand else 0;
def crossesUpline = if (valueUp - bottomBand) == 0 then 1 else 0;
def crossesDownline = if (valueDown - topBand) == 0 then 1 else 0;
def crossesUpline_filter = if crossesUpline and (crossesUpline[1] or crossesUpline[2]  or crossesUpline[3]   or crossesUpline[4])then 0 else 1;
def crossesDownline_filter = if crossesDownline and (crossesDownline[1] or crossesDownline[2]  or crossesDownline[3]   or crossesDownline[4])then 0 else 1;
def crossesUpZeroline = if (valueUp) == 0 then 1 else 0;
def crossesDownZeroline = if (valueDown) == 0 then 1 else 0;
def crossesUpBottomlinebn = if crossesUpline and !crossesUpline[1] then bn else crossesUpBottomlinebn[1];
def crossesDownToplinebn = if crossesDownline and !crossesDownline[1] then bn else crossesDownToplinebn[1];
def crossuplinewithin = if crossesUpBottomlinebn < bn then bn - crossesUpBottomlinebn else crossuplinewithin[1];
def crossdownlinewithin = if crossesDownToplinebn < bn then bn - crossesDownToplinebn else crossdownlinewithin[1];
def crosslinefirst = if crossuplinewithin < crossdownlinewithin then 1 else 0;
def crosslinelogic = crossesUpBottomlinebn > crossesDownToplinebn;
def HL = crossesUpline == 0 and crossesDownline == 0 and upperEMADLine crosses above lowerEMADLine;  #Normal HL LH condition
def LH = crossesDownline == 0 and upperEMADLine crosses below lowerEMADLine; #Normal HL LH condition
def bounceUpOnce = crossesUpline <> crossesUpline[1]; #XUpBtm happened previous bar or on current bar
def bounceDnOnce = crossesDownline <> crossesDownline[1];
def trackCrUp = if bounceUpOnce then 0 else if HL then 1 else trackCrUp[1];
def trackCrDn = if bounceDnOnce then 0 else if LH then 1 else trackCrDn[1];
## SECOND HL AND LH
def HLalready = if trackCrUp and !trackCrUp[1] then 1 else 0;
def LHalready = if trackCrDn and !trackCrDn[1] then 1 else 0;
def HL2 = HLalready == 0 and upperEMADLine crosses above lowerEMADLine;
def LH2 = LHalready == 0 and upperEMADLine crosses below lowerEMADLine;
def crossedUpOnce = HLalready <> HLalready[1];
def crossedDnOnce = LHalready <> LHalready[1];
def trackCrUp2 = if crossedUpOnce then 0 else if HL2 then 1 else trackCrUp2[1];
def trackCrDn2 = if crossedDnOnce then 0 else if LH2 then 1 else trackCrDn2[1];
#####################################################
##                                                 ##
#####################################################
def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);
def trueRange_Sq;
switch (trailType) {
case modified:
    trueRange_Sq = Max(HiLo, Max(HRef, LRef));
case unmodified:
    trueRange_Sq = TrueRange(high, close, low);
}
def loss_Sq = ATRFactor * MovingAverage(averageType_Sq, trueRange_Sq, ATRPeriod);
def state_Sq = {default init, long, short};
def trail_Sq;
switch (state_Sq[1]) {
case init:
    if (!IsNaN(loss_Sq)) {
        switch (firstTrade) {
        case long:
            state_Sq = state_Sq.long;
            trail_Sq =  close - loss_Sq;
        case short:
            state_Sq = state_Sq.short;
            trail_Sq = close + loss_Sq;
    }
    } else {
        state_Sq = state_Sq.init;
        trail_Sq = Double.NaN;
    }
case long:
    if (close > trail_Sq[1]) {
        state_Sq = state_Sq.long;
        trail_Sq = Max(trail_Sq[1], close - loss_Sq);
    } else {
        state_Sq = state_Sq.short;
        trail_Sq = close + loss_Sq;
    }
case short:
    if (close < trail_Sq[1]) {
        state_Sq = state_Sq.short;
        trail_Sq = Min(trail_Sq[1], close + loss_Sq);
    } else {
        state_Sq = state_Sq.long;
        trail_Sq =  close - loss_Sq;
    }
}
def TrailingStop_Sq = trail_Sq;
def H = Highest(TrailingStop_Sq, 12);
def L = Lowest(TrailingStop_Sq, 12);
def BulgeLengthPrice = 100;
def SqueezeLengthPrice = 100;
def BandwidthC3 = (H - L);
def IntermResistance2 = Highest(BandwidthC3, BulgeLengthPrice);
def IntermSupport2 = Lowest(BandwidthC3, SqueezeLengthPrice);
def sqzTrigger = BandwidthC3 <= IntermSupport2;
def sqzLevel = if !sqzTrigger[1] and sqzTrigger then hl2 else if !sqzTrigger then Double.NaN else sqzLevel[1];
def Squeeze_Alert_1 = if sqzLevel then (upperEMADLine + lowerEMADLine) / 2 else (upperEMADLine + lowerEMADLine) / 2 ;
#####################################################
##                                                 ##
#####################################################
def over_bought_3x = 80;
def over_sold_3x = 20;
def KPeriod_3x = 10;
def DPeriod_3x = 10;
def priceH1 = high;
def priceL1 = low;
def priceC1 = close;
def priceO1 = close;
def priceH_3x = high;
def priceL_3x = low;
def priceC_3x = close;   
def SlowK_3x = reference StochasticFull(over_bought_3x,  over_sold_3x,  KPeriod_3x,  DPeriod_3x,  priceH_3x,  priceL_3x,  priceC_3x,  3, if (averageType == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullK;
def MACD_3x = reference MACD()."Value";
def priceMean_3x = Average(MACD_3x, length_3x);
def MACD_stdev_3x =  (MACD_3x - priceMean_3x) / StDev(MACD_3x, length_3x);
def dPlus_3x = reference DMI()."DI+";
def dMinus_3x = reference DMI()."DI-";
def sellerRegular = SlowK_3x < 20 and MACD_stdev_3x < -1 and dPlus_3x < 15;
def sellerExtreme = SlowK_3x < 20 and MACD_stdev_3x < -2 and dPlus_3x < 15;
def buyerRegular = SlowK_3x > 80 and MACD_stdev_3x > 1 and dMinus_3x < 15;
def buyerExtreme = SlowK_3x > 80 and MACD_stdev_3x > 2 and dMinus_3x < 15;   
def ExtremeBuy1 = if sellerExtreme[1] and !sellerExtreme then 1 else 0;
def ExtremeSell1 = if buyerExtreme[1] and !buyerExtreme then 1 else 0;
def RegularSell1 = if buyerRegular[1] and !buyerRegular then 1 else 0;
def RegularBuy1= if sellerRegular[1] and !sellerRegular then 1 else 0;
#####################################################
##                                                 ##
#####################################################
def priceE = (emadhigh + emadlow) / 2;
def coeff = ELlength * priceE * priceE - 2 * priceE * sum(priceE, ELlength)[1] + sum(priceE * priceE, ELlength)[1];
def Ehlers =  sum(coeff * priceE, ELlength) / sum(coeff, ELlength);
#####################################################
##                                                 ##
#####################################################
def dataA = masterEMADLine;
def dataA1 =
    fold aD = 0
    to LengtH_MAD
    with k = 0
    do k + dataA[aD];
def MAEMAD = dataA1 / LengtH_MAD;
def MAD = MAEMAD;
def ElCrossDN = ehlers crosses above masterEMADline;
def ElCrossUP = ehlers crosses below masterEMADline;
def bullBias2 = (emadsup);
def bearBias2 = (emadsdown);
def MADehlers = (MAD - Ehlers)/2;
def Madebad = madehlers + ehlers;
def madebadavg = average(madebad, lengthBAD);
def crossmadeup = madebad > madebad[1];
def crossmadedn = madebad < madebad[1];
def crossmade2up = if (madebad < masterEMADLine) and crossmadeup and (bullBias2 > 0) then 1 else 0;
def crossmade2dn = if (madebad > masterEMADLine) and crossmadedn and (bearBias2 > 0) then 1 else 0;
def crossmade2 = if (madebad < masterEMADLine) and crossmadeup and (bullBias2 > 0) then 1 else if (madebad > masterEMADLine) and crossmadedn and (bearBias2 > 0) then -1 else 0;
def crossmade0 = if (!crossmade2[1] or !crossmade2[1]) and (crossmade2 == 0) then 1 else 0;
#####################################################
##                                                 ##
#####################################################
def pd = 22;
def bbl = 20;
def mult = 2.0;
def lb = 50;
def ph = 0.85;
def ltLB = 40;
def mtLB = 14;
def str = 3;
def wvf = ((Highest(close, pd) - low) / (Highest(close, pd))) * 100;
def sDev = mult * StDev(wvf, bbl);
def midLine1 = SimpleMovingAvg(wvf, bbl);
def lowerBand1 = midLine1 - sDev;
def upperBand1 = midLine1 + sDev;
def rangeHigh = (Highest(wvf, lb)) * ph;
def upRange = low > low[1] and close > high[1];
def upRange_Aggr = close > close[1] and close > open[1];
def filtered = ((wvf[1] >= upperBand1[1] or wvf[1] >= rangeHigh[1]) and (wvf < upperBand1 and wvf < rangeHigh));
def filtered_Aggr = (wvf[1] >= upperBand1[1] or wvf[1] >= rangeHigh[1]);
def alert4 = upRange_Aggr and close > close[str] and (close < close[ltLB] or close < close[mtLB]) and filtered_Aggr;
def alert4close = if alert4 then close else 0;
def crossmade = if (madebad < masterEMADLine) and crossmadeup then 1 else if (madebad > masterEMADLine) and crossmadedn then -1 else 0;
def madedn = (madebad > masterEMADLine);
def madeup = (madebad < masterEMADLine);
def made2 = madebadavg;
def made3 = if !madedn and (made2 <= zerolinedata) then madebadavg else double.nan;
def made4 = if !madeup and (made2 >= zerolinedata) then madebadavg else double.nan;
def madecrossupavg = if made2 crosses below masterEMADLine then 1 else 0;
def madecrossdownavg = if made2 crosses above masterEMADLine then 1 else 0;
def crossmadelogicup = if madecrossupavg and !madecrossupavg[1] then 1 else 0;
def crossmadelogicdown = if madecrossdownavg and !madecrossdownavg[1] then 1 else 0;
def crossmademorelogicup = if crossmadelogicup and crosslinelogic and emadup[1] then 1 else 0;
def crossmademorelogicdown = if crossmadelogicdown and !crosslinelogic and emaddown[1] then 1 else 0;
def EmaPushStepUp = if topBandStepUp and EmadUp and (((upperEMADLine) - bottomband) == 0) then 1 else 0;;
def EmaPushStepDown = if bottomBandStepDown and EmadDown and (((lowerEMADLine) - bottomband) == 0) then 1 else 0;
def HLFilter = if HL[1] < HL then 1 else 0;
def LHFilter = if LH[1] > LH then 1 else 0;
def HLFilter2 = if HL[2] < HL[1] then 1 else 0;
def LHFilter2 = if LH[2] > LH[1] then 1 else 0;
#####################################################
##                                                 ##
#####################################################
def ValueUp_lookback = fold index1 = 1 to filterBounceArrows with x1 do x1 + absvalue(valueUp)[index1];
def ValueDown_lookback = fold index2 = 1 to filterBounceArrows with x2 do x2 + absvalue(valueDown)[index2];
def topBandStepDown_lookback = fold index3 = 1 to Steplookback with x3 do x3 + topBandStepDown[index3];
def topBandStepUp_lookback = fold index4 = 1 to Steplookback with x4 do x4 + topBandStepUp[index4];
def bottomBandStepDown_lookback = fold index5 = 1 to Steplookback with x5 do x5 + bottomBandStepDown[index5];
def bottomBandStepUp_lookback = fold index6 = 1 to Steplookback with x6 do x6 + bottomBandStepUp[index6];
def bothBandsDown_lookback = fold index7 = 1 to filterBounceArrows with x7 do x7 + bothBandsDown[index7];
def bothBandsUp_lookback = fold index8 = 1 to filterBounceArrows with x8 do x8 + bothBandsUp[index8];
def bullBias_lookback = fold index9 = 1 to filterBounceArrows with x9 do x9 + bullBias[index9];
def bearBias_lookback = fold index10 = 1 to filterBounceArrows with x10 do x10 + bearBias[index10];
def crossesUpZeroline_lookback = fold index11 = 1 to filterZeroline with x11 do x11 + crossesUpZeroline[index11];
def crossesDownZeroline_lookback = fold index12 = 1 to filterZeroline with x12 do x12 + crossesDownZeroline[index12];
def crossesUpBottomline_lookback = fold index13 = 1 to filterBounceArrows with x13 do x13 + crossesUpline[index13];
def crossesDownTopline_lookback = fold index14 = 1 to filterBounceArrows with x14 do x14 + crossesDownline[index14];
def CrossedUPaboveZero_lookback = fold index15 = 1 to crossabovebelowzero with x15 do x15 + crossesUpZeroline[index15];
def CrossedDOWNbelowZero_lookback = fold index16 = 1 to crossabovebelowzero with x16 do x16 + crossesDownZeroline[index16];
def HL_lookback = fold index17 = 1 to LHHL_Lookback with x17 do x17 + HL[index17];
def LH_lookback = fold index18 = 1 to LHHL_Lookback with x18 do x18 + LH[index18];
def upabovezero_lookback = fold index19 = 1 to crossabovebelowzero with x19 do x19 + HL[index19];
def downbelowzero_lookback = fold index20 = 1 to crossabovebelowzero with x20 do x20 + LH[index20];
def PriceMonitor = fold index21 = 1 to crossabovebelowzero with x21 do x21 + HL[index21];
def ExtremeBuy1_lookback = fold index24 = 1 to filter_3x with x24 do x24 + ExtremeBuy1[index24];
def ExtremeSell1_lookback = fold index25 = 1 to filter_3x with x25 do x25 + ExtremeSell1[index25];
def RegularSell1_lookback = fold index26 = 1 to filter_3x with x26 do x26 + RegularSell1[index26];
def RegularBuy1_lookback = fold index27 = 1 to filter_3x with x27 do x27 + RegularBuy1[index27];
def Squeeze_lookback = fold index28 = 1 to SqueezeLook with x28 do x28 + Squeeze_Alert_1[index28];
def ElCrossDN_lookback = fold index29 = 1 to filterBounceArrows with x29 do x29 + ElCrossDN[index29];
def ElCrossUP_lookback = fold index30 = 1 to filterBounceArrows with x30 do x30 + ElCrossUP[index30];
def bearBias2_lookback = fold index31 = 1 to filterBounceArrows with x31 do x31 + bearBias2[index31];
def bullBias2_lookback = fold index32 = 1 to filterBounceArrows with x32 do x32 + bullBias2[index32];
def crossmade0_lookback = fold index33 = 1 to cloudlinelook with x33 do x33 + crossmade0[index33];
def alert4_lookback = fold index34 = 1 to alert4lookback with x34 do x34 + alert4close[index34];
#####################################################
##                                                 ##
#####################################################
def bubblehidertopdown = topBandStepDown_lookback > PreviousStepsDown;
def bubblehidertopup = topBandStepup_lookback > PreviousStepsUp;
def bubblehiderbottomdown = bottomBandStepDown_lookback > PreviousStepsDown;
def bubblehiderbottomup = bottomBandStepup_lookback > PreviousStepsUp;
def UP1 = if marketopen and (!bubblehidertopdown or !bubblehiderbottomdown) and !EmaPushStepDown and crossmademorelogicup then midBand else double.nan;
def DOWN1 = if marketopen and (!bubblehidertopup or !bubblehiderbottomup) and !EmaPushStepUp and crossmademorelogicdown then midBand else double.nan;
#####################################################
##                                                 ##
#####################################################
plot zeroLine = zerolinedata;
plot Squeeze_Alert = if sqzLevel then (upperEMADLine + lowerEMADLine) / 2 else (upperEMADLine + lowerEMADLine) / 2 ;
plot ExtremeBuy = if showTripleExh and sellerExtreme[1] and !sellerExtreme then midband else Double.NaN;
plot ExtremeSell = if showTripleExh and buyerExtreme[1] and !buyerExtreme then midband else Double.NaN;
plot RegularSell = if showTripleExh and buyerRegular[1] and !buyerRegular then midband else Double.NaN;
plot RegularBuy = if showTripleExh and sellerRegular[1] and !sellerRegular then midband else Double.NaN;
plot topBandPlot = topBand;
plot bottomBandPlot = bottomBand;
plot upperEMADLinePlot = upperEMADLine;
plot lowerEMADLinePlot = lowerEMADLine;
plot masterEMADLinePlot2 = (upperEMADLine + lowerEMADLine) / 2;
plot masterEMADLinePlot = ((upperEMADLinePlot + lowerEMADLinePlot) / 2);
plot made1 = made4;
plot made = made3;
plot UP = UP1;
plot DOWN = DOWN1;
plot firstHL = if showHLLH and trackCrUp and !trackCrUp[1] then lowerEMADLine else double.nan;
plot firstLH = if showHLLH and trackCrDn and !trackCrDn[1] then lowerEMADLine else double.nan;
plot secondHL = if showHLLH and trackCrUp2 and !trackCrUp2[1] and !crossesUpline then lowerEMADLine else double.nan;
plot secondLH = if showHLLH and trackCrDn2 and !trackCrDn2[1] and !crossesDownline then lowerEMADLine else double.nan;
#####################################################
##                                                 ##
#####################################################
def firstHL2 = if trackCrUp and !trackCrUp[1] then 1 else 0;
def firstLH2 = if trackCrDn and !trackCrDn[1] then 1 else 0;
def HLBuy = if firstHL2 and regularsell1 or extremesell1 then 1 else 0;
def LHSell = if firstHL2 and regularbuy1 or extremebuy1 then 1 else 0;
#####################################################
##                                                 ##
#####################################################
UP.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UP.SetLineWeight(1);
UP.SetDefaultColor(Color.white);
UP.HideBubble();
UP.HideTitle();
#####################################################
##                                                 ##
#####################################################
DOWN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DOWN.SetLineWeight(1);
DOWN.SetDefaultColor(Color.white);
DOWN.HideBubble();
DOWN.HideTitle();
#####################################################
##                                                 ##
#####################################################
made1.AssignValueColor(
     if crossmade2 == 1 then color.dark_green
else if crossmade2 == -1 then color.dark_red
else if crossmade0_lookback > 1 and crosslinelogic then Color.gray
else color.dark_red);
#####################################################
##                                                 ##
#####################################################
made.AssignValueColor(
     if crossmade2 == 1 then color.dark_green
else if crossmade2 == -1 then color.dark_red
else if crossmade0_lookback > 1 and crosslinelogic then Color.gray
else color.dark_red);
#####################################################
##                                                 ##
#####################################################
Squeeze_Alert.SetPaintingStrategy(PaintingStrategy.line);
Squeeze_Alert.SetLineWeight(2);
Squeeze_Alert.SetDefaultColor(Color.YELLOW);
#####################################################
##                                                 ##
#####################################################
RegularBuy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ExtremeBuy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
RegularSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ExtremeSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#####################################################
##                                                 ##
#####################################################
RegularBuy.SetLineWeight((1));
ExtremeBuy.SetLineWeight((1));
RegularSell.SetLineWeight((1));
ExtremeSell.SetLineWeight((1));
#####################################################
##                                                 ##
#####################################################
ExtremeSell.SetDefaultColor((Color.WHITE));
ExtremeBuy.SetDefaultColor((Color.WHITE));
RegularBuy.SetDefaultColor((Color.white));
RegularSell.SetDefaultColor((Color.white));
#####################################################
##                                                 ##
#####################################################
firstHL.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
firstHL.SetLineWeight(1);
firstHL.SetDefaultColor(Color.blue);
firstHL.HideBubble();
firstHL.HideTitle();
#####################################################
##                                                 ##
#####################################################
firstLH.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
firstLH.SetLineWeight(1);
firstLH.SetDefaultColor(Color.blue);
firstLH.HideBubble();
firstLH.HideTitle();
#####################################################
##                                                 ##
#####################################################
secondHL.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
secondHL.SetLineWeight(1);
secondHL.SetDefaultColor(Color.CYAN);
secondHL.HideBubble();
secondHL.HideTitle();
#####################################################
##                                                 ##
#####################################################
secondLH.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
secondLH.SetLineWeight(1);
secondLH.SetDefaultColor(Color.CYAN);
secondLH.HideBubble();
secondLH.HideTitle();
#####################################################
##                                                 ##
#####################################################
masterEMADLinePlot.SetPaintingStrategy(PaintingStrategy.histogram);
masterEMADLinePlot.HideBubble();
masterEMADLinePlot.SetLineWeight(1);
masterEMADLinePlot.AssignValueColor(
     if alert4 then color.cyan
else if HLBuy then color.light_green
else if LHSell then color.light_red
else if crossmade2up then Color.dark_green
else if crossmade2dn then color.dark_red
else if crossmade0_lookback > 1 and crosslinelogic then Color.dark_gray
else color.dark_red
);
DefineGlobalColor("G0", CreateColor(0, 255, 0));  #Green
DefineGlobalColor("G1", CreateColor(0, 229, 0));  #Green
DefineGlobalColor("G2", CreateColor(0, 206, 0));  #Green
DefineGlobalColor("G3", CreateColor(0, 186, 0));  #Green
DefineGlobalColor("G4", CreateColor(0, 167, 0));  #Green
DefineGlobalColor("G5", CreateColor(0, 151, 0));  #Green
DefineGlobalColor("G6", CreateColor(0, 136, 0));  #Green
DefineGlobalColor("G7", CreateColor(0, 122, 0));  #Green
DefineGlobalColor("G8", CreateColor(0, 109, 0));  #Green
DefineGlobalColor("G9", CreateColor(0, 98, 0));  #Green
DefineGlobalColor("R0", CreateColor(255, 0, 0));  #Red
DefineGlobalColor("R1", CreateColor(224, 0, 0));  #Red
DefineGlobalColor("R2", CreateColor(197, 0, 0));  #Red
DefineGlobalColor("R3", CreateColor(174, 0, 0));  #Red
DefineGlobalColor("R4", CreateColor(153, 0, 0));  #Red
DefineGlobalColor("R5", CreateColor(135, 0, 0));  #Red
DefineGlobalColor("R6", CreateColor(118, 0, 0));  #Red
DefineGlobalColor("R7", CreateColor(104, 0, 0));  #Red
DefineGlobalColor("R8", CreateColor(92, 0, 0));  #Red
DefineGlobalColor("R9", CreateColor(81, 0, 0));  #Red

upperEMADLinePlot.HideTitle();
upperEMADLinePlot.HideBubble();
upperEMADLinePlot.AssignValueColor(
    if (lowerEMADLinePlot > upperEMADLinePlot) then createcolor(153, 0, 0)
    else if (lowerEMADLinePlot < upperEMADLinePlot) then createcolor(0, 167, 0)
    else GlobalColor("Gray")
);
lowerEMADLinePlot.HideTitle();
lowerEMADLinePlot.HideBubble();
lowerEMADLinePlot.AssignValueColor(
    if (lowerEMADLinePlot > upperEMADLinePlot) then Color.red
    else if (lowerEMADLinePlot < upperEMADLinePlot) then Color.green
    else GlobalColor("Gray")
);
masterEMADLinePlot2.HideTitle();
masterEMADLinePlot2.HideBubble();
masterEMADLinePlot2.SetLineWeight(emadLineWeight);
masterEMADLinePlot2.AssignValueColor(
    if masterEMADLinePlot > masterEMADLinePlot[2] then createColor(0, 186, 0)
    else if masterEMADLinePlot < masterEMADLinePlot[2] then createColor(174, 0, 0)
    else GlobalColor("Gray")
);
zeroLine.HideTitle();
zeroLine.HideBubble();
zeroLine.AssignValueColor(
    if (upperEMADLinePlot > zeroLine) then  Color.green
    else if (upperEMADLinePlot < zeroLine) then  Color.red
    else GlobalColor("Yellow")
);
topBandPlot.HideTitle();
topBandPlot.HideBubble();
topBandPlot.AssignValueColor(
    if bothBandsDown then Color.dark_red
    else if bothBandsUp then color.Dark_green
    else if topBandStepUp then Color.green
    else if topBandStepDown then Color.red
    else if bearBias then  Color.yellow
    else GlobalColor("Gray")
);
bottomBandPlot.HideTitle();
bottomBandPlot.HideBubble();
bottomBandPlot.AssignValueColor(
    if bothBandsDown then Color.dark_red
    else if bothBandsUp then color.Dark_green
    else if bottomBandStepUp then Color.green
    else if bottomBandStepDown then Color.red
    else if bullBias then Color.yellow
    else  GlobalColor("Gray")
);
AddLabel(yes, " EMAD RANGE V1000 ", color.WHITE);
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Bullish: Observe cloud prior to reversal " else " Bullish ", color.dark_green);       
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Bearish: Observe cloud prior to reversal " else " Bearish ", color.dark_red);         
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Vix Alert4: Bounce incoming " else " Vix Alert4 ", color.cyan);       
AddLabel(ShowColorCodeLabel, 
    if  showHowToLabel then " Seller Exhaustion: Watch for pullback / reversal when exhaustion ends " else " Seller Exhaustion ",  color.light_red); 
AddLabel(ShowColorCodeLabel, 
    if  showHowToLabel then " Seller Exhaustion: Watch for pullback / reversal when exhaustion ends " else " Buyer Exhaustion ",  color.light_green); 
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Neutral: Direction not confirmed " else " Neutral ",  color.gray); 
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Squeeze: (non-directional) potential strong move incoming " else " Squeeze ",  color.yellow); 
#####################################################
##                                                 ##
#####################################################
AddCloud(if showEMACloud and (made1 > masterEMADLinePlot) then made1 else Double.NaN, masterEMADLinePlot, Color.dark_red, Color.gray);
AddCloud(if showEMACloud and (masterEMADLinePlot >= made) then masterEMADLinePlot else Double.NaN, made,  Color.dark_green, Color.gray);
#####################################################
##                                                 ##
#####################################################
AddChartBubble(showBubbles and crossesUpline and crossesUpline_filter, midBand, "Wait for HL", GlobalColor("Green"), no);
AddChartBubble(showBubbles and crossesDownline and crossesDownline_filter, midBand,"Wait for LH" , GlobalColor("Red"), yes);
#####################################################
##                                                 ##
#####################################################
AddVerticalLine(showVerticalline and crossesUpline and crossesUpline_filter, "", GlobalColor("Green"), no);
AddVerticalLine(showVerticalline and crossesDownline and crossesDownline_filter,"" , GlobalColor("Red"), yes);
 
Hi @tosman!
It can be adjusted by using the ATR factor and ATR period to trade with just about any timeframe or asset (if mult is adjusted to match the asset). It’s really just up to the trader’s preference. I have shared a few of the timeframes and settings I like on the /es 3min and 15 min charts(although I’m sure they can be improved). As you have chance to play around with indicator, if y’all find good settings for various assets you are trading, please feel free to share them.
Hi @Christopher84 ,
Is it possible to make TS an MTF Study with just the arrows only? For example, making it possible to place a 15min TS_Study on a 1min chart.
 
i did turn it off but it still there haha i dont know why? . What the differences between this one and lasted one? I do like this one with the cloud 😂
 
Last edited by a moderator:
Yes i have posted a few a couple pages back. Also posted a watchlist column which can be set to whatever timeframe.
To make it as "light" as possible on the system, below is what I have as a simplified TS_Study. Is it possible to add a 15min aggregation to this so that it could be placed onto a 1min chart as a confirmation measure? Thank you for your time.

#TS Strategy Created by Christopher84 08/10/2021
#Modified 05/23/2022 to include Chart Bubbles and Labels.

input trailType = {default modified, unmodified};
input ATRPeriod = 10;
input ATRFactor = 0.7;
input firstTrade = {default long, short};
input averageType = AverageType.SIMPLE;
input price = close;
input coloredCandlesOn = NO;

Assert(ATRFactor > 0, "'atr factor' must be positive: " + ATRFactor);

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
then high - close[1]
else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
then close[1] - low
else (close[1] - low) - 0.5 * (low[1] - high);

def trueRange;
switch (trailType) {
case modified:
trueRange = Max(HiLo, Max(HRef, LRef));
case unmodified:
trueRange = TrueRange(high, close, low);
}
def loss = ATRFactor * MovingAverage(averageType, trueRange, ATRPeriod);

def state = {default init, long, short};
def trail;
switch (state[1]) {
case init:
if (!IsNaN(loss)) {
switch (firstTrade) {
case long:
state = state.long;
trail = close - loss;
case short:
state = state.short;
trail = close + loss;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (close > trail[1]) {
state = state.long;
trail = Max(trail[1], close - loss);
} else {
state = state.short;
trail = close + loss;
}
case short:
if (close < trail[1]) {
state = state.short;
trail = Min(trail[1], close + loss);
} else {
state = state.long;
trail = close - loss;
}
}

def TrailingStop = trail;
def LongEnter = (price crosses above trailingStop);
def LongExit = (price crosses below trailingStop);

def upsignal = (price crosses above trailingStop);;
def downsignal = (price crosses below trailingStop);

###------------------------------------------------------------------------------------------
# Profit and Loss Labels
#
# Fill in the 0>0 in the Create Signals section below to match your buy and sell signal conditions
#
# When using large amounts of hisorical data, P/L may take time to calculate
###------------------------------------------------------------------------------------------

input showSignals = yes; #hint showSignals: show buy and sell arrows
input LongTrades = yes; #hint LongTrades: perform long trades
input ShortTrades = yes; #hint ShortTrades: perform short trades
input showLabels = no; #hint showLabels: show PL labels at top
input showBubbles = no; #hint showBubbles: show PL bubbles at close of trade
input useStops = no; #hint useStops: use stop orders
input useAlerts = YES; #hint useAlerts: use alerts on signals
input tradeDaytimeOnly = NO; #hint tradeDaytimeOnly: (IntraDay Only) Only perform trades during hours stated
input OpenTime = 0930; #hint OpenTime: Opening time of market
input CloseTime = 1600; #hint CloseTime: Closing time of market


def Begin = secondsfromTime(OpenTime);
def End = secondsTillTime(closetime);
# Only use market hours when using intraday timeframe
def isIntraDay = if getaggregationperiod() > 14400000 or getaggregationperiod()==0 then 0 else 1;
def MarketOpen = if !tradeDaytimeOnly or !isIntraDay then 1 else if tradeDaytimeOnly and isIntraDay and Begin > 0 and End > 0 then 1 else 0;
###------------------------------------------------------------------------------------------

######################################################
## Create Signals -
## FILL IN THIS SECTION
## replace 0>0 with your conditions for signals
######################################################

def PLBuySignal = if MarketOpen AND (upsignal) then 1 else 0 ; # insert condition to create long position in place of the 0>0
def PLSellSignal = if MarketOpen AND (downsignal) then 1 else 0; # insert condition to create short position in place of the 0>0

def PLBuyStop = if !useStops then 0 else if (0>0) then 1 else 0 ; # insert condition to stop in place of the 0<0
def PLSellStop = if !useStops then 0 else if (0>0) then 1 else 0 ; # insert condition to stop in place of the 0>0

def PLMktStop = if MarketOpen[-1] == 0 then 1 else 0; # If tradeDaytimeOnly is set, then stop at end of day


#######################################
## Maintain the position of trades
#######################################

def CurrentPosition; # holds whether flat = 0 long = 1 short = -1

if (BarNumber()==1) OR isNaN(CurrentPosition[1]) {
CurrentPosition = 0;
}else{
if CurrentPosition[1] == 0 { # FLAT
if (PLBuySignal AND LongTrades) {
CurrentPosition = 1;
} else if (PLSellSignal AND ShortTrades){
CurrentPosition = -1;
} else {
CurrentPosition = CurrentPosition[1];
}
} else if CurrentPosition[1] == 1 { # LONG
if (PLSellSignal AND ShortTrades){
CurrentPosition = -1;
} else if ((PLBuyStop and useStops) or PLMktStop or (PLSellSignal AND ShortTrades==0)){
CurrentPosition = 0;
} else {
CurrentPosition = CurrentPosition[1];
}
} else if CurrentPosition[1] == -1 { # SHORT
if (PLBuySignal AND LongTrades){
CurrentPosition = 1;
} else if ((PLSellStop and useStops) or PLMktStop or (PlBuySignal and LongTrades==0)){
CurrentPosition = 0;
} else {
CurrentPosition = CurrentPosition[1];
}
} else {
CurrentPosition = CurrentPosition[1];
}
}


def isLong = if CurrentPosition == 1 then 1 else 0;
def isShort = if CurrentPosition == -1 then 1 else 0;
def isFlat = if CurrentPosition == 0 then 1 else 0;

Plot BuySig = if (((isShort[1] and LongTrades) or (isFlat[1] and LongTrades)) and PLBuySignal and showSignals) then 1 else 0;
BuySig.AssignValueColor(color.WHITE);
BuySig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySig.SetLineWeight(5);

#Alert(BuySig and useAlerts, "Buy Signal",Alert.bar,sound.Ding);
#Alert(BuySig and useAlerts, "Buy Signal",Alert.bar,sound.Ding);

Plot SellSig = if (((isLong[1] and ShortTrades) or (isFlat[1] and ShortTrades)) and PLSellSignal and showSignals) then 1 else 0;
SellSig.AssignValueColor(color.WHITE);
SellSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSig.SetLineWeight(5);

#Alert(SellSig and useAlerts, "Sell Signal",Alert.bar,sound.Bell);
#Alert(SellSig and useAlerts, "Sell Signal",Alert.bar,sound.Bell);
 
Updated EMAD Range V1000

Updated calculation to plot arrows

EMAD Range (newest variant "V1000") - http://tos.mx/5jmDs9c

2k8hZIM.png


Code:
#EMAD Range by @ Christopher84
#EMAD V1000 - added arrow conditions - histogram - and color conditions HODL

#DECLARATIONS
declare lower;


#USER INPUTS
input showHLLH = no;
input showHowToLabel = yes;
input ShowColorCodeLabel = no;
input showtestlabels = no;
input showEMACloud = yes;
input showBubbles = no;
input showTripleExh = yes;
input showehlers = no;
input showMAD = no;
input showverticalline = yes;
input bandLength = 100;
input bandLength2 = 100;
input ELlength = 34;
Input LengtH_MAD = 4;
input fastLength = 10;
input slowLength = 35;
input lengthBAD = 3;
input smoothLength = 12;
input smoothLength2 = 14;
input ATRPeriod = 5;
input ATRFactor = 2.0;
input length_3x = 1000;
input priceType = close;
input emadLineWeight = 2;
input averageType = AverageType.WILDERS;
input averageType_Sq = AverageType.SIMPLE;
input firstTrade_Sq = {default long, short};
input trailType = {default modified, unmodified};
input firstTrade = {default long, short};
input filterBounceArrows = 1;
input filter_3x = 50;
input Control_3x = 3;
input crossabovebelowzero = 20;
input bandlengthbottom2 = 3;
input Lookback = 20;
input cloudlinelook = 20;
input LHHL_Lookback = 1;
input Steplookback = 10;
input filterZeroline = 20;
input topbanddownlookback = 1;
input bottombanduplookback = 1;
input SqueezeLook = 5;
input alert4lookback = 21;
input PreviousStepsDown = 2;
input PreviousStepsUp = 2;
input alert4control = 2;
input tradeDaytimeOnly = yes; #hint tradeDaytimeOnly: (IntraDay Only) Only perform trades during hours stated
input OpenTime = 0730; #hint OpenTime: Opening time of market
input CloseTime = 1800; #hint CloseTime: Closing time of market

def bn = barnumber();
def Begin = SecondsFromTime(OpenTime);
def End = SecondsTillTime(CloseTime);
def isIntraDay = if GetAggregationPeriod() > 14400000 or GetAggregationPeriod() == 0 then 0 else 1;
def MarketOpen = if !tradeDaytimeOnly or !isIntraDay then 1 else if tradeDaytimeOnly and isIntraDay and Begin > 0 and End > 0 then 1 else 0;

#GLOBAL COLOR DEFINITIONS
DefineGlobalColor("Green", CreateColor(0, 155, 0));
DefineGlobalColor("Red", CreateColor(225, 105, 105));
DefineGlobalColor("Gray", CreateColor(192, 192, 192));
DefineGlobalColor("Yellow", CreateColor(231, 190, 0));

## UPPER EMAD LINE
def fastExpAvg = ExpAverage(priceType, fastLength);
def slowExpAvg = ExpAverage(priceType, slowLength);
def EMAD = (priceType - fastExpAvg);
def EMAD2 = (priceType - slowExpAvg);
def EMADAvg = (EMAD + EMAD2) / 2;
def upperEMADLine = ExpAverage(EMADAvg, smoothLength);
## LOWER EMAD LINE
def emadOpen = (upperEMADLine + upperEMADLine[1]) / 2;
def emadHigh = Max(upperEMADLine, upperEMADLine[1]);
def emadLow = Min(upperEMADLine, upperEMADLine[1]);
def emadClose = upperEMADLine;
def bottom = Min(emadClose[1], emadLow);
def tr = TrueRange(emadHigh, emadClose, emadLow);
def ptr = tr / (bottom + tr / 2);
def APTR = MovingAverage(averageType, ptr, smoothLength2);
def upperBand = emadClose[1] + (APTR * emadOpen);
def lowerBand = emadClose[1] - (APTR * emadOpen);
def lowerEMADLine = (upperBand + lowerBand) / 2;
## TOP AND BOTTOM BANDS
def zeroLineData = if IsNaN(close) then Double.NaN else 0;
def EMADSUp = upperEMADLine > zeroLineData;
def EMADSDown = upperEMADLine < zeroLineData;
def EMADdown = (lowerEMADLine > upperEMADLine);
def EMADup = (upperEMADLine >= lowerEMADLine);
def topBand = Highest(lowerEMADLine, bandLength);
def bottomBand = Lowest(lowerEMADLine, bandLength);
def zerolinedatacondition = if (zerolinedata > topBand) then topBand else if (zerolinedata < bottomBand) then bottomBand else 0;
## Master
def masteremadline = (upperEMADLine + lowerEMADLine) / 2;
## BAND DIRECTION (USED ONLY FOR COLORING - NOT USED FOR PLOTS)
def topBandStepDown = if topBand < topBand[1] then 1 else 0;
def topBandStepUp = if topBand > topBand[1] then 1 else 0;
def bottomBandStepDown = if bottomBand < bottomBand[1] then 1 else 0;
def bottomBandStepUp = if bottomBand > bottomBand[1] then 1 else 0;
def bothBandsDown = bottomBandStepDown and topBandStepDown;
def bothBandsUp = bottomBandStepUp and topBandStepUp;
def bullBias = (bottomBand > zeroLineData);
def bearBias = (topBand < zeroLineData);
## BUBBLE CALCULATIONS (USED ONLY FOR BUBBLES)
def midBand = (upperBand + lowerBand) / 2;
def crossesUp = if (midBand[1] > upperEMADLine[1])and(midBand < upperEMADLine) then 1 else 0;
def crossesDown = if (upperEMADLine[1] > midBand[1])and(upperEMADLine < midBand) then 1 else 0;
def valueUp = if crossesUp then midBand else 0;
def valueDown = if crossesDown then midBand else 0;
def crossesUpline = if (valueUp - bottomBand) == 0 then 1 else 0;
def crossesDownline = if (valueDown - topBand) == 0 then 1 else 0;
def crossesUpline_filter = if crossesUpline and (crossesUpline[1] or crossesUpline[2]  or crossesUpline[3]   or crossesUpline[4])then 0 else 1;
def crossesDownline_filter = if crossesDownline and (crossesDownline[1] or crossesDownline[2]  or crossesDownline[3]   or crossesDownline[4])then 0 else 1;
def crossesUpZeroline = if (valueUp) == 0 then 1 else 0;
def crossesDownZeroline = if (valueDown) == 0 then 1 else 0;
def crossesUpBottomlinebn = if crossesUpline and !crossesUpline[1] then bn else crossesUpBottomlinebn[1];
def crossesDownToplinebn = if crossesDownline and !crossesDownline[1] then bn else crossesDownToplinebn[1];
def crossuplinewithin = if crossesUpBottomlinebn < bn then bn - crossesUpBottomlinebn else crossuplinewithin[1];
def crossdownlinewithin = if crossesDownToplinebn < bn then bn - crossesDownToplinebn else crossdownlinewithin[1];
def crosslinefirst = if crossuplinewithin < crossdownlinewithin then 1 else 0;
def crosslinelogic = crossesUpBottomlinebn > crossesDownToplinebn;
def HL = crossesUpline == 0 and crossesDownline == 0 and upperEMADLine crosses above lowerEMADLine;  #Normal HL LH condition
def LH = crossesDownline == 0 and upperEMADLine crosses below lowerEMADLine; #Normal HL LH condition
def bounceUpOnce = crossesUpline <> crossesUpline[1]; #XUpBtm happened previous bar or on current bar
def bounceDnOnce = crossesDownline <> crossesDownline[1];
def trackCrUp = if bounceUpOnce then 0 else if HL then 1 else trackCrUp[1];
def trackCrDn = if bounceDnOnce then 0 else if LH then 1 else trackCrDn[1];
## SECOND HL AND LH
def HLalready = if trackCrUp and !trackCrUp[1] then 1 else 0;
def LHalready = if trackCrDn and !trackCrDn[1] then 1 else 0;
def HL2 = HLalready == 0 and upperEMADLine crosses above lowerEMADLine;
def LH2 = LHalready == 0 and upperEMADLine crosses below lowerEMADLine;
def crossedUpOnce = HLalready <> HLalready[1];
def crossedDnOnce = LHalready <> LHalready[1];
def trackCrUp2 = if crossedUpOnce then 0 else if HL2 then 1 else trackCrUp2[1];
def trackCrDn2 = if crossedDnOnce then 0 else if LH2 then 1 else trackCrDn2[1];
#####################################################
##                                                 ##
#####################################################
def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);
def trueRange_Sq;
switch (trailType) {
case modified:
    trueRange_Sq = Max(HiLo, Max(HRef, LRef));
case unmodified:
    trueRange_Sq = TrueRange(high, close, low);
}
def loss_Sq = ATRFactor * MovingAverage(averageType_Sq, trueRange_Sq, ATRPeriod);
def state_Sq = {default init, long, short};
def trail_Sq;
switch (state_Sq[1]) {
case init:
    if (!IsNaN(loss_Sq)) {
        switch (firstTrade) {
        case long:
            state_Sq = state_Sq.long;
            trail_Sq =  close - loss_Sq;
        case short:
            state_Sq = state_Sq.short;
            trail_Sq = close + loss_Sq;
    }
    } else {
        state_Sq = state_Sq.init;
        trail_Sq = Double.NaN;
    }
case long:
    if (close > trail_Sq[1]) {
        state_Sq = state_Sq.long;
        trail_Sq = Max(trail_Sq[1], close - loss_Sq);
    } else {
        state_Sq = state_Sq.short;
        trail_Sq = close + loss_Sq;
    }
case short:
    if (close < trail_Sq[1]) {
        state_Sq = state_Sq.short;
        trail_Sq = Min(trail_Sq[1], close + loss_Sq);
    } else {
        state_Sq = state_Sq.long;
        trail_Sq =  close - loss_Sq;
    }
}
def TrailingStop_Sq = trail_Sq;
def H = Highest(TrailingStop_Sq, 12);
def L = Lowest(TrailingStop_Sq, 12);
def BulgeLengthPrice = 100;
def SqueezeLengthPrice = 100;
def BandwidthC3 = (H - L);
def IntermResistance2 = Highest(BandwidthC3, BulgeLengthPrice);
def IntermSupport2 = Lowest(BandwidthC3, SqueezeLengthPrice);
def sqzTrigger = BandwidthC3 <= IntermSupport2;
def sqzLevel = if !sqzTrigger[1] and sqzTrigger then hl2 else if !sqzTrigger then Double.NaN else sqzLevel[1];
def Squeeze_Alert_1 = if sqzLevel then (upperEMADLine + lowerEMADLine) / 2 else (upperEMADLine + lowerEMADLine) / 2 ;
#####################################################
##                                                 ##
#####################################################
def over_bought_3x = 80;
def over_sold_3x = 20;
def KPeriod_3x = 10;
def DPeriod_3x = 10;
def priceH1 = high;
def priceL1 = low;
def priceC1 = close;
def priceO1 = close;
def priceH_3x = high;
def priceL_3x = low;
def priceC_3x = close;  
def SlowK_3x = reference StochasticFull(over_bought_3x,  over_sold_3x,  KPeriod_3x,  DPeriod_3x,  priceH_3x,  priceL_3x,  priceC_3x,  3, if (averageType == 1) then AverageType.SIMPLE else AverageType.EXPONENTIAL).FullK;
def MACD_3x = reference MACD()."Value";
def priceMean_3x = Average(MACD_3x, length_3x);
def MACD_stdev_3x =  (MACD_3x - priceMean_3x) / StDev(MACD_3x, length_3x);
def dPlus_3x = reference DMI()."DI+";
def dMinus_3x = reference DMI()."DI-";
def sellerRegular = SlowK_3x < 20 and MACD_stdev_3x < -1 and dPlus_3x < 15;
def sellerExtreme = SlowK_3x < 20 and MACD_stdev_3x < -2 and dPlus_3x < 15;
def buyerRegular = SlowK_3x > 80 and MACD_stdev_3x > 1 and dMinus_3x < 15;
def buyerExtreme = SlowK_3x > 80 and MACD_stdev_3x > 2 and dMinus_3x < 15;  
def ExtremeBuy1 = if sellerExtreme[1] and !sellerExtreme then 1 else 0;
def ExtremeSell1 = if buyerExtreme[1] and !buyerExtreme then 1 else 0;
def RegularSell1 = if buyerRegular[1] and !buyerRegular then 1 else 0;
def RegularBuy1= if sellerRegular[1] and !sellerRegular then 1 else 0;
#####################################################
##                                                 ##
#####################################################
def priceE = (emadhigh + emadlow) / 2;
def coeff = ELlength * priceE * priceE - 2 * priceE * sum(priceE, ELlength)[1] + sum(priceE * priceE, ELlength)[1];
def Ehlers =  sum(coeff * priceE, ELlength) / sum(coeff, ELlength);
#####################################################
##                                                 ##
#####################################################
def dataA = masterEMADLine;
def dataA1 =
    fold aD = 0
    to LengtH_MAD
    with k = 0
    do k + dataA[aD];
def MAEMAD = dataA1 / LengtH_MAD;
def MAD = MAEMAD;
def ElCrossDN = ehlers crosses above masterEMADline;
def ElCrossUP = ehlers crosses below masterEMADline;
def bullBias2 = (emadsup);
def bearBias2 = (emadsdown);
def MADehlers = (MAD - Ehlers)/2;
def Madebad = madehlers + ehlers;
def madebadavg = average(madebad, lengthBAD);
def crossmadeup = madebad > madebad[1];
def crossmadedn = madebad < madebad[1];
def crossmade2up = if (madebad < masterEMADLine) and crossmadeup and (bullBias2 > 0) then 1 else 0;
def crossmade2dn = if (madebad > masterEMADLine) and crossmadedn and (bearBias2 > 0) then 1 else 0;
def crossmade2 = if (madebad < masterEMADLine) and crossmadeup and (bullBias2 > 0) then 1 else if (madebad > masterEMADLine) and crossmadedn and (bearBias2 > 0) then -1 else 0;
def crossmade0 = if (!crossmade2[1] or !crossmade2[1]) and (crossmade2 == 0) then 1 else 0;
#####################################################
##                                                 ##
#####################################################
def pd = 22;
def bbl = 20;
def mult = 2.0;
def lb = 50;
def ph = 0.85;
def ltLB = 40;
def mtLB = 14;
def str = 3;
def wvf = ((Highest(close, pd) - low) / (Highest(close, pd))) * 100;
def sDev = mult * StDev(wvf, bbl);
def midLine1 = SimpleMovingAvg(wvf, bbl);
def lowerBand1 = midLine1 - sDev;
def upperBand1 = midLine1 + sDev;
def rangeHigh = (Highest(wvf, lb)) * ph;
def upRange = low > low[1] and close > high[1];
def upRange_Aggr = close > close[1] and close > open[1];
def filtered = ((wvf[1] >= upperBand1[1] or wvf[1] >= rangeHigh[1]) and (wvf < upperBand1 and wvf < rangeHigh));
def filtered_Aggr = (wvf[1] >= upperBand1[1] or wvf[1] >= rangeHigh[1]);
def alert4 = upRange_Aggr and close > close[str] and (close < close[ltLB] or close < close[mtLB]) and filtered_Aggr;
def alert4close = if alert4 then close else 0;
def crossmade = if (madebad < masterEMADLine) and crossmadeup then 1 else if (madebad > masterEMADLine) and crossmadedn then -1 else 0;
def madedn = (madebad > masterEMADLine);
def madeup = (madebad < masterEMADLine);
def made2 = madebadavg;
def made3 = if !madedn and (made2 <= zerolinedata) then madebadavg else double.nan;
def made4 = if !madeup and (made2 >= zerolinedata) then madebadavg else double.nan;
def madecrossupavg = if made2 crosses below masterEMADLine then 1 else 0;
def madecrossdownavg = if made2 crosses above masterEMADLine then 1 else 0;
def crossmadelogicup = if madecrossupavg and !madecrossupavg[1] then 1 else 0;
def crossmadelogicdown = if madecrossdownavg and !madecrossdownavg[1] then 1 else 0;
def crossmademorelogicup = if crossmadelogicup and crosslinelogic and emadup[1] then 1 else 0;
def crossmademorelogicdown = if crossmadelogicdown and !crosslinelogic and emaddown[1] then 1 else 0;
def EmaPushStepUp = if topBandStepUp and EmadUp and (((upperEMADLine) - bottomband) == 0) then 1 else 0;;
def EmaPushStepDown = if bottomBandStepDown and EmadDown and (((lowerEMADLine) - bottomband) == 0) then 1 else 0;
def HLFilter = if HL[1] < HL then 1 else 0;
def LHFilter = if LH[1] > LH then 1 else 0;
def HLFilter2 = if HL[2] < HL[1] then 1 else 0;
def LHFilter2 = if LH[2] > LH[1] then 1 else 0;
#####################################################
##                                                 ##
#####################################################
def ValueUp_lookback = fold index1 = 1 to filterBounceArrows with x1 do x1 + absvalue(valueUp)[index1];
def ValueDown_lookback = fold index2 = 1 to filterBounceArrows with x2 do x2 + absvalue(valueDown)[index2];
def topBandStepDown_lookback = fold index3 = 1 to Steplookback with x3 do x3 + topBandStepDown[index3];
def topBandStepUp_lookback = fold index4 = 1 to Steplookback with x4 do x4 + topBandStepUp[index4];
def bottomBandStepDown_lookback = fold index5 = 1 to Steplookback with x5 do x5 + bottomBandStepDown[index5];
def bottomBandStepUp_lookback = fold index6 = 1 to Steplookback with x6 do x6 + bottomBandStepUp[index6];
def bothBandsDown_lookback = fold index7 = 1 to filterBounceArrows with x7 do x7 + bothBandsDown[index7];
def bothBandsUp_lookback = fold index8 = 1 to filterBounceArrows with x8 do x8 + bothBandsUp[index8];
def bullBias_lookback = fold index9 = 1 to filterBounceArrows with x9 do x9 + bullBias[index9];
def bearBias_lookback = fold index10 = 1 to filterBounceArrows with x10 do x10 + bearBias[index10];
def crossesUpZeroline_lookback = fold index11 = 1 to filterZeroline with x11 do x11 + crossesUpZeroline[index11];
def crossesDownZeroline_lookback = fold index12 = 1 to filterZeroline with x12 do x12 + crossesDownZeroline[index12];
def crossesUpBottomline_lookback = fold index13 = 1 to filterBounceArrows with x13 do x13 + crossesUpline[index13];
def crossesDownTopline_lookback = fold index14 = 1 to filterBounceArrows with x14 do x14 + crossesDownline[index14];
def CrossedUPaboveZero_lookback = fold index15 = 1 to crossabovebelowzero with x15 do x15 + crossesUpZeroline[index15];
def CrossedDOWNbelowZero_lookback = fold index16 = 1 to crossabovebelowzero with x16 do x16 + crossesDownZeroline[index16];
def HL_lookback = fold index17 = 1 to LHHL_Lookback with x17 do x17 + HL[index17];
def LH_lookback = fold index18 = 1 to LHHL_Lookback with x18 do x18 + LH[index18];
def upabovezero_lookback = fold index19 = 1 to crossabovebelowzero with x19 do x19 + HL[index19];
def downbelowzero_lookback = fold index20 = 1 to crossabovebelowzero with x20 do x20 + LH[index20];
def PriceMonitor = fold index21 = 1 to crossabovebelowzero with x21 do x21 + HL[index21];
def ExtremeBuy1_lookback = fold index24 = 1 to filter_3x with x24 do x24 + ExtremeBuy1[index24];
def ExtremeSell1_lookback = fold index25 = 1 to filter_3x with x25 do x25 + ExtremeSell1[index25];
def RegularSell1_lookback = fold index26 = 1 to filter_3x with x26 do x26 + RegularSell1[index26];
def RegularBuy1_lookback = fold index27 = 1 to filter_3x with x27 do x27 + RegularBuy1[index27];
def Squeeze_lookback = fold index28 = 1 to SqueezeLook with x28 do x28 + Squeeze_Alert_1[index28];
def ElCrossDN_lookback = fold index29 = 1 to filterBounceArrows with x29 do x29 + ElCrossDN[index29];
def ElCrossUP_lookback = fold index30 = 1 to filterBounceArrows with x30 do x30 + ElCrossUP[index30];
def bearBias2_lookback = fold index31 = 1 to filterBounceArrows with x31 do x31 + bearBias2[index31];
def bullBias2_lookback = fold index32 = 1 to filterBounceArrows with x32 do x32 + bullBias2[index32];
def crossmade0_lookback = fold index33 = 1 to cloudlinelook with x33 do x33 + crossmade0[index33];
def alert4_lookback = fold index34 = 1 to alert4lookback with x34 do x34 + alert4close[index34];
#####################################################
##                                                 ##
#####################################################
def bubblehidertopdown = topBandStepDown_lookback > PreviousStepsDown;
def bubblehidertopup = topBandStepup_lookback > PreviousStepsUp;
def bubblehiderbottomdown = bottomBandStepDown_lookback > PreviousStepsDown;
def bubblehiderbottomup = bottomBandStepup_lookback > PreviousStepsUp;
def UP1 = if marketopen and (!bubblehidertopdown or !bubblehiderbottomdown) and !EmaPushStepDown and crossmademorelogicup then midBand else double.nan;
def DOWN1 = if marketopen and (!bubblehidertopup or !bubblehiderbottomup) and !EmaPushStepUp and crossmademorelogicdown then midBand else double.nan;
#####################################################
##                                                 ##
#####################################################
plot zeroLine = zerolinedata;
plot Squeeze_Alert = if sqzLevel then (upperEMADLine + lowerEMADLine) / 2 else (upperEMADLine + lowerEMADLine) / 2 ;
plot ExtremeBuy = if showTripleExh and sellerExtreme[1] and !sellerExtreme then midband else Double.NaN;
plot ExtremeSell = if showTripleExh and buyerExtreme[1] and !buyerExtreme then midband else Double.NaN;
plot RegularSell = if showTripleExh and buyerRegular[1] and !buyerRegular then midband else Double.NaN;
plot RegularBuy = if showTripleExh and sellerRegular[1] and !sellerRegular then midband else Double.NaN;
plot topBandPlot = topBand;
plot bottomBandPlot = bottomBand;
plot upperEMADLinePlot = upperEMADLine;
plot lowerEMADLinePlot = lowerEMADLine;
plot masterEMADLinePlot2 = (upperEMADLine + lowerEMADLine) / 2;
plot masterEMADLinePlot = ((upperEMADLinePlot + lowerEMADLinePlot) / 2);
plot made1 = made4;
plot made = made3;
plot UP = UP1;
plot DOWN = DOWN1;
plot firstHL = if showHLLH and trackCrUp and !trackCrUp[1] then lowerEMADLine else double.nan;
plot firstLH = if showHLLH and trackCrDn and !trackCrDn[1] then lowerEMADLine else double.nan;
plot secondHL = if showHLLH and trackCrUp2 and !trackCrUp2[1] and !crossesUpline then lowerEMADLine else double.nan;
plot secondLH = if showHLLH and trackCrDn2 and !trackCrDn2[1] and !crossesDownline then lowerEMADLine else double.nan;
#####################################################
##                                                 ##
#####################################################
def firstHL2 = if trackCrUp and !trackCrUp[1] then 1 else 0;
def firstLH2 = if trackCrDn and !trackCrDn[1] then 1 else 0;
def HLBuy = if firstHL2 and regularsell1 or extremesell1 then 1 else 0;
def LHSell = if firstHL2 and regularbuy1 or extremebuy1 then 1 else 0;
#####################################################
##                                                 ##
#####################################################
UP.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UP.SetLineWeight(1);
UP.SetDefaultColor(Color.white);
UP.HideBubble();
UP.HideTitle();
#####################################################
##                                                 ##
#####################################################
DOWN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DOWN.SetLineWeight(1);
DOWN.SetDefaultColor(Color.white);
DOWN.HideBubble();
DOWN.HideTitle();
#####################################################
##                                                 ##
#####################################################
made1.AssignValueColor(
     if crossmade2 == 1 then color.dark_green
else if crossmade2 == -1 then color.dark_red
else if crossmade0_lookback > 1 and crosslinelogic then Color.gray
else color.dark_red);
#####################################################
##                                                 ##
#####################################################
made.AssignValueColor(
     if crossmade2 == 1 then color.dark_green
else if crossmade2 == -1 then color.dark_red
else if crossmade0_lookback > 1 and crosslinelogic then Color.gray
else color.dark_red);
#####################################################
##                                                 ##
#####################################################
Squeeze_Alert.SetPaintingStrategy(PaintingStrategy.line);
Squeeze_Alert.SetLineWeight(2);
Squeeze_Alert.SetDefaultColor(Color.YELLOW);
#####################################################
##                                                 ##
#####################################################
RegularBuy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ExtremeBuy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
RegularSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ExtremeSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#####################################################
##                                                 ##
#####################################################
RegularBuy.SetLineWeight((1));
ExtremeBuy.SetLineWeight((1));
RegularSell.SetLineWeight((1));
ExtremeSell.SetLineWeight((1));
#####################################################
##                                                 ##
#####################################################
ExtremeSell.SetDefaultColor((Color.WHITE));
ExtremeBuy.SetDefaultColor((Color.WHITE));
RegularBuy.SetDefaultColor((Color.white));
RegularSell.SetDefaultColor((Color.white));
#####################################################
##                                                 ##
#####################################################
firstHL.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
firstHL.SetLineWeight(1);
firstHL.SetDefaultColor(Color.blue);
firstHL.HideBubble();
firstHL.HideTitle();
#####################################################
##                                                 ##
#####################################################
firstLH.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
firstLH.SetLineWeight(1);
firstLH.SetDefaultColor(Color.blue);
firstLH.HideBubble();
firstLH.HideTitle();
#####################################################
##                                                 ##
#####################################################
secondHL.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
secondHL.SetLineWeight(1);
secondHL.SetDefaultColor(Color.CYAN);
secondHL.HideBubble();
secondHL.HideTitle();
#####################################################
##                                                 ##
#####################################################
secondLH.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
secondLH.SetLineWeight(1);
secondLH.SetDefaultColor(Color.CYAN);
secondLH.HideBubble();
secondLH.HideTitle();
#####################################################
##                                                 ##
#####################################################
masterEMADLinePlot.SetPaintingStrategy(PaintingStrategy.histogram);
masterEMADLinePlot.HideBubble();
masterEMADLinePlot.SetLineWeight(1);
masterEMADLinePlot.AssignValueColor(
     if alert4 then color.cyan
else if HLBuy then color.light_green
else if LHSell then color.light_red
else if crossmade2up then Color.dark_green
else if crossmade2dn then color.dark_red
else if crossmade0_lookback > 1 and crosslinelogic then Color.dark_gray
else color.dark_red
);
DefineGlobalColor("G0", CreateColor(0, 255, 0));  #Green
DefineGlobalColor("G1", CreateColor(0, 229, 0));  #Green
DefineGlobalColor("G2", CreateColor(0, 206, 0));  #Green
DefineGlobalColor("G3", CreateColor(0, 186, 0));  #Green
DefineGlobalColor("G4", CreateColor(0, 167, 0));  #Green
DefineGlobalColor("G5", CreateColor(0, 151, 0));  #Green
DefineGlobalColor("G6", CreateColor(0, 136, 0));  #Green
DefineGlobalColor("G7", CreateColor(0, 122, 0));  #Green
DefineGlobalColor("G8", CreateColor(0, 109, 0));  #Green
DefineGlobalColor("G9", CreateColor(0, 98, 0));  #Green
DefineGlobalColor("R0", CreateColor(255, 0, 0));  #Red
DefineGlobalColor("R1", CreateColor(224, 0, 0));  #Red
DefineGlobalColor("R2", CreateColor(197, 0, 0));  #Red
DefineGlobalColor("R3", CreateColor(174, 0, 0));  #Red
DefineGlobalColor("R4", CreateColor(153, 0, 0));  #Red
DefineGlobalColor("R5", CreateColor(135, 0, 0));  #Red
DefineGlobalColor("R6", CreateColor(118, 0, 0));  #Red
DefineGlobalColor("R7", CreateColor(104, 0, 0));  #Red
DefineGlobalColor("R8", CreateColor(92, 0, 0));  #Red
DefineGlobalColor("R9", CreateColor(81, 0, 0));  #Red

upperEMADLinePlot.HideTitle();
upperEMADLinePlot.HideBubble();
upperEMADLinePlot.AssignValueColor(
    if (lowerEMADLinePlot > upperEMADLinePlot) then createcolor(153, 0, 0)
    else if (lowerEMADLinePlot < upperEMADLinePlot) then createcolor(0, 167, 0)
    else GlobalColor("Gray")
);
lowerEMADLinePlot.HideTitle();
lowerEMADLinePlot.HideBubble();
lowerEMADLinePlot.AssignValueColor(
    if (lowerEMADLinePlot > upperEMADLinePlot) then Color.red
    else if (lowerEMADLinePlot < upperEMADLinePlot) then Color.green
    else GlobalColor("Gray")
);
masterEMADLinePlot2.HideTitle();
masterEMADLinePlot2.HideBubble();
masterEMADLinePlot2.SetLineWeight(emadLineWeight);
masterEMADLinePlot2.AssignValueColor(
    if masterEMADLinePlot > masterEMADLinePlot[2] then createColor(0, 186, 0)
    else if masterEMADLinePlot < masterEMADLinePlot[2] then createColor(174, 0, 0)
    else GlobalColor("Gray")
);
zeroLine.HideTitle();
zeroLine.HideBubble();
zeroLine.AssignValueColor(
    if (upperEMADLinePlot > zeroLine) then  Color.green
    else if (upperEMADLinePlot < zeroLine) then  Color.red
    else GlobalColor("Yellow")
);
topBandPlot.HideTitle();
topBandPlot.HideBubble();
topBandPlot.AssignValueColor(
    if bothBandsDown then Color.dark_red
    else if bothBandsUp then color.Dark_green
    else if topBandStepUp then Color.green
    else if topBandStepDown then Color.red
    else if bearBias then  Color.yellow
    else GlobalColor("Gray")
);
bottomBandPlot.HideTitle();
bottomBandPlot.HideBubble();
bottomBandPlot.AssignValueColor(
    if bothBandsDown then Color.dark_red
    else if bothBandsUp then color.Dark_green
    else if bottomBandStepUp then Color.green
    else if bottomBandStepDown then Color.red
    else if bullBias then Color.yellow
    else  GlobalColor("Gray")
);
AddLabel(yes, " EMAD RANGE V1000 ", color.WHITE);
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Bullish: Observe cloud prior to reversal " else " Bullish ", color.dark_green);      
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Bearish: Observe cloud prior to reversal " else " Bearish ", color.dark_red);        
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Vix Alert4: Bounce incoming " else " Vix Alert4 ", color.cyan);      
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Seller Exhaustion: Watch for pullback / reversal when exhaustion ends " else " Seller Exhaustion ",  color.light_red);
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Seller Exhaustion: Watch for pullback / reversal when exhaustion ends " else " Buyer Exhaustion ",  color.light_green);
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Neutral: Direction not confirmed " else " Neutral ",  color.gray);
AddLabel(ShowColorCodeLabel,
    if  showHowToLabel then " Squeeze: (non-directional) potential strong move incoming " else " Squeeze ",  color.yellow);
#####################################################
##                                                 ##
#####################################################
AddCloud(if showEMACloud and (made1 > masterEMADLinePlot) then made1 else Double.NaN, masterEMADLinePlot, Color.dark_red, Color.gray);
AddCloud(if showEMACloud and (masterEMADLinePlot >= made) then masterEMADLinePlot else Double.NaN, made,  Color.dark_green, Color.gray);
#####################################################
##                                                 ##
#####################################################
AddChartBubble(showBubbles and crossesUpline and crossesUpline_filter, midBand, "Wait for HL", GlobalColor("Green"), no);
AddChartBubble(showBubbles and crossesDownline and crossesDownline_filter, midBand,"Wait for LH" , GlobalColor("Red"), yes);
#####################################################
##                                                 ##
#####################################################
AddVerticalLine(showVerticalline and crossesUpline and crossesUpline_filter, "", GlobalColor("Green"), no);
AddVerticalLine(showVerticalline and crossesDownline and crossesDownline_filter,"" , GlobalColor("Red"), yes);
@HODL-Lay-HE-hoo! Can you share your chart, this big 7 max setup looks interesting
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
327 Online
Create Post

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