Confirmation Candles Indicator For ThinkorSwim

Thank you! What's your favorite timeframe to use with the Scalper? How do you adjust it so it works on timeframes other than 1 minute? Is it recommended to have extended hours on or off? Hope you haven't answered these questions a hundred times already.. thank you! :)
If you take the time and go back a few pages, I believe you'll find the answers to your questions. Yes, there are over 50 pages here, but every single one of them is worth your time and effort to review. If it's just scalper or C3 Max info, you won't have to go back very far! Good luck! @Christopher84 has done outstanding work for this community!!!
 
Last edited:
Thank you! What's your favorite timeframe to use with the Scalper? How do you adjust it so it works on timeframes other than 1 minute? Is it recommended to have extended hours on or off? Hope you haven't answered these questions a hundred times already.. thank you! :)
Other than the 1 min, I like the 3 min with agperiod1 set to 3 min and agperiod2 set to 5 min. Those are the only two I change for the 3 min chart. (y)
 
Thank you! What's your favorite timeframe to use with the Scalper? How do you adjust it so it works on timeframes other than 1 minute? Is it recommended to have extended hours on or off? Hope you haven't answered these questions a hundred times already.. thank you! :)
Can you please provide the codes for the above? Thanks,
 
Can you please provide the codes for the above? Thanks,
Hi @majidg,
For a 3 min Chart, you just need to change agperiod1 to 3 min, and agperiod2 to 5min and you will have it. Here's a screenshot. Hope it helps! :)
lNC9adf.png
 
When the label says Bearish Look to Sell, its alerting you to the fact that the Keltner Channel is still in a downward orientation which most of the time indicates a mean reverting state where price is likely to be rejected near the average.
Ah, that is helpful! Looks like I need to do some reading on Keltner. Thank you for the explanation!
 
Hi @lolreconlol!
The Scalper helps to give a better picture of the overall trend environment. In the image below you can see TSLA has been SCALP_SHORT today. That means that more of the ema's are currently crossed down indicating a bearish trend. That being said, I would only be looking for scalps in the direction of the major trend. When the C3_MF_Line goes gray, those are opportunities to take profits or exit the trade. I hope this helps. Happy trading!
g0hasPM.png
mfKIWIm.png
 
My observation on the Scalper and C3_MAX_V2

  • I think the Scalper thing is so fast than the other one (obviously because the other one does so much calculation)
  • Scalper MAMA line is much more sensitive/jumpy for changes (because it is more on price and MA than the Consensus which depends on 10+ other studies)
  • Of course , nothing is 100% and i found few cases that after ur price moves up , it's better to move SL accordingly ( like Mar 10th 6.50 AM PST on /MES 10M it did turn Green for only 3 , 10 mins bar before turning full red again). That's okay if u monitor it.

Question is @Christopher84 , do u use this scalper (only for sccalping or even for swing trading).
FYI i did found that even for Day time ( if i change the period to 2 Days, 4 days , week ,month) it does good job.

I like to use just this Scalper as it is more cleaner (visually not overwhelming) :) to see ... feedback welcome
 
My observation on the Scalper and C3_MAX_V2

  • I think the Scalper thing is so fast than the other one (obviously because the other one does so much calculation)
  • Scalper MAMA line is much more sensitive/jumpy for changes (because it is more on price and MA than the Consensus which depends on 10+ other studies)
  • Of course , nothing is 100% and i found few cases that after ur price moves up , it's better to move SL accordingly ( like Mar 10th 6.50 AM PST on /MES 10M it did turn Green for only 3 , 10 mins bar before turning full red again). That's okay if u monitor it.

Question is @Christopher84 , do u use this scalper (only for sccalping or even for swing trading).
FYI i did found that even for Day time ( if i change the period to 2 Days, 4 days , week ,month) it does good job.

I like to use just this Scalper as it is more cleaner (visually not overwhelming) :) to see ... feedback welcome
Hi @easyman!
I have used the scalper with agperiod1 set to 1 hour, agperiod2 2 hours and so on (I’ll include a screenshot later if needed). It makes for some interesting swings.
 
Here is what I've come up with so far, trying to make this into MTF

*This isn't complete (Signals are needed, Testing) So if anyone wants a stab at it :p

I haven't changed any of the conditions from the original.
Market Forecast not coded MTF (Wasn't sure how to do that)

My brain is scrambled right now and I need a break but wanted to post what I have, if anyone wants to work on it in the meantime

And here it is
Code:
#C3_Max_v2 Created by Christopher84 12/14/2021
#MTF by RedtoGreen 3/11/2022   
# Based off of the Confirmation Candles Study. Main difference is that CC Candles weigh factors of positive
# and negative price movement to create the Consensus_Level. The Consensus_Level is considered positive if
# above zero and negative if below zero.

declare upper;

input agperiod1 = { "1 min", default "2 min", "3 min", "5 min", "10 min", "15 min", "30 min", "1 hour", "2 hours", "4 hours", "Day", "Week", "Month"};
input agperiod2 = {"1 min", "2 min", default "3 min", "5 min", "10 min", "15 min", "30 min", "1 hour", "2 hours", "4 hours", "Day", "Week", "Month"};
input agperiod3 = {"1 min", "2 min", "3 min", "5 min", default "10 min", "15 min", "30 min", "1 hour", "2 hours", "4 hours", "Day", "Week", "Month"};
input agperiod4 = {"1 min", "2 min", "3 min", "5 min", "10 min", "15 min", default "30 min", "1 hour", "2 hours", "4 hours", "Day", "Week", "Month"};
input agperiod5 = {"1 min", "2 min", "3 min", "5 min", "10 min", "15 min", "30 min", "1 hour", "2 hours", default "4 hours", "Day", "Week", "Month"};
input agperiod6 = {"1 min", "2 min", "3 min", "5 min", "10 min", "15 min", "30 min", "1 hour", "2 hours", "4 hours", default "Day", "Week", "Month"};

input price = CLOSE;
input ShortLength1 = 5;
input ShortLength2 = 14;
input ShortLength3 = 5;
input LongLength1 = 12;
input LongLength2 = 55;
input LongLength3 = 7;
input ATRPeriod2 = 5;
input ATRFactor2 = 1.5;
input Confirmation_Factor = 7;
input price2 = hl2;
input FastLimit = 0.5;
input SlowLimit = 0.05;
input extension_length_limited_to = 10;
input length8 = 10; #EMA CLOUD
input length9 = 35; #EMA CLOUD
input show_ema_cloud = yes;
input lengthSCA = 10;
input length2 = 35;
input DMIlength = 5;
input averageTypeDMI = AverageType.WILDERS;
input MALength = 13;#Klinger
input paintCandles = yes;
input coloredCandlesOn = yes;

# Momentum Oscillators

def MS = Average(Average(price, ShortLength1) - Average(price, ShortLength2), ShortLength3);
def MS2 = Average(Average(price, LongLength1) - Average(price, LongLength2), LongLength3);
# Wave A
def MSGreens = If (MS >= 0, MS, 0);
def MSReds = If (MS < 0, MS, 0);
# Wave C
def MS2Blues = If (MS2 >= 0, MS2, 0);
def MS2Yellows = If (MS2 < 0, MS2, 0);

def MayhemBullish = MSGreens > MSGreens[1] and  MS2Blues > MS2Blues[1];
def MayhemBearish =  MSReds < MSReds[1] and  MS2Yellows < MS2Yellows[1];

def MS_Pos = MSGreens;
def MS_Neg = MSReds;
def MS2_Pos = MS2Blues;
def MS2_Neg = MS2Yellows;

# Squeeze Indicator
def length = 20;
def nK = 1.5;
def nBB = 2.0;

def BBHalfWidth = StDev(price, length);
def KCHalfWidth = nK * Average(TrueRange(high,  close,  low),  length);
#def isSqueezed = nBB * BBHalfWidth / KCHalfWidth < 1;

#def BBS_Ind = If(isSqueezed, 0, Double.NaN);

# Bollinger Resolution
def BBSMA = Average(price, length);
def BBSMAL = BBSMA + (-nBB * BBHalfWidth);
def BBSMAU = BBSMA + (nBB * BBHalfWidth);
def PerB = RoundUp((price - BBSMAL) / (BBSMAU - BBSMAL) * 100, 0);
#AddLabel(yes, Concat("%B: ", PerB), if PerB < 0 then Color.MAGENTA else if PerB > 0 and PerB[1] < 0 then Color.GREEN else Color.ORANGE);

####################################################################################################################################################

input averageType = AverageType.SIMPLE;
def BulgeLengthPrice = 100;
def SqueezeLengthPrice = 100;
#-----------------------------
#Yellow Candle_height (OB_OS)
#-----------------------------
def displace = 0;
def factorK2 = 3.25;
def lengthK2 = 20;
def price1 = open;
def trueRangeAverageType = AverageType.SIMPLE;
def ATR_length = 15;
def SMA_lengthS = 6;

#input averageType = AverageType.WILDERS;####Use Simple instead of Wilders

def multiplier_factor = 1.25;
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 shiftK2 = factorK2 * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), lengthK2);
def averageK2 = MovingAverage(averageType, price, lengthK2);
def AvgK2 = averageK2[-displace];
def Upper_BandK2 = averageK2[-displace] + shiftK2[-displace];
def Lower_BandK2 = averageK2[-displace] - shiftK2[-displace];

def fastLength = 12;
def slowLength = 26;
def MACDLength = 9;
input MACD_AverageType = {SMA, default EMA};

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

#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);

#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);

#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;

#Change in Price
def lengthCIP = 5;
def CIP = (price - price[1]);
def AvgCIP = ExpAverage(CIP[-displace], lengthCIP);
def CIP_UP = AvgCIP > AvgCIP[1];
def CIP_DOWN = AvgCIP < AvgCIP[1];

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

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

#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;

#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));

#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;

#Bollinger Bands PercentB
input BBPB_averageType = AverageType.SIMPLE;
def BBPB_length = 20;#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;

#Klinger Histogram
def Klinger_Length = 13;
def KVOsc = KlingerOscillator(Klinger_Length).KVOsc;
def KVOH = KVOsc - Average(KVOsc, Klinger_Length);

#Projection Oscillator
def ProjectionOsc_length = 30;#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;

#Trend Confirmation Calculator
#Confirmation_Factor range 1-15.


def factorK = 2.0;
def lengthK = 20;
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 Zero_Line = 0;
def Super_OB = 4;
def Super_OS = -4;

script WMA_Smooth {
    input price = hl2;
    plot smooth = (4 * price
+ 3 * price[1]
+ 2 * price[2]
+ price[3]) / 10;
}

script Phase_Accumulation {

    input price = hl2;

    rec Smooth;
    rec Detrender;
    rec Period;
    rec Q1;
    rec I1;
    rec I1p;
    rec Q1p;
    rec Phase1;
    rec Phase;
    rec DeltaPhase;
    rec DeltaPhase1;
    rec InstPeriod1;
    rec InstPeriod;
    def CorrectionFactor;

    if BarNumber() <= 5
    then {
        Period = 0;
        Smooth = 0;
        Detrender = 0;
        CorrectionFactor = 0;
        Q1 = 0;
        I1 = 0;
        Q1p = 0;
        I1p = 0;
        Phase = 0;
        Phase1 = 0;
        DeltaPhase1 = 0;
        DeltaPhase = 0;
        InstPeriod = 0;
        InstPeriod1 = 0;
    } else {
        CorrectionFactor = 0.075 * Period[1] + 0.54;

# Smooth and detrend my smoothed signal:
        Smooth = WMA_Smooth(price);
        Detrender = ( 0.0962 * Smooth
+ 0.5769 * Smooth[2]
- 0.5769 * Smooth[4]
- 0.0962 * Smooth[6] ) * CorrectionFactor;

# Compute Quadrature and Phase of Detrended signal:
        Q1p = ( 0.0962 * Detrender
+ 0.5769 * Detrender[2]
- 0.5769 * Detrender[4]
- 0.0962 * Detrender[6] ) * CorrectionFactor;
        I1p = Detrender[3];

# Smooth out Quadrature and Phase:
        I1 = 0.15 * I1p + 0.85 * I1p[1];
        Q1 = 0.15 * Q1p + 0.85 * Q1p[1];

# Determine Phase
        if I1 != 0
        then {
# Normally, ATAN gives results from -pi/2 to pi/2.
# We need to map this to circular coordinates 0 to 2pi

            if Q1 >= 0 and I1 > 0
            then { # Quarant 1
                Phase1 = ATan(AbsValue(Q1 / I1));
            } else if Q1 >= 0 and I1 < 0
            then { # Quadrant 2
                Phase1 = Double.Pi - ATan(AbsValue(Q1 / I1));
            } else if Q1 < 0 and I1 < 0
            then { # Quadrant 3
                Phase1 = Double.Pi + ATan(AbsValue(Q1 / I1));
            } else { # Quadrant 4
                Phase1 = 2 * Double.Pi - ATan(AbsValue(Q1 / I1));
            }
        } else if Q1 > 0
        then { # I1 == 0, Q1 is positive
            Phase1 = Double.Pi / 2;
        } else if Q1 < 0
        then { # I1 == 0, Q1 is negative
            Phase1 = 3 * Double.Pi / 2;
        } else { # I1 and Q1 == 0
            Phase1 = 0;
        }

# Convert phase to degrees
        Phase = Phase1 * 180 / Double.Pi;

        if Phase[1] < 90 and Phase > 270
        then {
# This occurs when there is a big jump from 360-0
            DeltaPhase1 = 360 + Phase[1] - Phase;
        } else {
            DeltaPhase1 = Phase[1] - Phase;
        }

# Limit our delta phases between 7 and 60
        if DeltaPhase1 < 7
        then {
            DeltaPhase = 7;
        } else if DeltaPhase1 > 60
        then {
            DeltaPhase = 60;
        } else {
            DeltaPhase = DeltaPhase1;
        }

# Determine Instantaneous period:
        InstPeriod1 =
-1 * (fold i = 0 to 40 with v=0 do
if v < 0 then
v
else if v > 360 then
-i
else
v + GetValue(DeltaPhase, i, 41)
);

        if InstPeriod1 <= 0
        then {
            InstPeriod = InstPeriod[1];
        } else {
            InstPeriod = InstPeriod1;
        }

        Period = 0.25 * InstPeriod + 0.75 * Period[1];
    }
    plot DC = Period;
}

script Ehler_MAMA {
    input price = hl2;
    input FastLimit = 0.5;
    input SlowLimit = 0.05;

    rec Period;
    rec Period_raw;
    rec Period_cap;
    rec Period_lim;

    rec Smooth;
    rec Detrender;
    rec I1;
    rec Q1;
    rec jI;
    rec jQ;
    rec I2;
    rec Q2;
    rec I2_raw;
    rec Q2_raw;

    rec Phase;
    rec DeltaPhase;
    rec DeltaPhase_raw;
    rec alpha;
    rec alpha_raw;

    rec Re;
    rec Im;
    rec Re_raw;
    rec Im_raw;

    rec SmoothPeriod;
    rec vmama;
    rec vfama;

    def CorrectionFactor = Phase_Accumulation(price).CorrectionFactor;

    if BarNumber() <= 5
    then {
        Smooth = 0;
        Detrender = 0;

        Period = 0;
        Period_raw = 0;
        Period_cap = 0;
        Period_lim = 0;
        I1 = 0;
        Q1 = 0;
        I2 = 0;
        Q2 = 0;
        jI = 0;
        jQ = 0;
        I2_raw = 0;
        Q2_raw = 0;
        Re = 0;
        Im = 0;
        Re_raw = 0;
        Im_raw = 0;
        SmoothPeriod = 0;
        Phase = 0;
        DeltaPhase = 0;
        DeltaPhase_raw = 0;
        alpha = 0;
        alpha_raw = 0;
        vmama = 0;
        vfama = 0;
    } else {
# Smooth and detrend my smoothed signal:
        Smooth = WMA_Smooth(price);
        Detrender = ( 0.0962 * Smooth
+ 0.5769 * Smooth[2]
- 0.5769 * Smooth[4]
- 0.0962 * Smooth[6] ) * CorrectionFactor;

        Q1 = ( 0.0962 * Detrender
+ 0.5769 * Detrender[2]
- 0.5769 * Detrender[4]
- 0.0962 * Detrender[6] ) * CorrectionFactor;
        I1 = Detrender[3];

        jI = ( 0.0962 * I1
+ 0.5769 * I1[2]
- 0.5769 * I1[4]
- 0.0962 * I1[6] ) * CorrectionFactor;

        jQ = ( 0.0962 * Q1
+ 0.5769 * Q1[2]
- 0.5769 * Q1[4]
- 0.0962 * Q1[6] ) * CorrectionFactor;

# This is the complex conjugate
        I2_raw = I1 - jQ;
        Q2_raw = Q1 + jI;

        I2 = 0.2 * I2_raw + 0.8 * I2_raw[1];
        Q2 = 0.2 * Q2_raw + 0.8 * Q2_raw[1];

        Re_raw = I2 * I2[1] + Q2 * Q2[1];
        Im_raw = I2 * Q2[1] - Q2 * I2[1];

        Re = 0.2 * Re_raw + 0.8 * Re_raw[1];
        Im = 0.2 * Im_raw + 0.8 * Im_raw[1];

# Compute the phase
        if Re != 0 and Im != 0
        then {
            Period_raw = 2 * Double.Pi / ATan(Im / Re);
        } else {
            Period_raw = 0;
        }

        if Period_raw > 1.5 * Period_raw[1]
        then {
            Period_cap = 1.5 * Period_raw[1];
        } else if Period_raw < 0.67 * Period_raw[1] {
            Period_cap = 0.67 * Period_raw[1];
        } else {
            Period_cap = Period_raw;
        }

        if Period_cap < 6
        then {
            Period_lim = 6;
        } else if Period_cap > 50
        then {
            Period_lim = 50;
        } else {
            Period_lim = Period_cap;
        }

        Period = 0.2 * Period_lim + 0.8 * Period_lim[1];
        SmoothPeriod = 0.33 * Period + 0.67 * SmoothPeriod[1];

        if I1 != 0
        then {
            Phase = ATan(Q1 / I1);
        } else if Q1 > 0
        then { # Quadrant 1:
            Phase = Double.Pi / 2;
        } else if Q1 < 0
        then { # Quadrant 4:
            Phase = -Double.Pi / 2;
        } else { # Both numerator and denominator are 0.
            Phase = 0;
        }

        DeltaPhase_raw = Phase[1] - Phase;
        if DeltaPhase_raw < 1
        then {
            DeltaPhase = 1;
        } else {
            DeltaPhase = DeltaPhase_raw;
        }

        alpha_raw = FastLimit / DeltaPhase;
        if alpha_raw < SlowLimit
        then {
            alpha = SlowLimit;
        } else {
            alpha = alpha_raw;
        }
        vmama = alpha * price + (1 - alpha) * vmama[1];
        vfama = 0.5 * alpha * vmama + (1 - 0.5 * alpha) * vfama[1];
    }

    plot MAMA = vmama;
    plot FAMA = vfama;
}

def MAMA = Ehler_MAMA(price2, FastLimit, SlowLimit).MAMA;
def FAMA = Ehler_MAMA(price2, FastLimit, SlowLimit).FAMA;

def Crossing = Crosses((MAMA < FAMA), yes);

def Crossing1 = Crosses((MAMA > FAMA), yes);

##################################

def MF_UP = FAMA < MAMA;
def MF_DN = FAMA > MAMA;


def lastbar = if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN;

####################################################################################################################################################

#EMA's

def AvgExp8 = ExpAverage(price[-displace], length8);
def AvgExp9 = ExpAverage(price[-displace], length9);
def Below = AvgExp8 < AvgExp9;
#def Spark = UPD + UPW + Below;

#=======================

# Parabolic SAR Signal
def accelerationFactor = 0.0275;
def accelerationLimit = 0.2;

def SAR = ParabolicSAR(accelerationFactor = accelerationFactor, accelerationLimit = accelerationLimit);
def bearishCross = Crosses(SAR, price, CrossingDirection.ABOVE);

def bullishCross = Crosses(SAR, price, CrossingDirection.BELOW);

def UP = bullishCross;
def DOWN = bearishCross;
def priceColor = if UP then 1
                 else if DOWN then -1
                 else priceColor[1];

# =============================================================================================================
# =====================================================================================
# ==================== SCALPER ============================

#Scalper Upper v2 Created 02/01/2022 by Christopher84
#Sound Alerts added by Barbaros

#Current Period
def AvgExpSCA = ExpAverage(price[-displace], lengthSCA);

def AvgExp2SCA = ExpAverage(price[-displace], length2);

def BelowSCA = AvgExpSCA < AvgExp2SCA;
#def SparkSCA = UPC1 + UPC2 + BelowSCA;

def UPC1 = AvgExpSCA > AvgExpSCA[1];
def DNC1 = AvgExpSCA < AvgExpSCA[1];
def UPC2 = AvgExp2SCA > AvgExp2SCA[1];
def DNC2 = AvgExp2SCA < AvgExp2SCA[1];
def UPEMASCA = AvgExpSCA[1] < AvgExpSCA;
def DOWNEMASCA = AvgExpSCA[1] > AvgExpSCA;
def UPEMA2SCA = AvgExp2SCA[1] < AvgExp2SCA;
def DOWNEMA2SCA = AvgExp2SCA[1] > AvgExp2SCA;

# ===================
# ============================
# =====================================

# ========= MTF INFO ========================
def MaxTimeAvg = ExpAverage(close(period = agperiod6), length8);
def MaxTimeUp = MaxTimeAvg > MaxTimeAvg[1];
def MaxTimeDown = MaxTimeAvg < MaxTimeAvg[1];

# ============================================================
def Price2Ag1 = hl2(period = agperiod1);
def Price2Ag2 = hl2(period = agperiod2);
def Price2Ag3 = hl2(period = agperiod3);
def Price2Ag4 = hl2(period = agperiod4);
def Price2Ag5 = hl2(period = agperiod5);
def Price2Ag6 = hl2(period = agperiod6);

def MAMAagg1 = Ehler_MAMA(Price2Ag1, FastLimit, SlowLimit).MAMA;
def FAMAagg1 = Ehler_MAMA(Price2Ag1, FastLimit, SlowLimit).FAMA;
def MAMAagg2 = Ehler_MAMA(Price2Ag2, FastLimit, SlowLimit).MAMA;
def FAMAagg2 = Ehler_MAMA(Price2Ag2, FastLimit, SlowLimit).FAMA;
def MAMAagg3 = Ehler_MAMA(Price2Ag3, FastLimit, SlowLimit).MAMA;
def FAMAagg3 = Ehler_MAMA(Price2Ag3, FastLimit, SlowLimit).FAMA;
def MAMAagg4 = Ehler_MAMA(Price2Ag4, FastLimit, SlowLimit).MAMA;
def FAMAagg4 = Ehler_MAMA(Price2Ag4, FastLimit, SlowLimit).FAMA;
def MAMAagg5 = Ehler_MAMA(Price2Ag5, FastLimit, SlowLimit).MAMA;
def FAMAagg5 = Ehler_MAMA(Price2Ag5, FastLimit, SlowLimit).FAMA;
def MAMAagg6 = Ehler_MAMA(Price2Ag6, FastLimit, SlowLimit).MAMA;
def FAMAagg6 = Ehler_MAMA(Price2Ag6, FastLimit, SlowLimit).FAMA;

def C3_MF_LineAgg1 = (MAMAagg1 + FAMAagg1) / 2;
def C3_MF_LineAgg2 = (MAMAagg2 + FAMAagg2) / 2;
def C3_MF_LineAgg3 = (MAMAagg3 + FAMAagg3) / 2;
def C3_MF_LineAgg4 = (MAMAagg4 + FAMAagg4) / 2;
def C3_MF_LineAgg5 = (MAMAagg5 + FAMAagg5) / 2;
def C3_MF_LineAgg6 = (MAMAagg6 + FAMAagg6) / 2;

# ======= SOME CONDITIONS ============================================================

def C3_MF_UPAgg1 = C3_MF_LineAgg1 > C3_MF_LineAgg1[1];
def C3_MF_DNAgg1 = C3_MF_LineAgg1 < C3_MF_LineAgg1[1];
def C3_MF_UPAgg2 = C3_MF_LineAgg2 > C3_MF_LineAgg2[1];
def C3_MF_DNAgg2 = C3_MF_LineAgg2 < C3_MF_LineAgg2[1];
def C3_MF_UPAgg3 = C3_MF_LineAgg3 > C3_MF_LineAgg3[1];
def C3_MF_DNAgg3 = C3_MF_LineAgg3 < C3_MF_LineAgg3[1];
def C3_MF_UPAgg4 = C3_MF_LineAgg4 > C3_MF_LineAgg4[1];
def C3_MF_DNAgg4 = C3_MF_LineAgg4 < C3_MF_LineAgg4[1];
def C3_MF_UPAgg5 = C3_MF_LineAgg5 > C3_MF_LineAgg5[1];
def C3_MF_DNAgg5 = C3_MF_LineAgg5 < C3_MF_LineAgg5[1];
def C3_MF_UPAgg6 = C3_MF_LineAgg6 > C3_MF_LineAgg6[1];
def C3_MF_DNAgg6 = C3_MF_LineAgg6 < C3_MF_LineAgg6[1];

def MF_UP1 = FAMAagg1 < MAMAagg1;
def MF_DN1 = FAMAagg1 > MAMAagg1;
def MF_UP2 = FAMAagg2 < MAMAagg2;
def MF_DN2 = FAMAagg2 > MAMAagg2;
def MF_UP3 = FAMAagg3 < MAMAagg3;
def MF_DN3 = FAMAagg3 > MAMAagg3;
def MF_UP4 = FAMAagg4 < MAMAagg4;
def MF_DN4 = FAMAagg4 > MAMAagg4;
def MF_UP5 = FAMAagg5 < MAMAagg5;
def MF_DN5 = FAMAagg5 > MAMAagg5;
def MF_UP6 = FAMAagg6 < MAMAagg6;
def MF_DN6 = FAMAagg6 > MAMAagg6;

# =========================================
# =================================================

#def MF_UP = FAMA < MAMA;
#def MF_DN = FAMA > MAMA;

def C3_MFUP = C3_MF_UPAgg1 + C3_MF_UPAgg2 + C3_MF_UPAgg3 + C3_MF_UPAgg4 + C3_MF_UPAgg5 + C3_MF_UPAgg6;
def C3_MFDN = C3_MF_DNAgg1 + C3_MF_DNAgg2 + C3_MF_DNAgg3 + C3_MF_DNAgg4 + C3_MF_DNAgg5 + C3_MF_DNAgg6;

def C3MFConsensusUP = C3_MFUP > C3_MFDN;
def C3MFConsensusDN = C3_MFDN > C3_MFUP;

def MFUP = MF_UP1 and MF_UP2 and MF_UP3 and MF_UP4 and MF_UP5 and MF_UP6;
def MFDN = MF_DN1 and MF_DN2 and MF_DN3 and MF_DN4 and MF_DN5 and MF_DN6;
# ============ MTF CANDLE COLOR REFerence ==================


#DEF Agg6CandleColorGRN = CandleColor(period = agperiod6) == 1;
#def UpCalcaGG6 = UPCalc(period = agperiod6);
#def CandleColorAGG6 = UPCalc(period = agperiod6),UPCALC;

# ====================================================
#Agperiod1
def avg = ExpAverage(close(period = agperiod1), lengthSCA);
def avg2 = ExpAverage(close(period = agperiod1), length2);
def avg3 = ExpAverage(close(period = agperiod2), lengthSCA);
def avg4 = ExpAverage(close(period = agperiod2), length2);
def avg5 = ExpAverage(close(period = agperiod3), lengthSCA);
def avg6 = ExpAverage(close(period = agperiod3), length2);
def avg7 = ExpAverage(close(period = agperiod4), lengthSCA);
def avg8 = ExpAverage(close(period = agperiod4), length2);
def avg9 = ExpAverage(close(period = agperiod5), lengthSCA);
def avg10 = ExpAverage(close(period = agperiod5), length2);
def avg11 = ExpAverage(close(period = agperiod6), lengthSCA);
def avg12 = ExpAverage(close(period = agperiod6), length2);

def height = avg - avg[lengthSCA];
def height2 = avg2 - avg2[length2];
def height3 = avg3 - avg3[lengthSCA];
def height4 = avg4 - avg4[length2];
def height5 = avg5 - avg5[lengthSCA];
def height6 = avg6 - avg6[length2];
def height7 = avg7 - avg7[lengthSCA];
def height8 = avg8 - avg8[length2];
def height9 = avg9 - avg9[lengthSCA];
def height10 = avg10 - avg10[length2];
def height11 = avg11 - avg11[lengthSCA];
def height12 = avg12 - avg12[length2];

def R1UP = avg > avg[1];
def R1DN = avg < avg[1];
def R2UP = avg2 > avg2[1];
def R2DN = avg2 < avg2[1];
def R3UP = avg3 > avg3[1];
def R3DN = avg3 < avg3[1];
def R4UP = avg4 > avg4[1];
def R4DN = avg4 < avg4[1];
def R5UP = avg5 > avg5[1];
def R5DN = avg5 < avg5[1];
def R6UP = avg6 > avg6[1];
def R6DN = avg6 < avg6[1];
def R7UP = avg7 > avg7[1];
def R7DN = avg7 < avg7[1];
def R8UP = avg8 > avg8[1];
def R8DN = avg8 < avg8[1];
def R9UP = avg9 > avg9[1];
def R9DN = avg9 < avg9[1];
def R10UP = avg10 > avg10[1];
def R10DN = avg10 < avg10[1];
def R11UP = avg11 > avg11[1];
def R11DN = avg11 < avg11[1];
def R12UP = avg12 > avg12[1];
def R12DN = avg12 < avg12[1];   

def UPSCA = avg > avg2;
def DOWNSCA = avg < avg2;
def UP2SCA = avg3 > avg4;
def DOWN2SCA = avg3 < avg4;

def UP3 = avg5 > avg6;
def DOWN3 = avg5 < avg6;
def UP4 = avg7 > avg8;
def DOWN4 = avg7 < avg8;
def UP5 = avg9 > avg10;
def DOWN5 = avg9 < avg10;
def UP6 = avg11 > avg12;
def DOWN6 = avg11 < avg12;



# ============== MTF MACD =================================
# =======================================
def fastEMAag1 = ExpAverage(close(PERIOD = agperiod1), fastLength);
def slowEMAAG1 = ExpAverage(close(PERIOD = agperiod1), slowLength);
def fastEMAag2 = ExpAverage(close(PERIOD = agperiod2), fastLength);
def slowEMAAG2 = ExpAverage(close(PERIOD = agperiod2), slowLength);
def fastEMAag3 = ExpAverage(close(PERIOD = agperiod3), fastLength);
def slowEMAAG3 = ExpAverage(close(PERIOD = agperiod3), slowLength);
def fastEMAag4 = ExpAverage(close(PERIOD = agperiod4), fastLength);
def slowEMAAG4 = ExpAverage(close(PERIOD = agperiod4), slowLength);
def fastEMAag5 = ExpAverage(close(PERIOD = agperiod5), fastLength);
def slowEMAAG5 = ExpAverage(close(PERIOD = agperiod5), slowLength);
def fastEMAag6 = ExpAverage(close(PERIOD = agperiod6), fastLength);
def slowEMAAG6 = ExpAverage(close(PERIOD = agperiod6), slowLength);

# ===============AGG1 MACD ==========

def ValueAG1;
def Avg1AG1;
switch (MACD_AverageType) {
case SMA:
    ValueAG1 = Average(close(PERIOD = agperiod1), fastLength) - Average(close(PERIOD = agperiod1), slowLength);
    Avg1AG1 = Average(ValueAG1, MACDLength);
case EMA:
    ValueAG1 = fastEMAag1 - slowEMAAG1;
    Avg1AG1 = ExpAverage(ValueAG1, MACDLength);
}
def DiffAG1 = ValueAG1 - Avg1AG1;
#def MACDLevel = 0.0;
#def Level = MACDLevel;



#================================================
# ===============AGG2 MACD ==========

def ValueAG2;
def Avg1AG2;
switch (MACD_AverageType) {
case SMA:
    ValueAG2 = Average(close(PERIOD = agperiod2), fastLength) - Average(close(PERIOD = agperiod2), slowLength);
    Avg1AG2 = Average(ValueAG2, MACDLength);
case EMA:
    ValueAG2 = fastEMAag2 - slowEMAAG2;
    Avg1AG2 = ExpAverage(ValueAG2, MACDLength);
}
def DiffAG2 = ValueAG2 - Avg1AG2;
#def MACDLevel = 0.0;
#def Level = MACDLevel;


#================================================
# ===============AGG3 MACD ==========

def ValueAG3;
def Avg1AG3;
switch (MACD_AverageType) {
case SMA:
    ValueAG3 = Average(close(PERIOD = agperiod3), fastLength) - Average(close(PERIOD = agperiod3), slowLength);
    Avg1AG3 = Average(ValueAG3, MACDLength);
case EMA:
    ValueAG3 = fastEMAag3 - slowEMAAG3;
    Avg1AG3 = ExpAverage(ValueAG3, MACDLength);
}
def DiffAG3 = ValueAG3 - Avg1AG3;
#def MACDLevel = 0.0;
#def Level = MACDLevel;


#================================================
# ===============AGG4 MACD ==========

def ValueAG4;
def Avg1AG4;
switch (MACD_AverageType) {
case SMA:
    ValueAG4 = Average(close(PERIOD = agperiod4), fastLength) - Average(close(PERIOD = agperiod4), slowLength);
    Avg1AG4 = Average(ValueAG4, MACDLength);
case EMA:
    ValueAG4 = fastEMAag4 - slowEMAAG4;
    Avg1AG4 = ExpAverage(ValueAG4, MACDLength);
}
def DiffAG4 = ValueAG4 - Avg1AG4;
#def MACDLevel = 0.0;
#def Level = MACDLevel;


#================================================
# ===============AGG5 MACD ==========

def ValueAG5;
def Avg1AG5;
switch (MACD_AverageType) {
case SMA:
    ValueAG5 = Average(close(PERIOD = agperiod5), fastLength) - Average(close(PERIOD = agperiod5), slowLength);
    Avg1AG5 = Average(ValueAG5, MACDLength);
case EMA:
    ValueAG5 = fastEMAag5 - slowEMAAG5;
    Avg1AG5 = ExpAverage(ValueAG5, MACDLength);
}
def DiffAG5 = ValueAG5 - Avg1AG5;
#def MACDLevel = 0.0;
#def Level = MACDLevel;


#================================================
# ===============AGG6 MACD ==========

def ValueAG6;
def Avg1AG6;
switch (MACD_AverageType) {
case SMA:
    ValueAG6 = Average(close(PERIOD = agperiod6), fastLength) - Average(close(PERIOD = agperiod6), slowLength);
    Avg1AG6 = Average(ValueAG6, MACDLength);
case EMA:
    ValueAG6 = fastEMAag6 - slowEMAAG6;
    Avg1AG6 = ExpAverage(ValueAG6, MACDLength);
}
def DiffAG6 = ValueAG6 - Avg1AG6;
#def MACDLevel = 0.0;
#def Level = MACDLevel;

#============== END MACD AGG==================================
# ==============RSI MTF ===========================
# =============         =======================

# =======AGG RSI ========================================
#def RSI_length = 14;
#def RSI_AverageType = AverageType.WILDERS;
#def RSI_OB = 70;
#def RSI_OS = 30;
#input mid = 50;

def rsi1 = close(period = agperiod1);
def rsi2 = close(period = agperiod2);
def rsi3 = close(period = agperiod3);
def rsi4 = close(period = agperiod4);
def rsi5 = close(period = agperiod5);
def rsi6 = close(period = agperiod6);


def NetChgAvg1 = MovingAverage(RSI_AverageType, rsi1 - rsi1[1], RSI_length);
def NetChgAvg2 = MovingAverage(RSI_AverageType, rsi2 - rsi2[1], RSI_length);
def NetChgAvg3 = MovingAverage(RSI_AverageType, rsi3 - rsi3[1], RSI_length);
def NetChgAvg4 = MovingAverage(RSI_AverageType, rsi4 - rsi4[1], RSI_length);
def NetChgAvG5 = MovingAverage(RSI_AverageType, rsi5 - rsi5[1], RSI_length);
def NetChgAvg6 = MovingAverage(RSI_AverageType, rsi6 - rsi6[1], RSI_length);

def TotChgAvg1 = MovingAverage(RSI_AverageType, AbsValue(rsi1 - rsi1[1]), RSI_length);
def TotChgAvg2 = MovingAverage(RSI_AverageType, AbsValue(rsi2 - rsi2[1]), RSI_length);
def TotChgAvg3 = MovingAverage(RSI_AverageType, AbsValue(rsi3 - rsi3[1]), RSI_length);
def TotChgAvg4 = MovingAverage(RSI_AverageType, AbsValue(rsi4 - rsi4[1]), RSI_length);
def TotChgAvg5 = MovingAverage(RSI_AverageType, AbsValue(rsi5 - rsi5[1]), RSI_length);
def TotChgAvg6 = MovingAverage(RSI_AverageType, AbsValue(rsi6 - rsi6[1]), RSI_length);

def ChgRatio1 = if TotChgAvg1 != 0 then NetChgAvg1 / TotChgAvg1 else 0;
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;
def ChgRatio3 = if TotChgAvg3 != 0 then NetChgAvg3 / TotChgAvg3 else 0;
def ChgRatio4 = if TotChgAvg4 != 0 then NetChgAvg4 / TotChgAvg4 else 0;
def ChgRatio5 = if TotChgAvg5 != 0 then NetChgAvG5 / TotChgAvg5 else 0;
def ChgRatio6 = if TotChgAvg6 != 0 then NetChgAvg6 / TotChgAvg6 else 0;

def RSI_1 = 50 * (ChgRatio1 + 1);
def RSI_2 = 50 * (ChgRatio2 + 1);
def RSI_3 = 50 * (ChgRatio3 + 1);
def RSI_4 = 50 * (ChgRatio4 + 1);
def RSI_5 = 50 * (ChgRatio5 + 1);
def RSI_6 = 50 * (ChgRatio6 + 1);


# =============================================================
# ===============================================================
# =================  MFI =============================

#MFI
#def MFI_Length = 14;
#def MFIover_Sold = 20;
#def MFIover_Bought = 80;
#def movingAvgLength = 1;
def MoneyFlowIndexAG1 = Average(MoneyFlow(high(period = agperiod1), close(period = agperiod1), low(period = agperiod1), volume(period = agperiod1), MFI_Length), movingAvgLength);
def MoneyFlowIndexAG2 = Average(MoneyFlow(high(period = agperiod2), close(period = agperiod2), low(period = agperiod2), volume(period = agperiod2), MFI_Length), movingAvgLength);
def MoneyFlowIndexAG3 = Average(MoneyFlow(high(period = agperiod3), close(period = agperiod3), low(period = agperiod3), volume(period = agperiod3), MFI_Length), movingAvgLength);
def MoneyFlowIndexAG4 = Average(MoneyFlow(high(period = agperiod4), close(period = agperiod4), low(period = agperiod4), volume(period = agperiod4), MFI_Length), movingAvgLength);
def MoneyFlowIndexAG5 = Average(MoneyFlow(high(period = agperiod5), close(period = agperiod5), low(period = agperiod5), volume(period = agperiod5), MFI_Length), movingAvgLength);
def MoneyFlowIndexAG6 = Average(MoneyFlow(high(period = agperiod6), close(period = agperiod6), low(period = agperiod6), volume(period = agperiod6), MFI_Length), movingAvgLength);


# ========================================================
# =================================================================
# ========== CHANGE IN PRICE ==================
    #  ======== CIP AGG1 =================
#def lengthCIP = 5;
def CIPAG1 = (close(period = agperiod1) - close(period = agperiod1)[1]);
def AvgCIPAG1 = ExpAverage(CIPAG1[-displace], lengthCIP);
def CIP_UPAG1 = AvgCIPAG1 > AvgCIPAG1[1];
def CIP_DOWNAG1 = AvgCIPAG1 < AvgCIPAG1[1];


# ============================================================
    #  ========CIP AGG2 =================
#def lengthCIP = 5;
def CIPAG2 = (close(period = agperiod2) - close(period = agperiod2)[1]);
def AvgCIPAG2 = ExpAverage(CIPAG2[-displace], lengthCIP);
def CIP_UPAG2 = AvgCIPAG2 > AvgCIPAG2[1];
def CIP_DOWNAG2 = AvgCIPAG2 < AvgCIPAG2[1];

;
# ============================================================
    #  ========CIP AGG3 =================
#def lengthCIP = 5;
def CIPAG3 = (close(period = agperiod3) - close(period = agperiod3)[1]);
def AvgCIPAG3 = ExpAverage(CIPAG3[-displace], lengthCIP);
def CIP_UPAG3 = AvgCIPAG3 > AvgCIPAG3[1];
def CIP_DOWNAG3 = AvgCIPAG3 < AvgCIPAG3[1];

;
# ============================================================
    #  ========CIP AGG4 =================
#def lengthCIP = 5;
def CIPAG4 = (close(period = agperiod4) - close(period = agperiod4)[1]);
def AvgCIPAG4 = ExpAverage(CIPAG4[-displace], lengthCIP);
def CIP_UPAG4 = AvgCIPAG4 > AvgCIPAG4[1];
def CIP_DOWNAG4 = AvgCIPAG4 < AvgCIPAG4[1];


# ============================================================
    #  ========CIP AGG5 =================
#def lengthCIP = 5;
def CIPAG5 = (close(period = agperiod5) - close(period = agperiod5)[1]);
def AvgCIPAG5 = ExpAverage(CIPAG5[-displace], lengthCIP);
def CIP_UPAG5 = AvgCIPAG5 > AvgCIPAG5[1];
def CIP_DOWNAG5 = AvgCIPAG5 < AvgCIPAG5[1];


# ============================================================
    #  ========CIP AGG6 =================
#def lengthCIP = 5;
def CIPAG6 = (close(period = agperiod6) - close(period = agperiod6)[1]);
def AvgCIPAG6 = ExpAverage(CIPAG6[-displace], lengthCIP);
def CIP_UPAG6 = AvgCIPAG6 > AvgCIPAG6[1];
def CIP_DOWNAG6 = AvgCIPAG6 < AvgCIPAG6[1];


# ============================================================
# ========== EMA MTF ===========================================
#EMA_1
#def EMA_length = 8;
def AvgExpAG1 = ExpAverage(close(period = agperiod1)[-displace], EMA_length);
def AvgExpAG2 = ExpAverage(close(period = agperiod2)[-displace], EMA_length);
def AvgExpAG3 = ExpAverage(close(period = agperiod3)[-displace], EMA_length);
def AvgExpAG4 = ExpAverage(close(period = agperiod4)[-displace], EMA_length);
def AvgExpAG5 = ExpAverage(close(period = agperiod5)[-displace], EMA_length);
def AvgExpAG6 = ExpAverage(close(period = agperiod6)[-displace], EMA_length);



#EMA_2
#def EMA_2length = 20;
def AvgExp2AG1 = ExpAverage(close(period = agperiod1)[-displace], EMA_2length);
def AvgExp2AG2 = ExpAverage(close(period = agperiod2)[-displace], EMA_2length);
def AvgExp2AG3 = ExpAverage(close(period = agperiod3)[-displace], EMA_2length);
def AvgExp2AG4 = ExpAverage(close(period = agperiod4)[-displace], EMA_2length);
def AvgExp2AG5 = ExpAverage(close(period = agperiod5)[-displace], EMA_2length);
def AvgExp2AG6 = ExpAverage(close(period = agperiod6)[-displace], EMA_2length);


# =========================================================

# =============== DMI ===================================

def hiDiffAG1 = high(period = agperiod1) - high(period = agperiod1)[1];
def loDiffAG1 = low(period = agperiod1)[1] - low(period = agperiod1);
def hiDiffAG2 = high(period = agperiod2) - high(period = agperiod2)[1];
def loDiffAG2 = low(period = agperiod2)[1] - low(period = agperiod2);
def hiDiffAG3 = high(period = agperiod3) - high(period = agperiod3)[1];
def loDiffAG3 = low(period = agperiod3)[1] - low(period = agperiod3);
def hiDiffAG4 = high(period = agperiod4) - high(period = agperiod4)[1];
def loDiffAG4 = low(period = agperiod4)[1] - low(period = agperiod4);
def hiDiffAG5 = high(period = agperiod5) - high(period = agperiod5)[1];
def loDiffAG5 = low(period = agperiod5)[1] - low(period = agperiod5);
def hiDiffAG6 = high(period = agperiod6) - high(period = agperiod6)[1];
def loDiffAG6 = low(period = agperiod6)[1] - low(period = agperiod6);

def plusDMAG1 = if hiDiffAG1 > loDiffAG1 and hiDiffAG1 > 0 then hiDiffAG1 else 0;
def minusDMAG1 =  if loDiffAG1 > hiDiffAG1 and loDiffAG1 > 0 then loDiffAG1 else 0;
def plusDMAG2 = if hiDiffAG2 > loDiffAG2 and hiDiffAG2 > 0 then hiDiffAG2 else 0;
def minusDMAG2 =  if loDiffAG2 > hiDiffAG2 and loDiffAG2 > 0 then loDiffAG2 else 0;
def plusDMAG3 = if hiDiffAG3 > loDiffAG3 and hiDiffAG3 > 0 then hiDiffAG3 else 0;
def minusDMAG3 =  if loDiffAG3 > hiDiffAG3 and loDiffAG3 > 0 then loDiffAG3 else 0;
def plusDMAG4 = if hiDiffAG4 > loDiffAG4 and hiDiffAG4 > 0 then hiDiffAG4 else 0;
def minusDMAG4 =  if loDiffAG4 > hiDiffAG4 and loDiffAG4 > 0 then loDiffAG4 else 0;
def plusDMAG5 = if hiDiffAG5 > loDiffAG5 and hiDiffAG5 > 0 then hiDiffAG5 else 0;
def minusDMAG5 =  if loDiffAG5 > hiDiffAG5 and loDiffAG5 > 0 then loDiffAG5 else 0;
def plusDMAG6 = if hiDiffAG6 > loDiffAG6 and hiDiffAG6 > 0 then hiDiffAG6 else 0;
def minusDMAG6 =  if loDiffAG6 > hiDiffAG6 and loDiffAG6 > 0 then loDiffAG6 else 0;


def ATRAG1 = MovingAverage(averageTypeDMI, TrueRange(high(period = agperiod1), close(period = agperiod1), low(period = agperiod1)), DMIlength);
def ATRAG2 = MovingAverage(averageTypeDMI, TrueRange(high(period = agperiod2), close(period = agperiod2), low(period = agperiod2)), DMIlength);
def ATRAG3 = MovingAverage(averageTypeDMI, TrueRange(high(period = agperiod3), close(period = agperiod3), low(period = agperiod3)), DMIlength);
def ATRAG4 = MovingAverage(averageTypeDMI, TrueRange(high(period = agperiod4), close(period = agperiod4), low(period = agperiod4)), DMIlength);
def ATRAG5 = MovingAverage(averageTypeDMI, TrueRange(high(period = agperiod5), close(period = agperiod5), low(period = agperiod5)), DMIlength);
def ATRAG6 = MovingAverage(averageTypeDMI, TrueRange(high(period = agperiod6), close(period = agperiod6), low(period = agperiod6)), DMIlength);

def "DI+AG1" = 100 * MovingAverage(averageTypeDMI, plusDMAG1, DMIlength) / ATRAG1;
def "DI+AG2" = 100 * MovingAverage(averageTypeDMI, plusDMAG2, DMIlength) / ATRAG2;
def "DI+AG3" = 100 * MovingAverage(averageTypeDMI, plusDMAG3, DMIlength) / ATRAG3;
def "DI+AG4" = 100 * MovingAverage(averageTypeDMI, plusDMAG4, DMIlength) / ATRAG4;
def "DI+AG5" = 100 * MovingAverage(averageTypeDMI, plusDMAG5, DMIlength) / ATRAG5;
def "DI+AG6" = 100 * MovingAverage(averageTypeDMI, plusDMAG6, DMIlength) / ATRAG6;

def "DI-AG1" = 100 * MovingAverage(averageTypeDMI, minusDMAG1, DMIlength) / ATRAG1;
def "DI-AG2" = 100 * MovingAverage(averageTypeDMI, minusDMAG2, DMIlength) / ATRAG2;
def "DI-AG3" = 100 * MovingAverage(averageTypeDMI, minusDMAG3, DMIlength) / ATRAG3;
def "DI-AG4" = 100 * MovingAverage(averageTypeDMI, minusDMAG4, DMIlength) / ATRAG4;
def "DI-AG5" = 100 * MovingAverage(averageTypeDMI, minusDMAG5, DMIlength) / ATRAG5;
def "DI-AG6" = 100 * MovingAverage(averageTypeDMI, minusDMAG6, DMIlength) / ATRAG6;

# ==================================================================
# ==============================================================================
# ============ TREND PERIODS =============================================
#Trend_Periods
#def TP_fastLength = 3;#Typically 7
#def TP_slowLength = 4;#Typically 15
def PeriodsAG1 = Sign(ExpAverage(close(period = agperiod1), TP_fastLength) - ExpAverage(close(period = agperiod1), TP_slowLength));
def PeriodsAG2 = Sign(ExpAverage(close(period = agperiod2), TP_fastLength) - ExpAverage(close(period = agperiod2), TP_slowLength));
def PeriodsAG3 = Sign(ExpAverage(close(period = agperiod3), TP_fastLength) - ExpAverage(close(period = agperiod3), TP_slowLength));
def PeriodsAG4 = Sign(ExpAverage(close(period = agperiod4), TP_fastLength) - ExpAverage(close(period = agperiod4), TP_slowLength));
def PeriodsAG5 = Sign(ExpAverage(close(period = agperiod5), TP_fastLength) - ExpAverage(close(period = agperiod5), TP_slowLength));
def PeriodsAG6 = Sign(ExpAverage(close(period = agperiod6), TP_fastLength) - ExpAverage(close(period = agperiod6), TP_slowLength));


#==================================================================================
# ============= POLARIZED FRACTAL ============================================

#Polarized Fractal Efficiency
#def PFE_length = 5;#Typically 10
#def smoothingLength = 2.5;#Typically 5
def PFE_diffAG1 = close(period = agperiod1) - close(period = agperiod1)[PFE_length - 1];
def PFE_diffAG2 = close(period = agperiod2) - close(period = agperiod2)[PFE_length - 1];
def PFE_diffAG3 = close(period = agperiod3) - close(period = agperiod3)[PFE_length - 1];
def PFE_diffAG4 = close(period = agperiod4) - close(period = agperiod4)[PFE_length - 1];
def PFE_diffAG5 = close(period = agperiod5) - close(period = agperiod5)[PFE_length - 1];
def PFE_diffAG6 = close(period = agperiod6) - close(period = agperiod6)[PFE_length - 1];

def valAG1 = 100 * Sqrt(Sqr(PFE_diffAG1) + Sqr(PFE_length)) / Sum(Sqrt(1 + Sqr(close(period = agperiod1) - close(period = agperiod1)[1])), PFE_length - 1);
def valAG2 = 100 * Sqrt(Sqr(PFE_diffAG2) + Sqr(PFE_length)) / Sum(Sqrt(1 + Sqr(close(period = agperiod2) - close(period = agperiod2)[1])), PFE_length - 1);
def valAG3 = 100 * Sqrt(Sqr(PFE_diffAG3) + Sqr(PFE_length)) / Sum(Sqrt(1 + Sqr(close(period = agperiod3) - close(period = agperiod3)[1])), PFE_length - 1);
def valAG4 = 100 * Sqrt(Sqr(PFE_diffAG4) + Sqr(PFE_length)) / Sum(Sqrt(1 + Sqr(close(period = agperiod4) - close(period = agperiod4)[1])), PFE_length - 1);
def valAG5 = 100 * Sqrt(Sqr(PFE_diffAG5) + Sqr(PFE_length)) / Sum(Sqrt(1 + Sqr(close(period = agperiod5) - close(period = agperiod5)[1])), PFE_length - 1);
def valAG6 = 100 * Sqrt(Sqr(PFE_diffAG6) + Sqr(PFE_length)) / Sum(Sqrt(1 + Sqr(close(period = agperiod6) - close(period = agperiod6)[1])), PFE_length - 1);


def PFEAG1 = ExpAverage(if PFE_diffAG1 > 0 then valAG1 else -valAG1, smoothingLength);
def PFEAG2 = ExpAverage(if PFE_diffAG2 > 0 then valAG2 else -valAG2, smoothingLength);
def PFEAG3 = ExpAverage(if PFE_diffAG3 > 0 then valAG3 else -valAG3, smoothingLength);
def PFEAG4 = ExpAverage(if PFE_diffAG4 > 0 then valAG4 else -valAG4, smoothingLength);
def PFEAG5 = ExpAverage(if PFE_diffAG5 > 0 then valAG5 else -valAG5, smoothingLength);
def PFEAG6 = ExpAverage(if PFE_diffAG6 > 0 then valAG6 else -valAG6, smoothingLength);
#def UpperLevel = 50;
#def LowerLevel = -50;


# ============================================================
# ===================================================================
# ========= BOLLingerPercentB MTF ======================

#input BBPB_averageType = AverageType.SIMPLE;
#def BBPB_length = 20;#Typically 20
#def Num_Dev_Dn = -2.0;
#def Num_Dev_up = 2.0;
#def BBPB_OB = 100;
#def BBPB_OS = 0;
def upperBandAG1 = BollingerBands(close(period = agperiod1), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);
def upperBandAG2 = BollingerBands(close(period = agperiod2), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);
def upperBandAG3 = BollingerBands(close(period = agperiod3), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);
def upperBandAG4 = BollingerBands(close(period = agperiod4), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);
def upperBandAG5 = BollingerBands(close(period = agperiod5), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);
def upperBandAG6 = BollingerBands(close(period = agperiod6), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);

def lowerBandAG1 = BollingerBands(close(PERIOD = agperiod1), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);
def lowerBandAG2 = BollingerBands(close(PERIOD = agperiod2), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);
def lowerBandAG3 = BollingerBands(close(PERIOD = agperiod3), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);
def lowerBandAG4 = BollingerBands(close(PERIOD = agperiod4), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);
def lowerBandAG5 = BollingerBands(close(PERIOD = agperiod5), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);
def lowerBandAG6 = BollingerBands(close(PERIOD = agperiod6), displace, BBPB_length, Num_Dev_Dn, Num_Dev_up, BBPB_averageType);

def PercentBAG1 = (close(period = agperiod1) - lowerBandAG1) / (upperBandAG1 - lowerBandAG1) * 100;
def PercentBAG2 = (close(period = agperiod2) - lowerBandAG2) / (upperBandAG2 - lowerBandAG2) * 100;
def PercentBAG3 = (close(period = agperiod3) - lowerBandAG3) / (upperBandAG3 - lowerBandAG3) * 100;
def PercentBAG4 = (close(period = agperiod4) - lowerBandAG4) / (upperBandAG4 - lowerBandAG4) * 100;
def PercentBAG5 = (close(period = agperiod5) - lowerBandAG5) / (upperBandAG5 - lowerBandAG5) * 100;
def PercentBAG6 = (close(period = agperiod6) - lowerBandAG6) / (upperBandAG6 - lowerBandAG6) * 100;



#def multiplier_factor = 1.25;
def valSAG1 = Average(close(PERIOD = agperiod1), SMA_lengthS);
def valSAG2 = Average(close(PERIOD = agperiod2), SMA_lengthS);
def valSAG3 = Average(close(PERIOD = agperiod3), SMA_lengthS);
def valSAG4 = Average(close(PERIOD = agperiod4), SMA_lengthS);
def valSAG5 = Average(close(PERIOD = agperiod5), SMA_lengthS);
def valSAG6 = Average(close(PERIOD = agperiod6), SMA_lengthS);

def average_true_rangeAG1 = Average(TrueRange(high(PERIOD = agperiod1), close(PERIOD = agperiod1), low(PERIOD = agperiod1)), length = ATR_length);
def average_true_rangeAG2 = Average(TrueRange(high(PERIOD = agperiod2), close(PERIOD = agperiod2), low(PERIOD = agperiod2)), length = ATR_length);
def average_true_rangeAG3 = Average(TrueRange(high(PERIOD = agperiod3), close(PERIOD = agperiod3), low(PERIOD = agperiod3)), length = ATR_length);
def average_true_rangeAG4 = Average(TrueRange(high(PERIOD = agperiod4), close(PERIOD = agperiod4), low(PERIOD = agperiod4)), length = ATR_length);
def average_true_rangeAG5 = Average(TrueRange(high(PERIOD = agperiod5), close(PERIOD = agperiod5), low(PERIOD = agperiod5)), length = ATR_length);
def average_true_rangeAG6 = Average(TrueRange(high(PERIOD = agperiod6), close(PERIOD = agperiod6), low(PERIOD = agperiod6)), length = ATR_length);

def Upper_BandSAG1 = valSAG1[-displace] + multiplier_factor * average_true_rangeAG1[-displace];
def Upper_BandSAG2 = valSAG2[-displace] + multiplier_factor * average_true_rangeAG2[-displace];
def Upper_BandSAG3 = valSAG3[-displace] + multiplier_factor * average_true_rangeAG3[-displace];
def Upper_BandSAG4 = valSAG4[-displace] + multiplier_factor * average_true_rangeAG4[-displace];
def Upper_BandSAG5 = valSAG5[-displace] + multiplier_factor * average_true_rangeAG5[-displace];
def Upper_BandSAG6 = valSAG6[-displace] + multiplier_factor * average_true_rangeAG6[-displace];

def Middle_BandSAG1 = valSAG1[-displace];
def Middle_BandSAG2 = valSAG2[-displace];
def Middle_BandSAG3 = valSAG3[-displace];
def Middle_BandSAG4 = valSAG4[-displace];
def Middle_BandSAG5 = valSAG5[-displace];
def Middle_BandSAG6 = valSAG6[-displace];

def Lower_BandSAG1 = valSAG1[-displace] - multiplier_factor * average_true_rangeAG1[-displace];
def Lower_BandSAG2 = valSAG2[-displace] - multiplier_factor * average_true_rangeAG2[-displace];
def Lower_BandSAG3 = valSAG3[-displace] - multiplier_factor * average_true_rangeAG3[-displace];
def Lower_BandSAG4 = valSAG4[-displace] - multiplier_factor * average_true_rangeAG4[-displace];
def Lower_BandSAG5 = valSAG5[-displace] - multiplier_factor * average_true_rangeAG5[-displace];
def Lower_BandSAG6 = valSAG6[-displace] - multiplier_factor * average_true_rangeAG6[-displace];

def shiftK2AG1 = factorK2 * MovingAverage(trueRangeAverageType, TrueRange(high(PERIOD = agperiod1), close(PERIOD = agperiod1), low(PERIOD = agperiod1)), lengthK2);
def shiftK2AG2 = factorK2 * MovingAverage(trueRangeAverageType, TrueRange(high(PERIOD = agperiod1), close(PERIOD = agperiod1), low(PERIOD = agperiod1)), lengthK2);
def shiftK2AG3 = factorK2 * MovingAverage(trueRangeAverageType, TrueRange(high(PERIOD = agperiod1), close(PERIOD = agperiod1), low(PERIOD = agperiod1)), lengthK2);
def shiftK2AG4 = factorK2 * MovingAverage(trueRangeAverageType, TrueRange(high(PERIOD = agperiod1), close(PERIOD = agperiod1), low(PERIOD = agperiod1)), lengthK2);
def shiftK2AG5 = factorK2 * MovingAverage(trueRangeAverageType, TrueRange(high(PERIOD = agperiod1), close(PERIOD = agperiod1), low(PERIOD = agperiod1)), lengthK2);
def shiftK2AG6 = factorK2 * MovingAverage(trueRangeAverageType, TrueRange(high(PERIOD = agperiod1), close(PERIOD = agperiod1), low(PERIOD = agperiod1)), lengthK2);

def averageK2AG1 = MovingAverage(averageType, close(PERIOD = agperiod1), lengthK2);
def averageK2AG2 = MovingAverage(averageType, close(PERIOD = agperiod2), lengthK2);
def averageK2AG3 = MovingAverage(averageType, close(PERIOD = agperiod3), lengthK2);
def averageK2AG4 = MovingAverage(averageType, close(PERIOD = agperiod4), lengthK2);
def averageK2AG5 = MovingAverage(averageType, close(PERIOD = agperiod5), lengthK2);
def averageK2AG6 = MovingAverage(averageType, close(PERIOD = agperiod6), lengthK2);

def AvgK2AG1 = averageK2AG1[-displace];
def AvgK2AG2 = averageK2AG2[-displace];
def AvgK2AG3 = averageK2AG3[-displace];
def AvgK2AG4 = averageK2AG4[-displace];
def AvgK2AG5 = averageK2AG5[-displace];
def AvgK2AG6 = averageK2AG6[-displace];

def Upper_BandK2AG1 = averageK2AG1[-displace] + shiftK2AG1[-displace];
def Upper_BandK2AG2 = averageK2AG2[-displace] + shiftK2AG2[-displace];
def Upper_BandK2AG3 = averageK2AG3[-displace] + shiftK2AG3[-displace];
def Upper_BandK2AG4 = averageK2AG4[-displace] + shiftK2AG4[-displace];
def Upper_BandK2AG5 = averageK2AG5[-displace] + shiftK2AG5[-displace];
def Upper_BandK2AG6 = averageK2AG6[-displace] + shiftK2AG6[-displace];

def Lower_BandK2AG1 = averageK2AG1[-displace] - shiftK2AG1[-displace];
def Lower_BandK2AG2 = averageK2AG2[-displace] - shiftK2AG2[-displace];
def Lower_BandK2AG3 = averageK2AG3[-displace] - shiftK2AG3[-displace];
def Lower_BandK2AG4 = averageK2AG4[-displace] - shiftK2AG4[-displace];
def Lower_BandK2AG5 = averageK2AG5[-displace] - shiftK2AG5[-displace];
def Lower_BandK2AG6 = averageK2AG6[-displace] - shiftK2AG6[-displace];


# ======================================================
# =============================================================
# ========== KLINGER ==================================

def DMAG1 = high(PERIOD = agperiod1) - low(PERIOD = agperiod1);
def DMAG2 = high(PERIOD = agperiod2) - low(PERIOD = agperiod2);
def DMAG3 = high(PERIOD = agperiod3) - low(PERIOD = agperiod3);
def DMAG4 = high(PERIOD = agperiod4) - low(PERIOD = agperiod4);
def DMAG5 = high(PERIOD = agperiod5) - low(PERIOD = agperiod5);
def DMAG6 = high(PERIOD = agperiod6) - low(PERIOD = agperiod6);

def TrendAG1 = if hlc3(PERIOD = agperiod1) > hlc3(PERIOD = agperiod1)[1] then 1 else -1;
def TrendAG2 = if hlc3(PERIOD = agperiod2) > hlc3(PERIOD = agperiod2)[1] then 1 else -1;
def TrendAG3 = if hlc3(PERIOD = agperiod3) > hlc3(PERIOD = agperiod3)[1] then 1 else -1;
def TrendAG4 = if hlc3(PERIOD = agperiod4) > hlc3(PERIOD = agperiod4)[1] then 1 else -1;
def TrendAG5 = if hlc3(PERIOD = agperiod5) > hlc3(PERIOD = agperiod5)[1] then 1 else -1;
def TrendAG6 = if hlc3(PERIOD = agperiod6) > hlc3(PERIOD = agperiod6)[1] then 1 else -1;

def CMAG1 = DMAG1 + if TrendAG1 == TrendAG1[1] then CMAG1[1] else DMAG1[1];
def CMAG2 = DMAG2 + if TrendAG2 == TrendAG2[1] then CMAG2[1] else DMAG2[1];
def CMAG3 = DMAG3 + if TrendAG3 == TrendAG3[1] then CMAG3[1] else DMAG3[1];
def CMAG4 = DMAG4 + if TrendAG4 == TrendAG4[1] then CMAG4[1] else DMAG4[1];
def CMAG5 = DMAG5 + if TrendAG5 == TrendAG5[1] then CMAG5[1] else DMAG5[1];
def CMAG6 = DMAG6 + if TrendAG6 == TrendAG6[1] then CMAG6[1] else DMAG6[1];

def VForceAG1 = if CMAG1 != 0 then TrendAG1 * 100 * volume(PERIOD = agperiod1) * AbsValue(2 * DMAG1 / CMAG1 - 1) else VForceAG1[1];
def VForceAG2 = if CMAG2 != 0 then TrendAG2 * 100 * volume(PERIOD = agperiod2) * AbsValue(2 * DMAG2 / CMAG2 - 1) else VForceAG2[1];
def VForceAG3 = if CMAG3 != 0 then TrendAG3 * 100 * volume(PERIOD = agperiod3) * AbsValue(2 * DMAG3 / CMAG3 - 1) else VForceAG3[1];
def VForceAG4 = if CMAG4 != 0 then TrendAG4 * 100 * volume(PERIOD = agperiod4) * AbsValue(2 * DMAG4 / CMAG4 - 1) else VForceAG4[1];
def VForceAG5 = if CMAG5 != 0 then TrendAG5 * 100 * volume(PERIOD = agperiod5) * AbsValue(2 * DMAG5 / CMAG5 - 1) else VForceAG5[1];
def VForceAG6 = if CMAG6 != 0 then TrendAG6 * 100 * volume(PERIOD = agperiod6) * AbsValue(2 * DMAG6 / CMAG6 - 1) else VForceAG6[1];

def KVOscAG1 = ExpAverage(VForceAG1, 34) - ExpAverage(VForceAG1, 55);
def KVOscAG2 = ExpAverage(VForceAG2, 34) - ExpAverage(VForceAG2, 55);
def KVOscAG3 = ExpAverage(VForceAG3, 34) - ExpAverage(VForceAG3, 55);
def KVOscAG4 = ExpAverage(VForceAG4, 34) - ExpAverage(VForceAG4, 55);
def KVOscAG5 = ExpAverage(VForceAG5, 34) - ExpAverage(VForceAG5, 55);
def KVOscAG6 = ExpAverage(VForceAG6, 34) - ExpAverage(VForceAG6, 55);

def TriggerLineAG1 = Average(KVOscAG1, MALength);
def TriggerLineAG2 = Average(KVOscAG2, MALength);
def TriggerLineAG3 = Average(KVOscAG3, MALength);
def TriggerLineAG4 = Average(KVOscAG4, MALength);
def TriggerLineAG5 = Average(KVOscAG5, MALength);
def TriggerLineAG6 = Average(KVOscAG6, MALength);



#DEF ZeroLineKLING = 0;

#=====================================
#=================================================
# ============ PROJECTION OSC

#Projection Oscillator
#def ProjectionOsc_length = 30;#Typically 10
def MaxBoundAG1 = HighestWeighted(high(PERIOD = agperiod1), ProjectionOsc_length, LinearRegressionSlope(PRICE = high(PERIOD = agperiod1), length = ProjectionOsc_length));
def MaxBoundAG2 = HighestWeighted(high(PERIOD = agperiod2), ProjectionOsc_length, LinearRegressionSlope(PRICE = high(PERIOD = agperiod2), length = ProjectionOsc_length));
def MaxBoundAG3 = HighestWeighted(high(PERIOD = agperiod3), ProjectionOsc_length, LinearRegressionSlope(PRICE = high(PERIOD = agperiod3), length = ProjectionOsc_length));
def MaxBoundAG4 = HighestWeighted(high(PERIOD = agperiod4), ProjectionOsc_length, LinearRegressionSlope(PRICE = high(PERIOD = agperiod4), length = ProjectionOsc_length));
def MaxBoundAG5 = HighestWeighted(high(PERIOD = agperiod5), ProjectionOsc_length, LinearRegressionSlope(PRICE = high(PERIOD = agperiod5), length = ProjectionOsc_length));
def MaxBoundAG6 = HighestWeighted(high(PERIOD = agperiod6), ProjectionOsc_length, LinearRegressionSlope(PRICE = high(PERIOD = agperiod6), length = ProjectionOsc_length));

def MinBoundAG1 = LowestWeighted(low(PERIOD = agperiod1), ProjectionOsc_length, LinearRegressionSlope(price = low(PERIOD = agperiod1), length = ProjectionOsc_length));
def MinBoundAG2 = LowestWeighted(low(PERIOD = agperiod2), ProjectionOsc_length, LinearRegressionSlope(price = low(PERIOD = agperiod2), length = ProjectionOsc_length));
def MinBoundAG3 = LowestWeighted(low(PERIOD = agperiod3), ProjectionOsc_length, LinearRegressionSlope(price = low(PERIOD = agperiod3), length = ProjectionOsc_length));
def MinBoundAG4 = LowestWeighted(low(PERIOD = agperiod4), ProjectionOsc_length, LinearRegressionSlope(price = low(PERIOD = agperiod4), length = ProjectionOsc_length));
def MinBoundAG5 = LowestWeighted(low(PERIOD = agperiod5), ProjectionOsc_length, LinearRegressionSlope(price = low(PERIOD = agperiod5), length = ProjectionOsc_length));
def MinBoundAG6 = LowestWeighted(low(PERIOD = agperiod6), ProjectionOsc_length, LinearRegressionSlope(price = low(PERIOD = agperiod6), length = ProjectionOsc_length));

def ProjectionOsc_diffAG1 = MaxBoundAG1 - MinBoundAG1;
def ProjectionOsc_diffAG2 = MaxBoundAG2 - MinBoundAG2;
def ProjectionOsc_diffAG3 = MaxBoundAG3 - MinBoundAG3;
def ProjectionOsc_diffAG4 = MaxBoundAG4 - MinBoundAG4;
def ProjectionOsc_diffAG5 = MaxBoundAG5 - MinBoundAG5;
def ProjectionOsc_diffAG6 = MaxBoundAG6 - MinBoundAG6;

def PROSCAG1 = if ProjectionOsc_diffAG1 != 0 then 100 * (close(PERIOD = agperiod1) - MinBoundAG1) / ProjectionOsc_diffAG1 else 0;
def PROSCAG2 = if ProjectionOsc_diffAG2 != 0 then 100 * (close(PERIOD = agperiod2) - MinBoundAG2) / ProjectionOsc_diffAG2 else 0;
def PROSCAG3 = if ProjectionOsc_diffAG3 != 0 then 100 * (close(PERIOD = agperiod3) - MinBoundAG3) / ProjectionOsc_diffAG3 else 0;
def PROSCAG4 = if ProjectionOsc_diffAG4 != 0 then 100 * (close(PERIOD = agperiod4) - MinBoundAG4) / ProjectionOsc_diffAG4 else 0;
def PROSCAG5 = if ProjectionOsc_diffAG5 != 0 then 100 * (close(PERIOD = agperiod5) - MinBoundAG5) / ProjectionOsc_diffAG5 else 0;
def PROSCAG6 = if ProjectionOsc_diffAG6 != 0 then 100 * (close(PERIOD = agperiod5) - MinBoundAG6) / ProjectionOsc_diffAG6 else 0;



# ========================================
# ========================================================
# =============== MULTIPLE TIME FRAME CONDITIONS ==================
#MACD
def condition1AG1 = ValueAG1[1] <= ValueAG1;
def condition1AG2 = ValueAG2[1] <= ValueAG2;
def condition1AG3 = ValueAG3[1] <= ValueAG3;
def condition1AG4 = ValueAG4[1] <= ValueAG4;
def condition1AG5 = ValueAG5[1] <= ValueAG5;
def condition1AG6 = ValueAG6[1] <= ValueAG6;

def condition1DAG1 = ValueAG1[1] > ValueAG1;
def condition1DAG2 = ValueAG2[1] > ValueAG2;
def condition1DAG3 = ValueAG3[1] > ValueAG3;
def condition1DAG4 = ValueAG4[1] > ValueAG4;
def condition1DAG5 = ValueAG5[1] > ValueAG5;
def condition1DAG6 = ValueAG6[1] > ValueAG6;

def condition2AG1 = (RSI_1[3] < RSI_1) is true or (RSI_1 >= 80) is true;
def condition2DAG1 = (RSI_1[3] > RSI_1) is true or (RSI_1 < 20) is true;

def condition2AG2 = (RSI_2[3] < RSI_2) is true or (RSI_2 >= 80) is true;
def condition2DAG2 = (RSI_2[3] > RSI_2) is true or (RSI_2 < 20) is true;

def condition2AG3 = (RSI_3[3] < RSI_3) is true or (RSI_3 >= 80) is true;
def condition2DAG3 = (RSI_3[3] > RSI_3) is true or (RSI_3 < 20) is true;

def condition2AG4 = (RSI_4[3] < RSI_4) is true or (RSI_4 >= 80) is true;
def condition2DAG4 = (RSI_4[3] > RSI_4) is true or (RSI_4 < 20) is true;

def condition2AG5 = (RSI_5[3] < RSI_5) is true or (RSI_5 >= 80) is true;
def condition2DAG5 = (RSI_5[3] > RSI_5) is true or (RSI_5 < 20) is true;

def condition2AG6 = (RSI_6[3] < RSI_6) is true or (RSI_6 >= 80) is true;
def condition2DAG6 = (RSI_6[3] > RSI_6) is true or (RSI_6 < 20) is true;   

def condition3AG1 = (MoneyFlowIndexAG1[2] < MoneyFlowIndexAG1) is true or (MoneyFlowIndexAG1 > 85) is true;
def condition3DAG1 = (MoneyFlowIndexAG1[2] > MoneyFlowIndexAG1) is true or (MoneyFlowIndexAG1 < 20) is true;
def condition3AG2 = (MoneyFlowIndexAG2[2] < MoneyFlowIndexAG2) is true or (MoneyFlowIndexAG2 > 85) is true;
def condition3DAG2 = (MoneyFlowIndexAG2[2] > MoneyFlowIndexAG2) is true or (MoneyFlowIndexAG2 < 20) is true;
def condition3AG3 = (MoneyFlowIndexAG3[2] < MoneyFlowIndexAG3) is true or (MoneyFlowIndexAG3 > 85) is true;
def condition3DAG3 = (MoneyFlowIndexAG3[2] > MoneyFlowIndexAG3) is true or (MoneyFlowIndexAG3 < 20) is true;
def condition3AG4 = (MoneyFlowIndexAG4[2] < MoneyFlowIndexAG4) is true or (MoneyFlowIndexAG4 > 85) is true;
def condition3DAG4 = (MoneyFlowIndexAG4[2] > MoneyFlowIndexAG4) is true or (MoneyFlowIndexAG4 < 20) is true;
def condition3AG5 = (MoneyFlowIndexAG5[2] < MoneyFlowIndexAG5) is true or (MoneyFlowIndexAG5 > 85) is true;
def condition3DAG5 = (MoneyFlowIndexAG5[2] > MoneyFlowIndexAG5) is true or (MoneyFlowIndexAG5 < 20) is true;
def condition3AG6 = (MoneyFlowIndexAG6[2] < MoneyFlowIndexAG6) is true or (MoneyFlowIndexAG6 > 85) is true;
def condition3DAG6 = (MoneyFlowIndexAG6[2] > MoneyFlowIndexAG6) is true or (MoneyFlowIndexAG6 < 20) is true;


def condition5AG1 = CIP_UPAG1;
def condition5DAG1 = CIP_DOWNAG1;
def condition5AG2 = CIP_UPAG2;
def condition5DAG2 = CIP_DOWNAG2;
def condition5AG3 = CIP_UPAG3;
def condition5DAG3 = CIP_DOWNAG3;
def condition5AG4 = CIP_UPAG4;
def condition5DAG4 = CIP_DOWNAG4;
def condition5AG5 = CIP_UPAG5;
def condition5DAG5 = CIP_DOWNAG5;
def condition5AG6 = CIP_UPAG6;
def condition5DAG6 = CIP_DOWNAG6;

# ========= EMA 1 ====================
def condition6AG1 = (price >= AvgExpAG1) and (AvgExpAG1[2] <= AvgExpAG1);
def condition6DAG1 = (price < AvgExpAG1) and (AvgExpAG1[2] > AvgExpAG1);
def condition6AG2 = (price >= AvgExpAG2) and (AvgExpAG2[2] <= AvgExpAG2);
def condition6DAG2 = (price < AvgExpAG2) and (AvgExpAG2[2] > AvgExpAG2);
def condition6AG3 = (price >= AvgExpAG3) and (AvgExpAG3[2] <= AvgExpAG3);
def condition6DAG3 = (price < AvgExpAG3) and (AvgExpAG3[2] > AvgExpAG3);
def condition6AG4 = (price >= AvgExpAG4) and (AvgExpAG4[2] <= AvgExpAG4);
def condition6DAG4 = (price < AvgExpAG4) and (AvgExpAG4[2] > AvgExpAG4);
def condition6AG5 = (price >= AvgExpAG5) and (AvgExpAG5[2] <= AvgExpAG5);
def condition6DAG5 = (price < AvgExpAG5) and (AvgExpAG5[2] > AvgExpAG5);
def condition6AG6 = (price >= AvgExpAG6) and (AvgExpAG6[2] <= AvgExpAG6);
def condition6DAG6 = (price < AvgExpAG6) and (AvgExpAG6[2] > AvgExpAG6);

# ============ EMA 2 =================================
def condition7AG1 = (price >= AvgExp2AG1) and (AvgExp2AG1[2] <= AvgExp2AG1);
def condition7DAG1 = (price < AvgExp2AG1) and (AvgExp2AG1[2] > AvgExp2AG1);
def condition7AG2 = (price >= AvgExp2AG2) and (AvgExp2AG2[2] <= AvgExp2AG2);
def condition7DAG2 = (price < AvgExp2AG2) and (AvgExp2AG2[2] > AvgExp2AG2);
def condition7AG3 = (price >= AvgExp2AG3) and (AvgExp2AG3[2] <= AvgExp2AG3);
def condition7DAG3 = (price < AvgExp2AG3) and (AvgExp2AG3[2] > AvgExp2AG3);
def condition7AG4 = (price >= AvgExp2AG4) and (AvgExp2AG4[2] <= AvgExp2AG4);
def condition7DAG4 = (price < AvgExp2AG4) and (AvgExp2AG4[2] > AvgExp2AG4);
def condition7AG5 = (price >= AvgExp2AG5) and (AvgExp2AG5[2] <= AvgExp2AG5);
def condition7DAG5 = (price < AvgExp2AG5) and (AvgExp2AG5[2] > AvgExp2AG5);
def condition7AG6 = (price >= AvgExp2AG6) and (AvgExp2AG6[2] <= AvgExp2AG6);
def condition7DAG6 = (price < AvgExp2AG6) and (AvgExp2AG6[2] > AvgExp2AG6);

# ================== DMI ==================================
def CONDITION8AG1 = "DI+AG1" > "DI-AG1";
def CONDITION8AG2 = "DI+AG2" > "DI-AG2";
def CONDITION8AG3 = "DI+AG3" > "DI-AG3";
def CONDITION8AG4 = "DI+AG4" > "DI-AG4";
def CONDITION8AG5 = "DI+AG5" > "DI-AG5";
def CONDITION8AG6 = "DI+AG6" > "DI-AG6";

def CONDITION8DAG1 = "DI+AG1" < "DI-AG1";
def CONDITION8DAG2 = "DI+AG2" < "DI-AG2";
def CONDITION8DAG3 = "DI+AG3" < "DI-AG3";
def CONDITION8DAG4 = "DI+AG4" < "DI-AG4";
def CONDITION8DAG5 = "DI+AG5" < "DI-AG5";
def CONDITION8DAG6 = "DI+AG6" < "DI-AG6";

# ============== TREND PERIODS ====================
def condition9AG1 = PeriodsAG1 > 0;
def condition9AG2 = PeriodsAG2 > 0;
def condition9AG3 = PeriodsAG3 > 0;
def condition9AG4 = PeriodsAG4 > 0;
def condition9AG5 = PeriodsAG5 > 0;
def condition9AG6 = PeriodsAG6 > 0;

def condition9DAG1 = PeriodsAG1 < 0;
def condition9DAG2 = PeriodsAG2 < 0;
def condition9DAG3 = PeriodsAG3 < 0;
def condition9DAG4 = PeriodsAG4 < 0;
def condition9DAG5 = PeriodsAG5 < 0;
def condition9DAG6 = PeriodsAG6 < 0;

# ============= POLARIZED FRACTAL ============================================

def condition10AG1 = PFEAG1 > 0;
def condition10AG2 = PFEAG2 > 0;
def condition10AG3 = PFEAG3 > 0;
def condition10AG4 = PFEAG4 > 0;
def condition10AG5 = PFEAG5 > 0;
def condition10AG6 = PFEAG6 > 0;

def condition10DAG1 = PFEAG1 < 0;
def condition10DAG2 = PFEAG2 < 0;
def condition10DAG3 = PFEAG3 < 0;
def condition10DAG4 = PFEAG4 < 0;
def condition10DAG5 = PFEAG5 < 0;
def condition10DAG6 = PFEAG6 < 0;

# ============ BOLLINGER%B ===================
def condition11AG1 = PercentBAG1 > HalfLine;
def condition11AG2 = PercentBAG2 > HalfLine;
def condition11AG3 = PercentBAG3 > HalfLine;
def condition11AG4 = PercentBAG4 > HalfLine;
def condition11AG5 = PercentBAG5 > HalfLine;
def condition11AG6 = PercentBAG6 > HalfLine;

def condition11DAG1 = PercentBAG1 < HalfLine;
def condition11DAG2 = PercentBAG2 < HalfLine;
def condition11DAG3 = PercentBAG3 < HalfLine;
def condition11DAG4 = PercentBAG4 < HalfLine;
def condition11DAG5 = PercentBAG5 < HalfLine;
def condition11DAG6 = PercentBAG6 < HalfLine;

# ================
def condition_BandRevDnAG1 = (Upper_BandSAG1 > Upper_BandK2AG1);
def condition_BandRevDnAG2 = (Upper_BandSAG2 > Upper_BandK2AG2);
def condition_BandRevDnAG3 = (Upper_BandSAG3 > Upper_BandK2AG3);
def condition_BandRevDnAG4 = (Upper_BandSAG4 > Upper_BandK2AG4);
def condition_BandRevDnAG5 = (Upper_BandSAG5 > Upper_BandK2AG5);
def condition_BandRevDnAG6 = (Upper_BandSAG6 > Upper_BandK2AG6);

def condition_BandRevUpAG1 = (Lower_BandSAG1 < Lower_BandK2AG1);
def condition_BandRevUpAG2 = (Lower_BandSAG2 < Lower_BandK2AG2);
def condition_BandRevUpAG3 = (Lower_BandSAG3 < Lower_BandK2AG3);
def condition_BandRevUpAG4 = (Lower_BandSAG4 < Lower_BandK2AG4);
def condition_BandRevUpAG5 = (Lower_BandSAG5 < Lower_BandK2AG5);
def condition_BandRevUpAG6 = (Lower_BandSAG6 < Lower_BandK2AG6);

def condition12AG1 = (Upper_BandSAG1[1] <= Upper_BandSAG1) and (Lower_BandSAG1[1] <= Lower_BandSAG1);
def condition12AG2 = (Upper_BandSAG2[1] <= Upper_BandSAG2) and (Lower_BandSAG2[1] <= Lower_BandSAG2);
def condition12AG3 = (Upper_BandSAG3[1] <= Upper_BandSAG3) and (Lower_BandSAG3[1] <= Lower_BandSAG3);
def condition12AG4 = (Upper_BandSAG4[1] <= Upper_BandSAG4) and (Lower_BandSAG4[1] <= Lower_BandSAG4);
def condition12AG5 = (Upper_BandSAG5[1] <= Upper_BandSAG5) and (Lower_BandSAG5[1] <= Lower_BandSAG5);
def condition12AG6 = (Upper_BandSAG6[1] <= Upper_BandSAG6) and (Lower_BandSAG6[1] <= Lower_BandSAG6);

def condition12DAG1 = (Upper_BandSAG1[1] > Upper_BandSAG1) and (Lower_BandSAG1[1] > Lower_BandSAG1);
def condition12DAG2 = (Upper_BandSAG2[1] > Upper_BandSAG2) and (Lower_BandSAG2[1] > Lower_BandSAG2);
def condition12DAG3 = (Upper_BandSAG3[1] > Upper_BandSAG3) and (Lower_BandSAG3[1] > Lower_BandSAG3);
def condition12DAG4 = (Upper_BandSAG4[1] > Upper_BandSAG4) and (Lower_BandSAG4[1] > Lower_BandSAG4);
def condition12DAG5 = (Upper_BandSAG5[1] > Upper_BandSAG5) and (Lower_BandSAG5[1] > Lower_BandSAG5);
def condition12DAG6 = (Upper_BandSAG6[1] > Upper_BandSAG6) and (Lower_BandSAG6[1] > Lower_BandSAG6);

# ============= KLINGER ========================

def CONDITION13AG1 = KVOscAG1 > TriggerLineAG1;
def CONDITION13AG2 = KVOscAG2 > TriggerLineAG2;
def CONDITION13AG3 = KVOscAG3 > TriggerLineAG3;
def CONDITION13AG4 = KVOscAG4 > TriggerLineAG4;
def CONDITION13AG5 = KVOscAG5 > TriggerLineAG5;
def CONDITION13AG6 = KVOscAG6 > TriggerLineAG6;

def CONDITION13DAG1 = KVOscAG1 < TriggerLineAG1;
def CONDITION13DAG2 = KVOscAG2 < TriggerLineAG2;
def CONDITION13DAG3 = KVOscAG3 < TriggerLineAG3;
def CONDITION13DAG4 = KVOscAG4 < TriggerLineAG4;
def CONDITION13DAG5 = KVOscAG5 < TriggerLineAG5;
def CONDITION13DAG6 = KVOscAG6 < TriggerLineAG6;

# =================== PROJECTION OSC ============
def condition14AG1 = PROSCAG1 > 50;
def condition14AG2 = PROSCAG2 > 50;
def condition14AG3 = PROSCAG3 > 50;
def condition14AG4 = PROSCAG4 > 50;
def condition14AG5 = PROSCAG5 > 50;
def condition14AG6 = PROSCAG6 > 50;

def condition14DAG1 = PROSCAG1 < 50;
def condition14DAG2 = PROSCAG2 < 50;
def condition14DAG3 = PROSCAG3 < 50;
def condition14DAG4 = PROSCAG4 < 50;
def condition14DAG5 = PROSCAG5 < 50;
def condition14DAG6 = PROSCAG6 < 50;









# ===================
# ====================================
# ==================================================

script WMA_Smooth {
    input price = hl2;
    plot smooth = (4 * price
+ 3 * price[1]
+ 2 * price[2]
+ price[3]) / 10;
}

#script Phase_Accumulation {
# This is Ehler's Phase Accumulation code. It has a full cycle delay.
# However, it computes the correction factor to a very high degree.
# ============= *** NOT CODED MTF ***  ===============================
 

# ======== CHART LEVEL CONDITIONS ===================

def condition_BandRevDn = (Upper_BandS > Upper_BandK2);
def condition_BandRevUp = (Lower_BandS < Lower_BandK2);

def condition1 = Value[1] <= Value;
def condition1D = Value[1] > Value;

def condition2 = (RSI[3] < RSI) is true or (RSI >= 80) is true;
def condition2D = (RSI[3] > RSI) is true or (RSI < 20) is true;

def condition3 = (MoneyFlowIndex[2] < MoneyFlowIndex) is true or (MoneyFlowIndex > 85) is true;
def condition3D = (MoneyFlowIndex[2] > MoneyFlowIndex) is true or (MoneyFlowIndex < 20) is true;

def condition4 = (Intermed[1] <= Intermed) or (NearT >= MidLine);
def condition4D = (Intermed[1] > Intermed) or (NearT < MidLine);

def condition5 = CIP_UP;
def condition5D = CIP_DOWN;

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

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

def condition8 = Osc >= ZeroLine;
def condition8D = Osc < ZeroLine;

def condition9 = Periods > 0;
def condition9D = Periods < 0;

def condition10 = PFE > 0;
def condition10D = PFE < 0;

def condition11 = PercentB > HalfLine;
def condition11D = PercentB < HalfLine;

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

def condition13 = (KVOH > 0);
def condition13D = (KVOH < 0);

def condition14 = PROSC > 50;
def condition14D = PROSC < 50;

def UPD = AvgExp8[1] < AvgExp8;
def UPW = AvgExp9[1] < AvgExp9;

def UPEMA = AvgExp8[1] < AvgExp8;
def DOWNEMA = AvgExp8[1] > AvgExp8;

def UPEMA2 = AvgExp9[1] < AvgExp9;
def DOWNEMA2 = AvgExp9[1] > AvgExp9;

def UP8 = UPEMA and UPEMA2;
def DOWN8 = DOWNEMA and DOWNEMA2;



def conditionK1UP = price >= Upper_BandK;
def conditionK2UP = (Upper_BandK[1] < Upper_BandK) and (Lower_BandK[1] < Lower_BandK);
def conditionK3DN = (Upper_BandK[1] > Upper_BandK) and (Lower_BandK[1] > Lower_BandK);
def conditionK4DN = price < Lower_BandK;

#def Agreement_Level = condition1 + condition2 + condition3 + condition4 + condition5 + condition6 + condition7 + condition8 + condition9 + condition10 + condition11 + condition12 + condition13 + condition14 + conditionK1UP + conditionK2UP;
#def Agreement_LevelD = (condition1D + condition2D + condition3D + condition4D + condition5D + condition6D + condition7D + condition8D + condition9D + condition10D + condition11D + condition12D + condition13D + condition14D + conditionK3DN + conditionK4DN);
# ============================
# =========================================

#Testing
def Agreement_LevelMTF = condition1AG1 + condition1AG2 + condition1AG3 + condition1AG4 + condition1AG5 + condition1AG6 + condition2AG1 + condition2AG2 + condition2AG3 + condition2AG4 + condition2AG5 + condition2AG6 + condition3AG1 + condition3AG2 + condition3AG3 + condition3AG4 + condition3AG5 + condition3AG6 + condition5AG1 +  condition5AG2 + condition5AG3 + condition5AG4 + condition5AG5 + condition5AG6 + condition6AG1 + condition6AG2 + condition6AG3 + condition6AG4 + condition6AG5 + condition6AG6 + condition7AG1 + condition7AG2 + condition7AG3 + condition7AG4 + condition7AG5 + condition7AG6 + CONDITION8AG1 + CONDITION8AG2 + CONDITION8AG3 + CONDITION8AG4 + CONDITION8AG5 + CONDITION8AG6 + condition9AG1 + condition9AG2 + condition9AG3 + condition9AG4 + condition9AG5 + condition9AG6 + condition10AG1 +  condition10AG2 + condition10AG3 + condition10AG4 + condition10AG5 + condition10AG6 + condition11AG1 + condition11AG2 + condition11AG3 + condition11AG4 + condition11AG5 + condition11AG6 + condition12AG1 + condition12AG2 + condition12AG3 + condition12AG4 + condition12AG5 + condition12AG6 + CONDITION13AG1 + CONDITION13AG2 + CONDITION13AG3 + CONDITION13AG4 + CONDITION13AG5 + CONDITION13AG6 + condition14AG1 + condition14AG2 + condition14AG3 + condition14AG4 + condition14AG5 + condition14AG6        ;

def Agreement_LevelD_MTF = condition1DAG1 + condition1DAG2 + condition1DAG3 + condition1DAG4 + condition1DAG5 + condition1DAG6 + condition2DAG1 + condition2DAG2 + condition2DAG3 + condition2DAG4 + condition2DAG5 + condition2DAG6 + condition3DAG1 + condition3DAG2 + condition3DAG3 + condition3DAG4 + condition3DAG5 + condition3DAG6 + condition5DAG1 + condition5DAG2 + condition5DAG3 + condition5DAG4 + condition5DAG5 + condition5DAG6 + condition6DAG1 + condition6DAG2 + condition6DAG3 + condition6DAG4 + condition6DAG5 + condition6DAG6 + condition7DAG1 + condition7DAG2 + condition7DAG3 + condition7DAG4 + condition7DAG5 + condition7DAG6 + CONDITION8DAG1 + CONDITION8DAG2 + CONDITION8DAG3 + CONDITION8DAG4 + CONDITION8DAG5 + CONDITION8DAG6 + condition9DAG1 + condition9DAG2 + condition9DAG3 + condition9DAG4 + condition9DAG5 + condition9DAG6 + condition10DAG1 + condition10DAG2 + condition10DAG3 + condition10DAG4 + condition10DAG5 + condition10DAG6 + condition11DAG1 + condition11DAG2 + condition11DAG3 + condition11DAG4 + condition11DAG5 + condition11DAG6 + condition12DAG1 + condition12DAG2 + condition12DAG3 + condition12DAG4 + condition12DAG5 + condition12DAG6 + CONDITION13DAG1 + CONDITION13DAG2 + CONDITION13DAG3 + CONDITION13DAG4 + CONDITION13DAG5 + CONDITION13DAG6 + condition14DAG1 + condition14DAG2 + condition14DAG3 + condition14DAG4 + condition14DAG5 + condition14DAG6 ;
# ======================
# =======================================
#def Consensus_Level = Agreement_Level - Agreement_LevelD;
Def Consensus_LevelMTF = Agreement_LevelMTF - Agreement_LevelD_MTF;
def MomentumUPMTF = Consensus_LevelMTF > Consensus_LevelMTF[1];
def MomentumDNMTF = Consensus_LevelMTF < Consensus_LevelMTF[1];
def Agreement_UP_L = Agreement_LevelMTF > Agreement_LevelMTF[1];
def Agreement_DN_S = Agreement_LevelD_MTF > Agreement_LevelD_MTF[1];
#def UP2 = Consensus_Level >= 4;
#def DOWN2 = Consensus_Level < -5;

#def MomentumUP = Consensus_Level[1] < Consensus_Level;
#def MomentumDOWN = Consensus_Level[1] > Consensus_Level;

#def Long_Only = UP + UP2 + UP3 + UP4 + UP5 + UP6;
#def Short_Only = DOWN + DOWN2 + DOWN3 + DOWN4 + DOWN5 + DOWN6;
#def Consensus_Bias = Long_Only - Short_Only;

def RUP = UPC1 + UPC2 + R1UP + R2UP + R3UP + R4UP + R5UP + R6UP + R7UP + R8UP + R9UP + R10UP + R11UP + R12UP;
def RDN = DNC1 + DNC2 + R1DN + R2DN + R3DN + R4DN + R5DN + R6DN + R7DN + R8DN + R9DN + R10DN + R11DN + R12DN;
def ConsensusR = RUP - RDN;
def ConsensusL = RUP > RUP[1] and RUP > RDN;

#def direction = if ConsensusR > Consensus_Bias then 1 else if ConsensusR < Consensus_Bias then -1 else 0;
#C3_MF_Line.AssignValueColor(if paintCandles and ((direction == 1) and (price > C3_MF_Line)) then Color.GREEN else if paintCandles and ((direction == -1) and (price < C3_MF_Line)) then Color.RED else Color.DARK_GRAY);

#testing
plot buySCA = Condition12AG1 and condition8AG1; #AvgExp crosses above AvgExp2 and RUP and MaxTimeUp and long_Only and C3_MF_UPAgg1 and C3_MF_UPAgg2 and C3_MF_UPAgg3 and C3_MF_UPAgg4 and C3_MF_UPAgg5 ; # and Mf_UP1 and MF_UP2 and MF_UP3 and MF_UP4 and MF_UP5 and MF_UP6 and((UP6 == 1) and (Consensus_Bias > 0)) and maxTimeUp ;#highest time expup #direction crosses above 0;
buySCA.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buySCA.SetDefaultColor(CreateColor(58, 194, 129));
buySCA.SetLineWeight(5);

plot sellSCA = Condition12DAG1 and condition8DAG1;
; #AvgExp crosses below AvgExp2 and RDN and MaxTimeDown and Short_Only and C3_MF_DNAgg1 and C3_MF_DNAgg2 and C3_MF_DNAgg3 and C3_MF_DNAgg4 and C3_MF_DNAgg5;# and MF_DN1 and MF_DN2 and MF_DN3 and MF_DN4 and MF_DN5 and MF_DN6 and ((DOWN6) and (Consensus_Bias < 0));  #HighestTime frame EMA down #direction crosses below 0;
sellSCA.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN );
sellSCA.SetDefaultColor(CreateColor(165, 51, 51));
sellSCA.SetLineWeight(5);
#AssignPriceColor(if paintCandles then if direction == 1 then Color.GREEN else if direction == -1 then Color.RED else Color.GRAY else Color.CURRENT);



#AddLabel(yes, if ((UP6 == 1) and (Consensus_Bias > 0)) then " SCALP_LONG " else if ((DOWN6) and (Consensus_Bias < 0)) then " SCALP_SHORT " else " CHOP ", if ((Consensus_Bias > 0) and (UP6 == 1)) then Color.GREEN else if ((Consensus_Bias < 0) and (DOWN6 == 1)) then Color.RED else Color.GRAY);

AddLabel(yes, if (ConsensusR > 0) then " LONG BIAS = %" + Round((ConsensusR / 14) * 100, 1) + " " else if (ConsensusR < 0) then  " SHORT BIAS = %" + Round(((ConsensusR * -1) / 14) * 100, 1) + " " else " CHOP =" + Round((ConsensusR / 14) * 100, 1) + " ", if (ConsensusR > 0) then Color.GREEN else if (ConsensusR < 0) then Color.RED else Color.GRAY);

#Alert(AvgExp crosses above AvgExp2 and RUP and MaxTimeUp and Long_Only and C3_MF_UPAgg1 and C3_MF_UPAgg2 and C3_MF_UPAgg3 and C3_MF_UPAgg4 and C3_MF_UPAgg5, "long", Alert.BAR, Sound.Ding);
#Alert(AvgExp crosses below AvgExp2 and RDN and MaxTimeDown and Short_Only and C3_MF_DNAgg1 and C3_MF_DNAgg2 and C3_MF_DNAgg3 and C3_MF_DNAgg4 and C3_MF_DNAgg5, "short", Alert.BAR, Sound.Chimes);
 
Thank you! I'm currently implementing this strategy with reading the tape and it's working pretty well, almost like a double confirmation with reading tape.
That's awesome, would you mind elaborating a little more on the cues you're looking for on the Tape for the second confirmation? I'm currently using the scalper on 9 different intraday timeframes for confirmations.
 
You need to extend the timeframe. Try 10 D/1m or 15D/1m.
Hi @drizzla,
One other thing you can try besides @arm1’s suggestion, is going to settings and turning off fit studies. Hope that helps!

Unfortunately neither of these things worked to prevent the study always appearing to start from zero, at the very beginning of whatever timeframe I choose. But if I scroll forward in time, it becomes a non-issue. Just seems a bit odd, particularly if I am the only one experiencing this.

Here's a pic of the 10D 1min chart (and actually, realizing this is Scalper, and the other was C3 Max, so it's apparently happening on both.)

 
Unfortunately neither of these things worked to prevent the study always appearing to start from zero, at the very beginning of whatever timeframe I choose. But if I scroll forward in time, it becomes a non-issue. Just seems a bit odd, particularly if I am the only one experiencing this.

Here's a pic of the 10D 1min chart (and actually, realizing this is Scalper, and the other was C3 Max, so it's apparently happening on both.)

Hi @drizzla!
It appears to be an issue with your chart settings. I’m not at my office today, when I get back in I’ll share a screenshot of my settings.
 
That's awesome, would you mind elaborating a little more on the cues you're looking for on the Tape for the second confirmation? I'm currently using the scalper on 9 different intraday timeframes for confirmations.
Thank you! I've tested this strategy alone with no news or reading the tape in the strategy and the data says that it's 48.21% with a win rate1:5 risk reward ratio so it's still profitable. Well, the point of reading the tape is to give you information about the current market data... such as buyer & seller volumes. The confirmation really depends on your strategy. I mainly take breakout trades, so for example I look for support that buyers are willing to buy and if those buyers can't hold the support area I take risk and watch the tape to play defense to see if the breakout is real or not. If it's a failed breakout I want to see slow move down and few sellers. Obviously there's a lot of catalyst that plays before you take position such as news, trend, levels, ATRs, then you use the tape to give you more confirmation for your trade.
 
Unfortunately neither of these things worked to prevent the study always appearing to start from zero, at the very beginning of whatever timeframe I choose. But if I scroll forward in time, it becomes a non-issue. Just seems a bit odd, particularly if I am the only one experiencing this.

Here's a pic of the 10D 1min chart (and actually, realizing this is Scalper, and the other was C3 Max, so it's apparently happening on both.)

DH7O5Xg.png
 

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
200 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