#### mbarcala

##### Active member

## This first post contains the most updated code

BPM is base in my way of trading every day, I never fight again the price movement with specific exceptions that I learned over time. I do combine this BPM with a Double Bollinger Band

I thanks this site for the contribution that it has giving me to put all these ideas together, help from members like SleepyZ, MarryDay, BenTen, barbaros, they help me to visualize, improve and optimize my daily work, thanks big time!

Any improvement idea is more than welcome!

Code:

```
# Break Price Momentum "BPM" by mbarcala and usethinkscript.com on 12/21/21(18)
declare lower;
input length = 20;
input lowlength = 5;
input lookForward = yes;
input reverType = {default "Momentum", "MultiMomentum", "temaMomentum"};
def exitLevelBeg = 1.5;
def calDays = 0.5;
def mLev = 1.1;
def nDev = 2.0;
def AvgExp = ExpAverage(close, length);
def UpSignal = close crosses above AvgExp;
def DnSignal = close crosses below AvgExp;
def SignUpDn = UpSignal or DnSignal;
def slength = 17;
def lowest_k = Lowest(low, slength);
def c1 = close - lowest_k;
def c2 = Highest(high, slength) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovAvgExponential(FastK, lowlength);
def FullD = Max(-100, Min(100, (MovAvgExponential(FullK, 1))) - 50) / 50;
def flen = 0.5 * (Log((1 + FullD) / (1 - FullD)) + flen[1]);
plot BPM = flen;
BPM.SetDefaultColor(CreateColor(0, 101, 255));
BPM.SetLineWeight(2);
BPM.HideBubble();
BPM.HideTitle();
plot cLine = 0;
cLine.SetPaintingStrategy(PaintingStrategy.LINE);
cLine.SetDefaultColor(Color.GRAY);
cLine.SetLineWeight(1);
cLine.HideTitle();
cLine.HideTitle();
plot oBl = mLev;
oBl.SetPaintingStrategy(PaintingStrategy.LINE);
oBl.SetDefaultColor(CreateColor(22, 42, 115));
oBl.SetLineWeight(1);
oBl.HideTitle();
plot oSl = -mLev;
oSl.SetPaintingStrategy(PaintingStrategy.LINE);
oSl.SetDefaultColor(CreateColor(22, 42, 115));
oSl.SetLineWeight(1);
oSl.HideTitle();
plot centlev = 0.2;
centlev.SetDefaultColor(Color.BLACK);
centlev.HideBubble();
centlev.HideTitle();
plot centLev2 = -centlev;
centLev2.SetDefaultColor(Color.BLACK);
centLev2.HideBubble();
centLev2.HideTitle();
AddCloud(BPM, centlev, CreateColor(15, 50, 108), CreateColor(27, 27, 27));#GREEN
AddCloud(BPM, -centlev, CreateColor(27, 27, 27), CreateColor(99, 17, 73));#RED
def extValue = if BPM >= exitLevelBeg then RoundDown((BPM - exitLevelBeg) / calDays, 0) + 1 else if BPM <= -exitLevelBeg then RoundDown((-exitLevelBeg - BPM) / calDays, 0) + 1 else 0;
#def ema1 = ExpAverage(close, length);
def ema2 = ExpAverage(AvgExp, length);
def ema3 = ExpAverage(ema2, length);
def TEMA = 3 * AvgExp - 3 * ema2 + ema3;
plot upArrow;
plot dnArrow;
plot trendUp;
plot trendDn;
plot exts;
plot upBuy;
plot dnSell;
plot temaUp;
plot temaDn;
switch (reverType) {
case "Momentum":
upArrow = if BPM crosses above cLine then BPM else Double.NaN;
dnArrow = if BPM crosses below cLine then BPM else Double.NaN;
trendUp = if BPM > centlev and BPM crosses above BPM[1] then BPM + -0.1 else Double.NaN;
trendDn = if BPM < -centlev and BPM crosses below BPM[1] then BPM + 0.1 else Double.NaN;
exts = if extValue > 0 and extValue[1] != extValue then BPM else Double.NaN;
upBuy = Double.NaN;
dnSell = Double.NaN;
temaUp = Double.NaN;
temaDn = Double.NaN;
case "MultiMomentum":
upArrow = if BPM crosses above cLine then BPM else Double.NaN;
dnArrow = if BPM crosses below cLine then BPM else Double.NaN;
trendUp = Double.NaN;
trendDn = Double.NaN;
exts = Double.NaN;
upBuy = if flen crosses above flen[1] then flen[1] else Double.NaN;
dnSell = if flen crosses below flen[1] then flen[1] else Double.NaN;
temaUp = Double.NaN;
temaDn = Double.NaN;
case "temaMomentum":
upArrow = Double.NaN;
dnArrow = Double.NaN;
trendUp = Double.NaN;
trendDn = Double.NaN;
exts = Double.NaN;
upBuy = Double.NaN;
dnSell = Double.NaN;
temaUp = if TEMA crosses above TEMA[1] then BPM + -0.1 else Double.NaN;
temaDn = if TEMA crosses below TEMA[1] then BPM + 0.1 else Double.NaN;
}
############### BPM Crossing cLine ################
upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upArrow.SetDefaultColor(Color.GREEN);
upArrow.SetLineWeight(3);
upArrow.HideBubble();
upArrow.HideTitle();
dnArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
dnArrow.SetDefaultColor(Color.RED);
dnArrow.SetLineWeight(3);
dnArrow.HideBubble();
dnArrow.HideTitle();
############### Price Reversals ################
trendUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
trendUp.SetDefaultColor(Color.WHITE);
trendUp.SetLineWeight(1);
trendUp.HideBubble();
trendUp.HideTitle();
trendDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
trendDn.SetDefaultColor(Color.WHITE);
trendDn.SetLineWeight(1);
trendDn.HideBubble();
trendDn.HideTitle();
############## Possible Exit Levels #################
exts.SetPaintingStrategy(PaintingStrategy.POINTS);
exts.SetDefaultColor(Color.MAGENTA);
exts.SetLineWeight(3);
exts.HideBubble();
exts.HideTitle();
############## Multi Revertion Points #################
upBuy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upBuy.SetDefaultColor(Color.MAGENTA);
upBuy.SetLineWeight(1);
upBuy.HideBubble();
upBuy.HideTitle();
dnSell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
dnSell.SetDefaultColor(Color.MAGENTA);
dnSell.SetLineWeight(1);
dnSell.HideBubble();
dnSell.HideTitle();
############## TEMA Arrows #################
temaUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
temaUp.SetDefaultColor(Color.MAGENTA);
temaUp.SetLineWeight(1);
temaUp.HideBubble();
temaUp.HideTitle();
temaDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
temaDn.SetDefaultColor(Color.MAGENTA);
temaDn.SetLineWeight(1);
temaDn.HideBubble();
temaDn.HideTitle();
############## Vertical Lines #################
AddVerticalLine(if lookForward then UpSignal and !SignUpDn[-1] else UpSignal and !UpSignal[1], "Up", Color.DARK_GREEN, Curve.SHORT_DASH);
AddVerticalLine(if lookForward then DnSignal and !SignUpDn[-1] else DnSignal and !UpSignal[1], "Down", Color.DARK_RED, Curve.SHORT_DASH);
########## BB Squeeze ###########
def sDev = StDev(close, length);
def MidLine = MovAvgExponential(close, length);
def LowerBand = MidLine + -nDev * sDev;
def UpperBand = MidLine + nDev * sDev;
def shhigh = 1.0 * MovAvgExponential(TrueRange(high, close, low), length);
def shMid = 1.5 * MovAvgExponential(TrueRange(high, close, low), length);
def shlow = 2.0 * MovAvgExponential(TrueRange(high, close, low), length);
def average = MovAvgExponential(close, length);
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 IsNaN(close) then Double.NaN else if ExtSqueeze or oriSqueeze or preSqueeze then cLine else Double.NaN;
squeezeline.AssignValueColor(if ExtSqueeze then CreateColor(155, 83, 21) else if oriSqueeze then CreateColor(122, 22, 46) else if preSqueeze then Color.DARK_GRAY else Color.GREEN);
squeezeline.SetPaintingStrategy(PaintingStrategy.SQUARES);
squeezeline.SetLineWeight(4);
squeezeline.HideTitle();
AddCloud(centlev, -centlev, Color.BLACK);
```

Last edited by a moderator: