#study(title="Blast Off Momentum [DW]", shorttitle="BOM [DW]", overlay=false)
#//by Donovan Wall
#//This study is an alternative experimental interpretation of the Blast Off Indicator by Larry Williams.
#//This formula takes positive and negative magnitudes rather than the absolute value. The result is then smoothed with an ema, and twice smoothed to provide a signal line.
# Converted by Sam4Cok@Samer800 - 05/2023
declare lower;
input ColorBars = yes;
input ShowTriggerCandle = no;
input Period = 34; # "Period"
input SignalPeriod = 9; # "Signal Period"
input Threshold = 10; # "Threshold Distance"
def na = Double.NaN;
def last = isNaN(close);
#//Definitions
#//Blast Off Momentum
def ocrng = close - open;
def hlrng = high - low;
def bo = ocrng/hlrng*100;
def BOM = ExpAverage(bo, Period);
def SIG = ExpAverage(BOM, SignalPeriod);
#//Thresholds
def uth = Threshold;
def lth = -Threshold;
#//Color
def col = if (bom > 0) and (bom < uth) then 1 else
if (bom < 0) and (bom > lth) then -1 else
if (bom > uth) then 2 else if (bom < lth) then -2 else 0;
#//Plots
#//Signal Line
plot sigLine = sig; # "Signal Line"
sigLine.SetDefaultColor(Color.YELLOW);
#//BOM
plot bomplot = bom; # "BOM"
bomplot.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
bomplot.AssignValueColor(if col==2 then Color.GREEN else
if col==1 then Color.DARK_GREEN else
if col==-1 then Color.DARK_RED else
if col==-2 then Color.RED else Color.GRAY);
#//Thresholds
plot uthplot = if last then na else uth; # "Upper Threshold"
plot centplot = if last then na else 0; # "Center Line"
plot lthplot = if last then na else lth; # "Lower Threshold"
uthplot.SetDefaultColor(Color.GREEN);
centplot.SetDefaultColor(Color.DARK_GRAY);
lthplot.SetDefaultColor(Color.RED);
uthplot.SetStyle(Curve.SHORT_DASH);
lthplot.SetStyle(Curve.SHORT_DASH);
#-- Trigger Candle
def up = ShowTriggerCandle and col==2 and col[1]!=2;
def dn = ShowTriggerCandle and col==-2 and col[1]!=-2;
AssignPriceColor(if up then Color.CYAN else
if dn then Color.MAGENTA else Color.CURRENT);
#//Bar Color
AssignPriceColor(if !ColorBars then Color.CURRENT else
if up then Color.CYAN else
if col==2 then Color.GREEN else
if col==1 then Color.DARK_GREEN else
if col==-1 then Color.DARK_RED else
if dn then Color.MAGENTA else
if col==-2 then Color.RED else Color.GRAY);
#-- END of CODE