Alright, here you go. Automatically calculates the crossing of overbought/oversold levels in 0.5 increments. The increment is a variable so you can change it.don't get wrong I know you trying to help and appreciate a lot believe me! what do you think about this line here, can be possible to create this more dynamic, the signal every time increase 0.5 show another signal, right now looks to manual?
Code:plot ext1 = if mSig crosses above obL1 or mSig crosses below -obL1 then mSig else if mSig crosses above obL2 or mSig crosses below -obL2 then mSig else if mSig crosses above obL3 or mSig crosses below -obL3 then mSig else if mSig crosses above obL4 or mSig crosses below -obL4 then mSig else Double.NaN;
I also added an option to look forward or not. You can turn that on to go back to your original implementation. Added hints, etc. Variable names can be cleaned up, but it is all cosmetic at that point.
Code:
# Break Price Momentum, BPM by mbarcala and usethinkscript.com on 12/21/21(9)
# StochasticFull
# 20211229 - barbaros - rework
# 20211230 - barbaros - added autmatic calculation of obL dots
# 20211230 - barbaros - added option to look forward and hints
declare lower;
input highLowLookback = 17; #HINT highLowLookback: Look back period for highs and lows
input movAvgLength = 6; #HINT movAvgLength: Length used in exponential moving average
input lookForward = no; #HINT lookForward: Look forward to remove non confirmed signals. If turned on, might repaint.
def slength = 20;
def mLev = 1.1;
def trendL = 0.3;
def obL1 = 1.8;
def obLStep = 0.5;
def nDev = 2.0;
def AvgExp = ExpAverage(close, slength);
def UpSignal = close crosses above AvgExp;
def DnSignal = close crosses below AvgExp;
def SignUpDn = UpSignal or DnSignal;
def lowest_k = Lowest(low, highLowLookback);
def c1 = close - lowest_k;
def c2 = Highest(high, highLowLookback) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovAvgExponential(FastK, movAvgLength);
def FullD = Max(-100, Min(100, (MovAvgExponential(FullK, 1))) - 50) / 50;
def flen = 0.5 * (Log((1 + FullD) / (1 - FullD)) + flen[1]);
plot mSig = flen;
mSig.SetDefaultColor(Color.MAGENTA);
mSig.SetLineWeight(2);
mSig.HideBubble();
mSig.HideTitle();
AddCloud(mSig, 0, Color.DARK_GREEN, Color.CURRENT);
AddCloud(mSig, 0, Color.CURRENT, Color.DARK_RED);
AddCloud(mSig, mLev, Color.GREEN, CreateColor(27, 27, 27));
AddCloud(mSig, -mLev, CreateColor(27, 27, 27), Color.RED);
plot cLine = 0;
cLine.SetPaintingStrategy(PaintingStrategy.LINE);
cLine.SetDefaultColor(Color.GRAY);
cLine.SetLineWeight(2);
cLine.HideTitle();
plot oBl = mLev;
oBl.SetPaintingStrategy(PaintingStrategy.LINE);
oBl.SetDefaultColor(CreateColor(0, 155, 255));
oBl.SetLineWeight(1);
oBl.HideTitle();
plot oSl = -mLev;
oSl.SetPaintingStrategy(PaintingStrategy.LINE);
oSl.SetDefaultColor(CreateColor(0, 155, 255));
oSl.SetLineWeight(1);
oSl.HideTitle();
############### Price Crossing Level ################
plot upArrow = if mSig crosses above 0 then mSig else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upArrow.SetDefaultColor(Color.GREEN);
upArrow.SetLineWeight(3);
upArrow.HideBubble();
upArrow.HideTitle();
plot dnArrow = if mSig crosses below 0 then mSig else Double.NaN;
dnArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
dnArrow.SetDefaultColor(Color.RED);
dnArrow.SetLineWeight(3);
dnArrow.HideBubble();
dnArrow.HideTitle();
############### Signal Reversal ################
plot trendUp = if mSig crosses above mSig[1] and mSig[1] > trendL[1] then mSig else Double.NaN;
trendUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
trendUp.SetDefaultColor(Color.CYAN);
trendUp.SetLineWeight(1);
trendUp.HideBubble();
trendUp.HideTitle();
#--------------
plot trendDn = if mSig crosses below mSig[1] and mSig[1] < -trendL[1] then mSig else Double.NaN;
trendDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
trendDn.SetDefaultColor(Color.CYAN);
trendDn.SetLineWeight(1);
trendDn.HideBubble();
trendDn.HideTitle();
############## Exit Levels #################
def extValue = if msig >= obL1 then RoundDown((msig - obL1) / obLStep, 0) + 1 else if msig <= -obL1 then RoundDown((-obL1 - msig) / obLStep, 0) + 1 else 0;
plot exts = if extValue > 0 and extValue[1] != extValue then mSig else Double.NaN;
exts.SetPaintingStrategy(PaintingStrategy.POINTS);
exts.SetDefaultColor(CreateColor(255,255,0));
exts.SetLineWeight(5);
exts.HideBubble();
exts.HideTitle();
############## Vertical Lines #################
AddVerticalLine(if lookForward then UpSignal and !SignUpDn[-1] else UpSignal and !UpSignal[1], "Up", Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(if lookForward then DnSignal and !SignUpDn[-1] else DnSignal and !UpSignal[1], "Down", Color.RED, Curve.SHORT_DASH);
########## BB Squeeze ###########
def sDev = StDev(data = close, slength);
def MidLine = MovingAverage(averageType = AverageType.EXPONENTIAL, data = close, slength);
def LowerBand = MidLine + -nDev * sDev;
def UpperBand = MidLine + nDev * sDev;
def shhigh = 1.0 * MovAvgExponential(TrueRange(high, close, low), slength);
def shMid = 1.5 * MovAvgExponential(TrueRange(high, close, low), slength);
def shlow = 2.0 * MovAvgExponential(TrueRange(high, close, low), slength);
def average = MovAvgExponential(close, slength);
def UpperBandKCLow = average + shlow;
def LowerBandKCLow = average - shlow;
def UpperBandKCMid = average + shMid;
def LowerBandKCMid = average - shMid;
def UpperBandKCHigh = average + shhigh;
def LowerBandKCHigh = average - shhigh;
def preSqueeze = LowerBand > LowerBandKCLow and UpperBand < UpperBandKCLow;
def oriSqueeze = LowerBand > LowerBandKCMid and UpperBand < UpperBandKCMid;
def ExtSqueeze = LowerBand > LowerBandKCHigh and UpperBand < UpperBandKCHigh;
plot squeezeline = if ExtSqueeze or oriSqueeze or preSqueeze then 0 else Double.NaN;
squeezeline.AssignValueColor(if ExtSqueeze then Color.ORANGE else if oriSqueeze then Color.RED else if preSqueeze then Color.BLACK else Color.GREEN);
squeezeline.SetPaintingStrategy(PaintingStrategy.POINTS);
squeezeline.SetLineWeight(4);
squeezeline.HideTitle();