PercentR_MAC Indicator with Multi-Choice Smoothing for Thinkorswim

netarchitech

Well-known member
@HighBredCloud GOT IT! 👍 For your review:

percent-R-fourscore.png


average.png


select.png


type.png



Code:
# filename: MR__EZ_PercentR_MAC_
# idea source: @HighBredCloud and https://usethinkscript.com/threads/moving-average-crossover-rsi-indicator-for-thinkorswim.185/

# Code: Thanson Stevens, @korygill and netarchitech

# V11.12.2019 - netarchitech added multiple-choice smoothing per HighBredCloud request


declare lower;

# PercentR_MAC

input length = 14;
input over_Bought = 80;
input over_Sold = 20;

input lowBand = 10; #Smoothing LowerBand
input data = close;
input lower = low; #Research Lower = Low?

def highest = Highest(high, length);
def divisor = highest - Lowest(low, length);
def PI = 3.14159265359;
def a1 = Exp(-PI * Sqrt(2) / lower);
def coeff2 = 2 * a1 * Cos(Sqrt(2) * PI / lower);
def coeff3 = - Power(a1, 2);
def coeff1 = 1 - coeff2 - coeff3;
def filt = coeff1 * (data + (data[1])) / 2 + coeff2 * (filt[1]) + coeff3 * (filt[2]);

input PercentRMALength5 = 5;
input PercentRMALength8 = 8;
#input PercentRMALength13 = 13;
input PercentRAverageType = AverageType.SIMPLE;

# plot and smooth PercentR
plot "%R" = if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor;
"%R".DefineColor("OverBought", GetColor(9)); #GetColor(9));
"%R".DefineColor("Normal", GetColor(7));
"%R".DefineColor("OverSold", GetColor(1)); #GetColor(1));
"%R".AssignValueColor(if "%R" > over_Bought then "%R".Color("OverBought") else if "%R" < over_Sold then "%R".Color("OverSold") else "%R".Color("Normal"));
"%R".SetLineWeight(3);
"%R".Hide();

# plot and smooth the PercentR Moving Averages
def PercentRMA5 = MovingAverage(PercentRAverageType, "%R", PercentRMALength5);
plot PercentRMovAvg5 = PercentRMA5;
PercentRMovAvg5.SetDefaultColor(Color.GREEN);
PercentRMovAvg5.SetLineWeight(3);
PercentRMovAvg5.hide();

def PercentRMA8 = MovingAverage(PercentRAverageType, "%R", PercentRMALength8);
plot PercentRMovAvg8 = PercentRMA8;
PercentRMovAvg8.SetDefaultColor(Color.RED);
PercentRMovAvg8.SetLineWeight(3);
PercentRMovAvg8.hide();

#def PercentRMA13 = MovingAverage(PercentRAverageType, "%R", PercentRMALength13);
#plot PercentRMovAvg13 = PercentRMA13;
#PercentRMovAvg13.SetDefaultColor(Color.ORANGE);
#PercentRMovAvg13.SetLineWeight(2);
#PercentRMovAvg13.hide();


input applySelectSmoothing = yes;

def smooth_it = EhlersSuperSmootherFilter(if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor, lowBand);
def smooth_MA5 = EhlersSuperSmootherFilter(MovingAverage(PercentRAverageType, "%R", PercentRMALength5));
def smooth_MA8 = EhlersSuperSmootherFilter(MovingAverage(PercentRAverageType, "%R", PercentRMALength8));


input SelectSmoothingType = {default "PercentR Only", "MAs Only", "PercentR & MAs", "No Smoothing"};

plot X;
X.AssignValueColor(if "%R" > over_Bought then "%R".Color("OverBought") else if "%R" < over_Sold then "%R".Color("OverSold") else "%R".Color("Normal"));
X.SetLineWeight(3);
plot Y;
Y.SetDefaultColor(Color.GREEN);
Y.SetLineWeight(2);
plot Z;
Z.SetDefaultColor(Color.RED);
Z.SetLineWeight(2);

switch (SelectSmoothingType) {
case "PercentR Only":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
case "MAs Only":
    X = if applySelectSmoothing and "%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "PercentR & MAs":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "No Smoothing":
    X = if applySelectSmoothing and"%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
}

plot OverBought = over_Bought;
OverBought.SetDefaultColor(Color.DARK_RED);
OverBought.HideTitle();

plot OverSold = over_Sold;
OverSold.SetDefaultColor(Color.DARK_GREEN);
OverSold.HideTitle();

plot fifty_line = 50;
fifty_line.SetDefaultColor(GetColor(8));
fifty_line.HideTitle();
fifty_line.SetStyle(Curve.SHORT_DASH);


# plot the Breakout Signals
input showBreakoutSignals = yes;

plot UpSignal = if "%R" crosses above OverSold then OverSold else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(3);
UpSignal.HideTitle();

plot DownSignal = if "%R" crosses below OverBought then OverBought else Double.NaN;
DownSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(3);
DownSignal.HideTitle();


AddCloud(0, over_Sold, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(over_Bought, 100, Color.DARK_RED, Color.DARK_RED);


# Gmode

def lengthRSI = 14;
def price = close;

input averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], lengthRSI);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
RSI.SetDefaultColor(CreateColor(0, 102, 204));
RSI.SetLineWeight(3);
#RSI.HideTitle();
RSI.HideBubble();
RSI.Hide();

input n1 = 9; #Channel Length
input n2 = 26; #Average Length
input n3 = 13; #Short length
def multi = no; #Multi-exchange?

def src0 = hlc3;

def src1 = hlc3(period = AggregationPeriod.MONTH);
def src2 = hlc3(period = AggregationPeriod.MONTH);
def src3 = hlc3(period = AggregationPeriod.MONTH);
def src4 = hlc3(period = AggregationPeriod.MONTH);

script tci {

    input src = hlc3;
    input n1 = 9; #Channel Length
    input n2 = 26; #Average Length
    plot tci = MovAvgExponential((src - MovAvgExponential(src, n1)) / (0.025 * MovAvgExponential(AbsValue(src - MovAvgExponential(src, n1)), n1)), n2) + 50;
    tci.Hide();
}

#mf(src) => rsi(sum(volume * (change(src) <= 0 ? 0 : src), n3), sum(volume * (change(src) >= 0 ? 0 : src), n3))

script mf {

    input src = hlc3;
    input n3 = 13; #Short length


    def rsi = reference RSI();


    #plot mf = rsi(Sum(volume * (if Average(src) <= 0 then 0 else src), n3), Sum(volume * (if Average(src) >= 0 then 0 else src), n3));
    plot mf = RSI(n3, src);
    mf.Hide();
}

script willy {

    input src = hlc3;
    input n2 = 26; #Average Length
    plot willy = 60 * (src - Highest(src, n2)) / (Highest(src, n2) - Lowest(src, n2)) + 80;
    willy.Hide();

}

#csi(src) => avg(rsi(src, n3),tsi(src0,n1,n2)*50+50)

script csi {

    input src = hlc3;
    input n1 = 9; #Channel Length
    input n2 = 26; #Average Length
    input n3 = 13; #Short length

    def rsi = reference RSI();

    plot csi = RSI(n3, src) + TrueStrengthIndex(n1, n2) / 2 * 50 + 50;
    csi.Hide();

}

script godmode {

    input src = hlc3;
    def rsi = reference RSI();
    plot godmode = (tci(src) + CSI(src) + mf(src) + willy(src)) / 4;
    godmode.Hide();

}

script tradition {

    input src = hlc3;
    input n3 = 13; #Short length

    def rsi = reference RSI();

    plot tradition = (tci(src) + mf(src) + RSI(n3, src)) / 3;
    tradition.Hide();

}


def wt1 = if multi then (godmode(src0) + godmode(src1) + godmode(src2) + godmode(src3) + godmode(src4) / 5) else tradition(src0);

def wt2 = SimpleMovingAvg(wt1, 6);

def extended = if wt2 < 20 then wt2 + 5 else if wt2 > 80 then wt2 - 5 else Double.NaN;

plot wta = wt1;
wta.SetDefaultColor(Color.GREEN);
wta.SetLineWeight(2);
wta.Hide();

plot wtb = wt2;
wtb.SetDefaultColor(Color.RED);
wtb.SetLineWeight(2);
wtb.Hide();

plot ext = extended; #Caution!
ext.SetPaintingStrategy(PaintingStrategy.POINTS);
ext.SetDefaultColor(Color.YELLOW);
ext.SetLineWeight(3);
 
@netarchitech WOW...OK...let me test it now...I was just playing around with the PercentR_MAC settings on the previous version. Glad I checked back here...By the looks of it the options are exactly what I was thinking. Very Nice Job! Now lets just hope it performs as good as it looks...
 
@netarchitech OK I figured this out but to be clear for others to know...

X Y Z plots are the ones that you can actually change in terms of line thickness and color etc...Plot X appears to be the %R...and plot Y is the PercentRMA5 and plot Z is PercentRMA8 in the Plots section.

IF you could update the script and change the "percent r average type" to "PercentR MA type" under the inputs...I think that's what you meant...as the actual PercentR is in wilders I believe...IF that part got me a bit confused it will confuse others as well as I thought I was changing the PercentR and not the moving averages like I wanted to.

Also can you just change the "percent rma lenght5" to "PercentR MA length 1" and "percent rma lenght8" to PercentR MA lenght 2" ? Because so far...the optimal settings that I found when the smoothing is turned on the MA's is:

moving average 1 set to 3 periods
moving average 2 set to 5 periods
Simple Average on a 5 minute chart...this could vary on different timeframes.

When I first uploaded this new version of PRMAC and compared it to the previous PRMAC_V2 I noticed the difference in the moving averages as you can see below even though they were set to the same settings...(I took the PercentR out so you can see the differences.) I don't know if that was an isolated incident or if this will change later as after I switched and kept playing with the SuperSmootherFilter it seemed to go back to normal...just a heads up.

Other than what that...this PercentR_MAC ROCKS! WOW...Now the user can choose whatever they want in their options. Fully customizable...EXCELLENT!

 
@HighBredCloud Updated code for your review:

Code:
# filename: MR__EZ_PercentR_MAC_
# idea source: @HighBredCloud and https://usethinkscript.com/threads/moving-average-crossover-rsi-indicator-for-thinkorswim.185/

# Code: Thanson Stevens, @korygill and netarchitech

# V11.11.2019 - netarchitech added multiple-choice smoothing per HighBredCloud request
# V11.12.2019 - netarchitech modified several variables per HighBredCloud request


declare lower;

# PercentR_MAC

input length = 14;
input over_Bought = 80;
input over_Sold = 20;

input lowBand = 10; #Smoothing LowerBand
input data = close;
input lower = low; #Research Lower = Low?

def highest = Highest(high, length);
def divisor = highest - Lowest(low, length);
def PI = 3.14159265359;
def a1 = Exp(-PI * Sqrt(2) / lower);
def coeff2 = 2 * a1 * Cos(Sqrt(2) * PI / lower);
def coeff3 = - Power(a1, 2);
def coeff1 = 1 - coeff2 - coeff3;
def filt = coeff1 * (data + (data[1])) / 2 + coeff2 * (filt[1]) + coeff3 * (filt[2]);

input PercentRMALength1 = 5;
input PercentRMALength2 = 8;
input PercentRMAType = AverageType.SIMPLE;

# plot and smooth PercentR
plot "%R" = if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor;
"%R".DefineColor("OverBought", GetColor(9)); #GetColor(9));
"%R".DefineColor("Normal", GetColor(7));
"%R".DefineColor("OverSold", GetColor(1)); #GetColor(1));
"%R".AssignValueColor(if "%R" > over_Bought then "%R".Color("OverBought") else if "%R" < over_Sold then "%R".Color("OverSold") else "%R".Color("Normal"));
"%R".SetLineWeight(3);
"%R".Hide();

# plot and smooth the PercentR Moving Averages
def PercentRMA5 = MovingAverage(PercentRMAType, "%R", PercentRMALength1);
plot PercentRMovAvg5 = PercentRMA5;
PercentRMovAvg5.SetDefaultColor(Color.GREEN);
PercentRMovAvg5.SetLineWeight(3);
PercentRMovAvg5.hide();

def PercentRMA8 = MovingAverage(PercentRMAType, "%R", PercentRMALength2);
plot PercentRMovAvg8 = PercentRMA8;
PercentRMovAvg8.SetDefaultColor(Color.RED);
PercentRMovAvg8.SetLineWeight(3);
PercentRMovAvg8.hide();

input applySelectSmoothing = yes;

def smooth_it = EhlersSuperSmootherFilter(if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor, lowBand);
def smooth_MA5 = EhlersSuperSmootherFilter(MovingAverage(PercentRMAType, "%R", PercentRMALength1));
def smooth_MA8 = EhlersSuperSmootherFilter(MovingAverage(PercentRMAType, "%R", PercentRMALength2));


input SelectSmoothingType = {default "PercentR Only", "MAs Only", "PercentR & MAs", "No Smoothing"};

plot X;
X.AssignValueColor(if "%R" > over_Bought then "%R".Color("OverBought") else if "%R" < over_Sold then "%R".Color("OverSold") else "%R".Color("Normal"));
X.SetLineWeight(3);
plot Y;
Y.SetDefaultColor(Color.GREEN);
Y.SetLineWeight(2);
plot Z;
Z.SetDefaultColor(Color.RED);
Z.SetLineWeight(2);

switch (SelectSmoothingType) {
case "PercentR Only":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
case "MAs Only":
    X = if applySelectSmoothing and "%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "PercentR & MAs":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "No Smoothing":
    X = if applySelectSmoothing and"%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
}

plot OverBought = over_Bought;
OverBought.SetDefaultColor(Color.DARK_RED);
OverBought.HideTitle();

plot OverSold = over_Sold;
OverSold.SetDefaultColor(Color.DARK_GREEN);
OverSold.HideTitle();

plot fifty_line = 50;
fifty_line.SetDefaultColor(GetColor(8));
fifty_line.HideTitle();
fifty_line.SetStyle(Curve.SHORT_DASH);


# plot the Breakout Signals
input showBreakoutSignals = yes;

plot UpSignal = if "%R" crosses above OverSold then OverSold else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(3);
UpSignal.HideTitle();

plot DownSignal = if "%R" crosses below OverBought then OverBought else Double.NaN;
DownSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(3);
DownSignal.HideTitle();


AddCloud(0, over_Sold, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(over_Bought, 100, Color.DARK_RED, Color.DARK_RED);


# Gmode

def lengthRSI = 14;
def price = close;

def averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], lengthRSI);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
RSI.SetDefaultColor(CreateColor(0, 102, 204));
RSI.SetLineWeight(3);
#RSI.HideTitle();
RSI.HideBubble();
RSI.Hide();

input n1 = 9; #Channel Length
input n2 = 26; #Average Length
input n3 = 13; #Short length
def multi = no; #Multi-exchange?

def src0 = hlc3;

def src1 = hlc3(period = AggregationPeriod.MONTH);
def src2 = hlc3(period = AggregationPeriod.MONTH);
def src3 = hlc3(period = AggregationPeriod.MONTH);
def src4 = hlc3(period = AggregationPeriod.MONTH);

script tci {

    input src = hlc3;
    input n1 = 9; #Channel Length
    input n2 = 26; #Average Length
    plot tci = MovAvgExponential((src - MovAvgExponential(src, n1)) / (0.025 * MovAvgExponential(AbsValue(src - MovAvgExponential(src, n1)), n1)), n2) + 50;
    tci.Hide();
}

#mf(src) => rsi(sum(volume * (change(src) <= 0 ? 0 : src), n3), sum(volume * (change(src) >= 0 ? 0 : src), n3))

script mf {

    input src = hlc3;
    input n3 = 13; #Short length


    def rsi = reference RSI();


    #plot mf = rsi(Sum(volume * (if Average(src) <= 0 then 0 else src), n3), Sum(volume * (if Average(src) >= 0 then 0 else src), n3));
    plot mf = RSI(n3, src);
    mf.Hide();
}

script willy {

    input src = hlc3;
    input n2 = 26; #Average Length
    plot willy = 60 * (src - Highest(src, n2)) / (Highest(src, n2) - Lowest(src, n2)) + 80;
    willy.Hide();

}

#csi(src) => avg(rsi(src, n3),tsi(src0,n1,n2)*50+50)

script csi {

    input src = hlc3;
    input n1 = 9; #Channel Length
    input n2 = 26; #Average Length
    input n3 = 13; #Short length

    def rsi = reference RSI();

    plot csi = RSI(n3, src) + TrueStrengthIndex(n1, n2) / 2 * 50 + 50;
    csi.Hide();

}

script godmode {

    input src = hlc3;
    def rsi = reference RSI();
    plot godmode = (tci(src) + CSI(src) + mf(src) + willy(src)) / 4;
    godmode.Hide();

}

script tradition {

    input src = hlc3;
    input n3 = 13; #Short length

    def rsi = reference RSI();

    plot tradition = (tci(src) + mf(src) + RSI(n3, src)) / 3;
    tradition.Hide();

}


def wt1 = if multi then (godmode(src0) + godmode(src1) + godmode(src2) + godmode(src3) + godmode(src4) / 5) else tradition(src0);

def wt2 = SimpleMovingAvg(wt1, 6);

def extended = if wt2 < 20 then wt2 + 5 else if wt2 > 80 then wt2 - 5 else Double.NaN;

plot wta = wt1;
wta.SetDefaultColor(Color.GREEN);
wta.SetLineWeight(2);
wta.Hide();

plot wtb = wt2;
wtb.SetDefaultColor(Color.RED);
wtb.SetLineWeight(2);
wtb.Hide();

plot ext = extended; #Caution!
ext.SetPaintingStrategy(PaintingStrategy.POINTS);
ext.SetDefaultColor(Color.YELLOW);
ext.SetLineWeight(3);

IF you could update the script and change the "percent r average type" to "PercentR MA type" under the inputs...I think that's what you meant...as the actual PercentR is in wilders I believe...IF that part got me a bit confused it will confuse others as well as I thought I was changing the PercentR and not the moving averages like I wanted to.
Variable Name changes...Done...

FYI...The "Wilders" MA Type is for the other component in the script...the one that plots the yellow dots a/k/a the "Siren" or "Early Warning System" as we discussed a ways back...I removed it so it won't be an issue any longer...Sorry for the confusion...

Also can you just change the "percent rma lenght5" to "PercentR MA length 1" and "percent rma lenght8" to PercentR MA lenght 2" ?
Variable Name changes...Done...

@HighBredCloud Thanks again for the kind words...Looking forward to your additional findings...BTW, a rough %R with smooth MA's is my favorite out of the options :)
 
X Y Z plots are the ones that you can actually change in terms of line thickness and color etc...Plot X appears to be the %R...and plot Y is the PercentRMA5 and plot Z is PercentRMA8 in the Plots section.
@HighBredCloud Yes that's correct:
  • Plot X = %R
  • Plot Y = PercentRMA5
  • PLot Z = PercentRMA8
Upon further reflection, I made a mistake with the variable names...Lesson learned :) Thanks for pointing these issues out...

When I first uploaded this new version of PRMAC and compared it to the previous PRMAC_V2 I noticed the difference in the moving averages as you can see below even though they were set to the same settings...(I took the PercentR out so you can see the differences.) I don't know if that was an isolated incident or if this will change later as after I switched and kept playing with the SuperSmootherFilter it seemed to go back to normal...just a heads up.
Uh-oh...Another anomaly...I'll take a look and let you know what I find...
 
Hey there @HighBredCloud You are certainly welcome...You know, I was thinking about the fact that your thoughts and ideas created the framework of this whole endeavor...so Thank YOU :)

I really like this indicator too! I like having options...right now I prefer the rough %R and smooth MAs, but I can see the value of all the elements being smooth...
...testing this in live market...so far so good...
Go get 'em, @HighBredCloud! We got the AI and HFT's in our sights...building the tools to take the markets back from the automatons :cool:
 
@HighBredCloud Updated code and image for your review:

prmac.png


Code:
# filename: MR__EZ_PercentR_MAC_
# idea source: @HighBredCloud and https://usethinkscript.com/threads/moving-average-crossover-rsi-indicator-for-thinkorswim.185/

# Code: Thanson Stevens, @korygill and netarchitech

# V11.11.2019 - netarchitech added multiple-choice smoothing per HighBredCloud request
# V11.12.2019 - netarchitech modified several variables per HighBredCloud request
# V11.12.2019 - netarchitech modified several inputs per HighBredCloud request


declare lower;

# PercentR_MAC

input length = 14;
def over_Bought = 80;
def over_Sold = 20;

def lowBand = 10; #Smoothing LowerBand
def data = close;
def lower = low; #Research Lower = Low?

def highest = Highest(high, length);
def divisor = highest - Lowest(low, length);
def PI = 3.14159265359;
def a1 = Exp(-PI * Sqrt(2) / lower);
def coeff2 = 2 * a1 * Cos(Sqrt(2) * PI / lower);
def coeff3 = - Power(a1, 2);
def coeff1 = 1 - coeff2 - coeff3;
def filt = coeff1 * (data + (data[1])) / 2 + coeff2 * (filt[1]) + coeff3 * (filt[2]);

input PercentRMALength1 = 3;
input PercentRMALength2 = 5;
input PercentRMAType = AverageType.SIMPLE;

# plot and smooth PercentR
plot "%R" = if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor;
"%R".DefineColor("OverBought", GetColor(9)); #GetColor(9));
"%R".DefineColor("Normal", GetColor(7));
"%R".DefineColor("OverSold", GetColor(1)); #GetColor(1));
"%R".AssignValueColor(if "%R" > over_Bought then "%R".Color("OverBought") else if "%R" < over_Sold then "%R".Color("OverSold") else "%R".Color("Normal"));
"%R".SetLineWeight(3);
"%R".Hide();

# plot and smooth the PercentR Moving Averages
def PercentRMA5 = MovingAverage(PercentRMAType, "%R", PercentRMALength1);
plot PercentRMovAvg5 = PercentRMA5;
PercentRMovAvg5.SetDefaultColor(Color.GREEN);
PercentRMovAvg5.SetLineWeight(3);
PercentRMovAvg5.hide();

def PercentRMA8 = MovingAverage(PercentRMAType, "%R", PercentRMALength2);
plot PercentRMovAvg8 = PercentRMA8;
PercentRMovAvg8.SetDefaultColor(Color.RED);
PercentRMovAvg8.SetLineWeight(3);
PercentRMovAvg8.hide();

input applySelectSmoothing = yes;

def smooth_it = EhlersSuperSmootherFilter(if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor, lowBand);
def smooth_MA5 = EhlersSuperSmootherFilter(MovingAverage(PercentRMAType, "%R", PercentRMALength1));
def smooth_MA8 = EhlersSuperSmootherFilter(MovingAverage(PercentRMAType, "%R", PercentRMALength2));


input SelectSmoothingType = {default "PercentR Only", "MAs Only", "PercentR & MAs", "No Smoothing"};

plot X;
X.AssignValueColor(if "%R" > over_Bought then "%R".Color("OverBought") else if "%R" < over_Sold then "%R".Color("OverSold") else "%R".Color("Normal"));
X.SetLineWeight(3);
plot Y;
Y.SetDefaultColor(Color.GREEN);
Y.SetLineWeight(2);
plot Z;
Z.SetDefaultColor(Color.RED);
Z.SetLineWeight(2);

switch (SelectSmoothingType) {
case "PercentR Only":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
case "MAs Only":
    X = if applySelectSmoothing and "%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "PercentR & MAs":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "No Smoothing":
    X = if applySelectSmoothing and"%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
}

plot OverBought = over_Bought;
OverBought.SetDefaultColor(Color.DARK_RED);
OverBought.HideTitle();

plot OverSold = over_Sold;
OverSold.SetDefaultColor(Color.DARK_GREEN);
OverSold.HideTitle();

plot fifty_line = 50;
fifty_line.SetDefaultColor(GetColor(8));
fifty_line.HideTitle();
fifty_line.SetStyle(Curve.SHORT_DASH);


# plot the Breakout Signals
input showBreakoutSignals = no;

plot UpSignal = if "%R" crosses above OverSold then OverSold else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(3);
UpSignal.HideTitle();

plot DownSignal = if "%R" crosses below OverBought then OverBought else Double.NaN;
DownSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(3);
DownSignal.HideTitle();


AddCloud(0, over_Sold, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(over_Bought, 100, Color.DARK_RED, Color.DARK_RED);


# Gmode

def lengthRSI = 14;
def price = close;

def averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], lengthRSI);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
RSI.SetDefaultColor(CreateColor(0, 102, 204));
RSI.SetLineWeight(3);
#RSI.HideTitle();
RSI.HideBubble();
RSI.Hide();

def n1 = 9; #Channel Length
def n2 = 26; #Average Length
def n3 = 13; #Short length
def multi = no; #Multi-exchange?

def src0 = hlc3;

def src1 = hlc3(period = AggregationPeriod.MONTH);
def src2 = hlc3(period = AggregationPeriod.MONTH);
def src3 = hlc3(period = AggregationPeriod.MONTH);
def src4 = hlc3(period = AggregationPeriod.MONTH);

script tci {

    input src = hlc3;
    input n1 = 9; #Channel Length
    input n2 = 26; #Average Length
    plot tci = MovAvgExponential((src - MovAvgExponential(src, n1)) / (0.025 * MovAvgExponential(AbsValue(src - MovAvgExponential(src, n1)), n1)), n2) + 50;
    tci.Hide();
}

#mf(src) => rsi(sum(volume * (change(src) <= 0 ? 0 : src), n3), sum(volume * (change(src) >= 0 ? 0 : src), n3))

script mf {

    input src = hlc3;
    input n3 = 13; #Short length


    def rsi = reference RSI();


    #plot mf = rsi(Sum(volume * (if Average(src) <= 0 then 0 else src), n3), Sum(volume * (if Average(src) >= 0 then 0 else src), n3));
    plot mf = RSI(n3, src);
    mf.Hide();
}

script willy {

    input src = hlc3;
    input n2 = 26; #Average Length
    plot willy = 60 * (src - Highest(src, n2)) / (Highest(src, n2) - Lowest(src, n2)) + 80;
    willy.Hide();

}

#csi(src) => avg(rsi(src, n3),tsi(src0,n1,n2)*50+50)

script csi {

    input src = hlc3;
    input n1 = 9; #Channel Length
    input n2 = 26; #Average Length
    input n3 = 13; #Short length

    def rsi = reference RSI();

    plot csi = RSI(n3, src) + TrueStrengthIndex(n1, n2) / 2 * 50 + 50;
    csi.Hide();

}

script godmode {

    input src = hlc3;
    def rsi = reference RSI();
    plot godmode = (tci(src) + CSI(src) + mf(src) + willy(src)) / 4;
    godmode.Hide();

}

script tradition {

    input src = hlc3;
    input n3 = 13; #Short length

    def rsi = reference RSI();

    plot tradition = (tci(src) + mf(src) + RSI(n3, src)) / 3;
    tradition.Hide();

}


def wt1 = if multi then (godmode(src0) + godmode(src1) + godmode(src2) + godmode(src3) + godmode(src4) / 5) else tradition(src0);

def wt2 = SimpleMovingAvg(wt1, 6);

def extended = if wt2 < 20 then wt2 + 5 else if wt2 > 80 then wt2 - 5 else Double.NaN;

plot wta = wt1;
wta.SetDefaultColor(Color.GREEN);
wta.SetLineWeight(2);
wta.Hide();

plot wtb = wt2;
wtb.SetDefaultColor(Color.RED);
wtb.SetLineWeight(2);
wtb.Hide();

plot ext = extended; #Caution!
ext.SetPaintingStrategy(PaintingStrategy.POINTS);
ext.SetDefaultColor(Color.YELLOW);
ext.SetLineWeight(3);

Let me know what you think...Hope this helps :)
 
@netarchitech this actually does helps a lot especially when running tight charts next to one another...I never change the other stuff that you took out...,however, if I wanted to change like the OB/OS I can just go into the code and change from there right? It appears so. Thanks again for coming up with a solution for this.
 
Yes...exactly...you are well on your way to scripting :)


You are always welcome, @HighBredCloud ...I'm just glad it helped...
@netarchitech My scripting only goes as deep as changing the colors...LOL...I just uploaded both the PercentR_MAC and the MACD_FREMA shorter versions...I am sure they will do much better...

I am just curious...but on the PercentR_MAC...is it a possibility to incorporate breakout signals each time the MA's cross? IF not no biggie...figured I'd ask...it gets kinda cramped at times when they all merge...The MA's crossover seems to be very accurate as far as the trend goes too...

I just don't know if that would be breakout signal overload or not...BUT if you can perhaps you can incorporate under the drop down menu kind of like you did with Stochastic Moment Index with DSS...where you can chose the breakout on both SMI and AVG...
 
My scripting only goes as deep as changing the colors...LOL...
I don't think so @HighBredCloud I sense there is a vast reservoir of talent and ability at your fingertips if you chose to focus in that direction...I understand that you are focused on testing and analysis, whereas I have to say I am at a complete loss in that area...so maybe we're both just choosing to focus on our strengths... :cool:

I am just curious...but on the PercentR_MAC...is it a possibility to incorporate breakout signals each time the MA's cross?
I have to admit breakout signals aren't my specialty, but I'll put it on the list and see what I can do...

BUT if you can perhaps you can incorporate under the drop down menu kind of like you did with Stochastic Moment Index with DSS...where you can chose the breakout on both SMI and AVG...
Thanks for another great idea! I'll take a look...Thanks @HighBredCloud :)
 
@HighBredCloud Below please find the initial update (test) for the multiple MA selection menu:

Code:
# filename: MR__EZ_PercentR_MAC_ ***TEST***
# idea source: @HighBredCloud and https://usethinkscript.com/threads/moving-average-crossover-rsi-indicator-for-thinkorswim.185/

# Code: Thanson Stevens, @korygill and netarchitech

# V11.11.2019 - netarchitech added multiple-choice smoothing per HighBredCloud request
# V11.12.2019 - netarchitech modified several variables per HighBredCloud request
# V11.12.2019 - netarchitech modified several inputs per HighBredCloud request


declare lower;

# PercentR_MAC

input length = 14;
def over_Bought = 80;
def over_Sold = 20;

def lowBand = 10; #Smoothing LowerBand
def data = close;
def lower = low; #Research Lower = Low?

def highest = Highest(high, length);
def divisor = highest - Lowest(low, length);
def PI = 3.14159265359;
def a1 = Exp(-PI * Sqrt(2) / lower);
def coeff2 = 2 * a1 * Cos(Sqrt(2) * PI / lower);
def coeff3 = - Power(a1, 2);
def coeff1 = 1 - coeff2 - coeff3;
def filt = coeff1 * (data + (data[1])) / 2 + coeff2 * (filt[1]) + coeff3 * (filt[2]);

input PercentRMALength1 = 3;
input PercentRMALength2 = 5;
input PercentRMAType = AverageType.SIMPLE;

# plot and smooth PercentR
plot "%R" = if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor;
"%R".DefineColor("OverBought", GetColor(9)); #GetColor(9));
"%R".DefineColor("Normal", GetColor(7));
"%R".DefineColor("OverSold", GetColor(1)); #GetColor(1));
"%R".AssignValueColor(if "%R" > over_Bought then "%R".Color("OverBought") else if "%R" < over_Sold then "%R".Color("OverSold") else "%R".Color("Normal"));
"%R".SetLineWeight(3);
"%R".Hide();

# plot and smooth the PercentR Moving Averages
def PercentRMA5 = MovingAverage(PercentRMAType, "%R", PercentRMALength1);
plot PercentRMovAvg5 = PercentRMA5;
PercentRMovAvg5.SetDefaultColor(Color.GREEN);
PercentRMovAvg5.SetLineWeight(3);
PercentRMovAvg5.hide();

def PercentRMA8 = MovingAverage(PercentRMAType, "%R", PercentRMALength2);
plot PercentRMovAvg8 = PercentRMA8;
PercentRMovAvg8.SetDefaultColor(Color.RED);
PercentRMovAvg8.SetLineWeight(3);
PercentRMovAvg8.hide();

input applySelectSmoothing = yes;

def smooth_it = EhlersSuperSmootherFilter(if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor, lowBand);
def smooth_MA5 = EhlersSuperSmootherFilter(MovingAverage(PercentRMAType, "%R", PercentRMALength1));
def smooth_MA8 = EhlersSuperSmootherFilter(MovingAverage(PercentRMAType, "%R", PercentRMALength2));


input SelectSmoothingType = {default "PercentR Only", "MAs Only", "PercentR & MAs", "No Smoothing"};

plot X;
X.AssignValueColor(if "%R" > over_Bought then "%R".Color("OverBought") else if "%R" < over_Sold then "%R".Color("OverSold") else "%R".Color("Normal"));
X.SetLineWeight(3);
plot Y;
Y.SetDefaultColor(Color.GREEN);
Y.SetLineWeight(2);
plot Z;
Z.SetDefaultColor(Color.RED);
Z.SetLineWeight(2);

switch (SelectSmoothingType) {
case "PercentR Only":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
case "MAs Only":
    X = if applySelectSmoothing and "%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "PercentR & MAs":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "No Smoothing":
    X = if applySelectSmoothing and"%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
}

plot OverBought = over_Bought;
OverBought.SetDefaultColor(Color.DARK_RED);
OverBought.HideTitle();

plot OverSold = over_Sold;
OverSold.SetDefaultColor(Color.DARK_GREEN);
OverSold.HideTitle();

plot fifty_line = 50;
fifty_line.SetDefaultColor(GetColor(8));
fifty_line.HideTitle();
fifty_line.SetStyle(Curve.SHORT_DASH);


# plot the Breakout Signals
input showBreakoutSignals = {default "On PRMA1", "On PRMA2", "On PRMA1 & PRMA2", "No"};

def PRMA1 = PercentRMA5;
def PRMA2 = PercentRMA8;

def upPRMA1 = PRMA1 crosses above PRMA2;
def upPRMA2 = PRMA2 crosses above PRMA1;
def downPRMA1 = PRMA1 crosses below PRMA2;
def downPRMA2 = PRMA2 crosses above PRMA1;

plot UpSignal;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(3);

plot DownSignal;
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(3);

switch (showBreakoutSignals) {

case "No":
    UpSignal = Double.NaN;
    DownSignal = Double.NaN;

case "On PRMA1":
    UpSignal = if upPRMA1 then PRMA2 else Double.NaN;
    DownSignal = if downPRMA1 then PRMA1 else Double.NaN;

case "On PRMA2":
    UpSignal = if upPRMA2 then PRMA2 else Double.NaN;
    DownSignal = if downPRMA2 then PRMA1 else Double.NaN;

case "On PRMA1 & PRMA2":
    UpSignal = if upPRMA1 or upPRMA2 then PRMA2 else Double.NaN;
    DownSignal = if downPRMA1 or downPRMA2 then PRMA1 else Double.NaN;
}

UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");


AddCloud(0, over_Sold, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(over_Bought, 100, Color.DARK_RED, Color.DARK_RED);


# Gmode

def lengthRSI = 14;
def price = close;

def averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], lengthRSI);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
RSI.SetDefaultColor(CreateColor(0, 102, 204));
RSI.SetLineWeight(3);
#RSI.HideTitle();
RSI.HideBubble();
RSI.Hide();

def n1 = 9; #Channel Length
def n2 = 26; #Average Length
def n3 = 13; #Short length
def multi = no; #Multi-exchange?

def src0 = hlc3;

def src1 = hlc3(period = AggregationPeriod.MONTH);
def src2 = hlc3(period = AggregationPeriod.MONTH);
def src3 = hlc3(period = AggregationPeriod.MONTH);
def src4 = hlc3(period = AggregationPeriod.MONTH);

script tci {

    input src = hlc3;
    input n1 = 9; #Channel Length
    input n2 = 26; #Average Length
    plot tci = MovAvgExponential((src - MovAvgExponential(src, n1)) / (0.025 * MovAvgExponential(AbsValue(src - MovAvgExponential(src, n1)), n1)), n2) + 50;
    tci.Hide();
}

#mf(src) => rsi(sum(volume * (change(src) <= 0 ? 0 : src), n3), sum(volume * (change(src) >= 0 ? 0 : src), n3))

script mf {

    input src = hlc3;
    input n3 = 13; #Short length


    def rsi = reference RSI();


    #plot mf = rsi(Sum(volume * (if Average(src) <= 0 then 0 else src), n3), Sum(volume * (if Average(src) >= 0 then 0 else src), n3));
    plot mf = RSI(n3, src);
    mf.Hide();
}

script willy {

    input src = hlc3;
    input n2 = 26; #Average Length
    plot willy = 60 * (src - Highest(src, n2)) / (Highest(src, n2) - Lowest(src, n2)) + 80;
    willy.Hide();

}

#csi(src) => avg(rsi(src, n3),tsi(src0,n1,n2)*50+50)

script csi {

    input src = hlc3;
    input n1 = 9; #Channel Length
    input n2 = 26; #Average Length
    input n3 = 13; #Short length

    def rsi = reference RSI();

    plot csi = RSI(n3, src) + TrueStrengthIndex(n1, n2) / 2 * 50 + 50;
    csi.Hide();

}

script godmode {

    input src = hlc3;
    def rsi = reference RSI();
    plot godmode = (tci(src) + CSI(src) + mf(src) + willy(src)) / 4;
    godmode.Hide();

}

script tradition {

    input src = hlc3;
    input n3 = 13; #Short length

    def rsi = reference RSI();

    plot tradition = (tci(src) + mf(src) + RSI(n3, src)) / 3;
    tradition.Hide();

}


def wt1 = if multi then (godmode(src0) + godmode(src1) + godmode(src2) + godmode(src3) + godmode(src4) / 5) else tradition(src0);

def wt2 = SimpleMovingAvg(wt1, 6);

def extended = if wt2 < 20 then wt2 + 5 else if wt2 > 80 then wt2 - 5 else Double.NaN;

plot wta = wt1;
wta.SetDefaultColor(Color.GREEN);
wta.SetLineWeight(2);
wta.Hide();

plot wtb = wt2;
wtb.SetDefaultColor(Color.RED);
wtb.SetLineWeight(2);
wtb.Hide();

plot ext = extended; #Caution!
ext.SetPaintingStrategy(PaintingStrategy.POINTS);
ext.SetDefaultColor(Color.YELLOW);
ext.SetLineWeight(3);

This is a rough initial draft (test)...Plug it in and hide the regular PercentR_MAC...Thanks :)
 
@netarchitech Checked out the new code...It does the job it was intended to so its up to the user to choose what type of a breakout signal they want without having a breakout signal overload. I don't see the PercentR breakout signals anymore in this version?

Personally from what I have observed thus far in my testing of the PercentR_MAC...the best crossovers are when PercentR is in OB/OS territory as in the version you updated yesterday I think?...NEXT when PercentR crosses over the Green Line (percent rma length 1) and when the Green Line crosses over the Red Line...
 
@HighBredCloud OK...It looks like I'm going to have to merge the PercentR breakout signals with the MA breakout signals...if possible...I'll let you know...

...the best crossovers are when PercentR is in OB/OS territory as in the version you updated yesterday I think
We can always revert to that version...that's why i created the "test" version...I'll keep working on the test version to see if I can get everything straightened away...
 
@HighBredCloud OK...It looks like I'm going to have to merge the PercentR breakout signals with the MA breakout signals...if possible...I'll let you know...


We can always revert to that version...that's why i created the "test" version...I'll keep working on the test version to see if I can get everything straightened away...
@netarchitech honestly its no big deal...I know you have your hands full with the new project. We can put that on the back burner...What you did with the previous version allows me to check the actual values when the cross overs happen...so I can live with that now that I can actually see what is going on especially when I am running a tight chart...
 
@HighBredCloud Below please find the updated code (test) for the multiple MA selection menu as well as the standard breakout signals:

Code:
# filename: MR__EZ_PercentR_MAC_ ***TEST***
# idea source: @HighBredCloud and https://usethinkscript.com/threads/moving-average-crossover-rsi-indicator-for-thinkorswim.185/

# Code: Thanson Stevens, @korygill and netarchitech

# V11.11.2019 - netarchitech added multiple-choice smoothing per HighBredCloud request
# V11.12.2019 - netarchitech modified several variables per HighBredCloud request
# V11.12.2019 - netarchitech modified several inputs per HighBredCloud request
# V11.13.2019 - netarchitech added additional multiple-choice breakout signals


declare lower;

# PercentR_MAC

input length = 14;
def over_Bought = 80;
def over_Sold = 20;

def lowBand = 10; #Smoothing LowerBand
def data = close;
def lower = low; #Research Lower = Low?

def highest = Highest(high, length);
def divisor = highest - Lowest(low, length);
def PI = 3.14159265359;
def a1 = Exp(-PI * Sqrt(2) / lower);
def coeff2 = 2 * a1 * Cos(Sqrt(2) * PI / lower);
def coeff3 = - Power(a1, 2);
def coeff1 = 1 - coeff2 - coeff3;
def filt = coeff1 * (data + (data[1])) / 2 + coeff2 * (filt[1]) + coeff3 * (filt[2]);

input PercentRMALength1 = 3;
input PercentRMALength2 = 5;
input PercentRMAType = AverageType.SIMPLE;

# plot and smooth PercentR
plot "%R" = if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor;
"%R".DefineColor("OverBought", GetColor(9)); #GetColor(9));
"%R".DefineColor("Normal", GetColor(7));
"%R".DefineColor("OverSold", GetColor(1)); #GetColor(1));
"%R".AssignValueColor(if "%R" > over_Bought then "%R".Color("OverBought") else if "%R" < over_Sold then "%R".Color("OverSold") else "%R".Color("Normal"));
"%R".SetLineWeight(3);
"%R".Hide();

# plot and smooth the PercentR Moving Averages
def PercentRMA5 = MovingAverage(PercentRMAType, "%R", PercentRMALength1);
plot PercentRMovAvg5 = PercentRMA5;
PercentRMovAvg5.SetDefaultColor(Color.GREEN);
PercentRMovAvg5.SetLineWeight(3);
PercentRMovAvg5.hide();

def PercentRMA8 = MovingAverage(PercentRMAType, "%R", PercentRMALength2);
plot PercentRMovAvg8 = PercentRMA8;
PercentRMovAvg8.SetDefaultColor(Color.RED);
PercentRMovAvg8.SetLineWeight(3);
PercentRMovAvg8.hide();

input applySelectSmoothing = no;

def smooth_it = EhlersSuperSmootherFilter(if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor, lowBand);
def smooth_MA5 = EhlersSuperSmootherFilter(MovingAverage(PercentRMAType, "%R", PercentRMALength1));
def smooth_MA8 = EhlersSuperSmootherFilter(MovingAverage(PercentRMAType, "%R", PercentRMALength2));


input SelectSmoothingType = {default "PercentR Only", "MAs Only", "PercentR & MAs", "No Smoothing"};

plot X;
X.AssignValueColor(if "%R" > over_Bought then "%R".Color("OverBought") else if "%R" < over_Sold then "%R".Color("OverSold") else "%R".Color("Normal"));
X.SetLineWeight(3);
plot Y;
Y.SetDefaultColor(Color.GREEN);
Y.SetLineWeight(2);
plot Z;
Z.SetDefaultColor(Color.RED);
Z.SetLineWeight(2);

switch (SelectSmoothingType) {
case "PercentR Only":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
case "MAs Only":
    X = if applySelectSmoothing and "%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "PercentR & MAs":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "No Smoothing":
    X = if applySelectSmoothing and"%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
}

plot OverBought = over_Bought;
OverBought.SetDefaultColor(Color.DARK_RED);
OverBought.HideTitle();

plot OverSold = over_Sold;
OverSold.SetDefaultColor(Color.DARK_GREEN);
OverSold.HideTitle();

plot fifty_line = 50;
fifty_line.SetDefaultColor(GetColor(8));
fifty_line.HideTitle();
fifty_line.SetStyle(Curve.SHORT_DASH);


# plot the Breakout Signals

input showBreakoutSignals = no;

plot UpSignal = if "%R" crosses above OverSold then OverSold else Double.NaN;
UpSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(3);
UpSignal.HideTitle();

plot DownSignal = if "%R" crosses below OverBought then OverBought else Double.NaN;
DownSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(3);
DownSignal.HideTitle();

input showBreakoutSignalsMA = {"On PRMA1", "On PRMA2", "On PRMA1 & PRMA2", default "No"};

def PRMA1 = PercentRMA5;
def PRMA2 = PercentRMA8;

def upPRMA1 = PRMA1 crosses above PRMA2;
def upPRMA2 = PRMA2 crosses above PRMA1;
def downPRMA1 = PRMA1 crosses below PRMA2;
def downPRMA2 = PRMA2 crosses above PRMA1;

plot UpSignalMA;
UpSignalMA.SetDefaultColor(Color.GREEN);
UpSignalMA.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignalMA.SetLineWeight(3);

plot DownSignalMA;
DownSignalMA.SetDefaultColor(Color.RED);
DownSignalMA.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignalMA.SetLineWeight(3);

switch (showBreakoutSignalsMA) {

case "No":
    UpSignalMA = Double.NaN;
    DownSignalMA = Double.NaN;

case "On PRMA1":
    UpSignalMA = if upPRMA1 then PRMA2 else Double.NaN;
    DownSignalMA = if downPRMA1 then PRMA1 else Double.NaN;

case "On PRMA2":
    UpSignalMA = if upPRMA2 then PRMA2 else Double.NaN;
    DownSignalMA = if downPRMA2 then PRMA1 else Double.NaN;

case "On PRMA1 & PRMA2":
    UpSignalMA = if upPRMA1 or upPRMA2 then PRMA2 else Double.NaN;
    DownSignalMA = if downPRMA1 or downPRMA2 then PRMA1 else Double.NaN;
}

UpSignalMA.setHiding(showBreakoutSignalsMA == showBreakoutSignalsMA."No");
DownSignalMA.setHiding(showBreakoutSignalsMA == showBreakoutSignalsMA."No");


AddCloud(0, over_Sold, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(over_Bought, 100, Color.DARK_RED, Color.DARK_RED);


# Gmode

def lengthRSI = 14;
def price = close;

def averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], lengthRSI);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
RSI.SetDefaultColor(CreateColor(0, 102, 204));
RSI.SetLineWeight(3);
#RSI.HideTitle();
RSI.HideBubble();
RSI.Hide();

def n1 = 9; #Channel Length
def n2 = 26; #Average Length
def n3 = 13; #Short length
def multi = no; #Multi-exchange?

def src0 = hlc3;

def src1 = hlc3(period = AggregationPeriod.MONTH);
def src2 = hlc3(period = AggregationPeriod.MONTH);
def src3 = hlc3(period = AggregationPeriod.MONTH);
def src4 = hlc3(period = AggregationPeriod.MONTH);

script tci {

    input src = hlc3;
    input n1 = 9; #Channel Length
    input n2 = 26; #Average Length
    plot tci = MovAvgExponential((src - MovAvgExponential(src, n1)) / (0.025 * MovAvgExponential(AbsValue(src - MovAvgExponential(src, n1)), n1)), n2) + 50;
    tci.Hide();
}

#mf(src) => rsi(sum(volume * (change(src) <= 0 ? 0 : src), n3), sum(volume * (change(src) >= 0 ? 0 : src), n3))

script mf {

    input src = hlc3;
    input n3 = 13; #Short length


    def rsi = reference RSI();


    #plot mf = rsi(Sum(volume * (if Average(src) <= 0 then 0 else src), n3), Sum(volume * (if Average(src) >= 0 then 0 else src), n3));
    plot mf = RSI(n3, src);
    mf.Hide();
}

script willy {

    input src = hlc3;
    input n2 = 26; #Average Length
    plot willy = 60 * (src - Highest(src, n2)) / (Highest(src, n2) - Lowest(src, n2)) + 80;
    willy.Hide();

}

#csi(src) => avg(rsi(src, n3),tsi(src0,n1,n2)*50+50)

script csi {

    input src = hlc3;
    input n1 = 9; #Channel Length
    input n2 = 26; #Average Length
    input n3 = 13; #Short length

    def rsi = reference RSI();

    plot csi = RSI(n3, src) + TrueStrengthIndex(n1, n2) / 2 * 50 + 50;
    csi.Hide();

}

script godmode {

    input src = hlc3;
    def rsi = reference RSI();
    plot godmode = (tci(src) + CSI(src) + mf(src) + willy(src)) / 4;
    godmode.Hide();

}

script tradition {

    input src = hlc3;
    input n3 = 13; #Short length

    def rsi = reference RSI();

    plot tradition = (tci(src) + mf(src) + RSI(n3, src)) / 3;
    tradition.Hide();

}


def wt1 = if multi then (godmode(src0) + godmode(src1) + godmode(src2) + godmode(src3) + godmode(src4) / 5) else tradition(src0);

def wt2 = SimpleMovingAvg(wt1, 6);

def extended = if wt2 < 20 then wt2 + 5 else if wt2 > 80 then wt2 - 5 else Double.NaN;

plot wta = wt1;
wta.SetDefaultColor(Color.GREEN);
wta.SetLineWeight(2);
wta.Hide();

plot wtb = wt2;
wtb.SetDefaultColor(Color.RED);
wtb.SetLineWeight(2);
wtb.Hide();

plot ext = extended; #Caution!
ext.SetPaintingStrategy(PaintingStrategy.POINTS);
ext.SetDefaultColor(Color.YELLOW);
ext.SetLineWeight(3);

Let me know how it goes when you have a chance...Thanks :)
 
@Rsully2222 Per your request I have converted this study to scan for an upSignal. Just place the following code directly in the scanner. Scanning this against the S&P 500 on a daily aggregation I obtained 23 results. If you'd like to scan for a downSignal, just replace the last line of this code with

plot scan = downSignal;

Code:
# PercentR MAC Scan
# tomsk
# 1.6.2020

# tomsk: I have converted the following code to scan for an upSignal (see header information below)
#
# If you'd like to scan for a downSignal, just replace the last line of this code with
#
# plot scan = downSignal;

# filename: MR__EZ_PercentR_MAC_ ***TEST***
# idea source: @HighBredCloud and https://usethinkscript.com/threads/moving-average-crossover-rsi-indicator-for-thinkorswim.185/

# Code: Thanson Stevens, @korygill and netarchitech

# V11.11.2019 - netarchitech added multiple-choice smoothing per HighBredCloud request
# V11.12.2019 - netarchitech modified several variables per HighBredCloud request
# V11.12.2019 - netarchitech modified several inputs per HighBredCloud request
# V11.13.2019 - netarchitech added additional multiple-choice breakout signals

# PercentR_MAC

input length = 14;
def over_Bought = 80;
def over_Sold = 20;

def lowBand = 10; #Smoothing LowerBand
def data = close;
def lower = low; #Research Lower = Low?

def highest = Highest(high, length);
def divisor = highest - Lowest(low, length);
def PI = 3.14159265359;
def a1 = Exp(-PI * Sqrt(2) / lower);
def coeff2 = 2 * a1 * Cos(Sqrt(2) * PI / lower);
def coeff3 = - Power(a1, 2);
def coeff1 = 1 - coeff2 - coeff3;
def filt = coeff1 * (data + (data[1])) / 2 + coeff2 * (filt[1]) + coeff3 * (filt[2]);

input PercentRMALength1 = 3;
input PercentRMALength2 = 5;
input PercentRMAType = AverageType.SIMPLE;

# plot and smooth PercentR
def "%R" = if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor;

# plot and smooth the PercentR Moving Averages
def PercentRMA5 = MovingAverage(PercentRMAType, "%R", PercentRMALength1);
def PercentRMovAvg5 = PercentRMA5;

def PercentRMA8 = MovingAverage(PercentRMAType, "%R", PercentRMALength2);
def PercentRMovAvg8 = PercentRMA8;

input applySelectSmoothing = no;

def smooth_it = EhlersSuperSmootherFilter(if divisor equals 0 then 0 else 100 - 100 * (highest - close) / divisor, lowBand);
def smooth_MA5 = EhlersSuperSmootherFilter(MovingAverage(PercentRMAType, "%R", PercentRMALength1));
def smooth_MA8 = EhlersSuperSmootherFilter(MovingAverage(PercentRMAType, "%R", PercentRMALength2));

input SelectSmoothingType = {default "PercentR Only", "MAs Only", "PercentR & MAs", "No Smoothing"};

def X;
def Y;
def Z;

switch (SelectSmoothingType) {
case "PercentR Only":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
case "MAs Only":
    X = if applySelectSmoothing and "%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "PercentR & MAs":
    X = if applySelectSmoothing and "%R" then smooth_it else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then smooth_MA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then smooth_MA8 else PercentRMA8;
case "No Smoothing":
    X = if applySelectSmoothing and"%R" then "%R" else "%R";
    Y = if applySelectSmoothing and PercentRMA5 then PercentRMA5 else PercentRMA5;
    Z = if applySelectSmoothing and PercentRMA8 then PercentRMA8 else PercentRMA8;
}

# Breakout Signals

def UpSignal = "%R" crosses above Over_Sold;
def DownSignal = "%R" crosses below Over_Bought;

plot scan = upSignal;
# End PercentR MAC Scan
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
451 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top