mbarcala
Active member
HiLoBands is a combination of two keltner channel, using one Moving Average with two different calculations at the same time with two Average True Range (ATR). The idea behind of this combination, is to find a possible exhaustion point in an Up Trend or Down Trend run before a possible reversal (small or big).
As a main idea of trading, I got price crossing the 20MA (Up or Down). I used the small moving average with Wilders calculation and Wilders ATR and on the higher moving average I used Simple calculation with Weighted ATR.
The small deviation can be used as a way to read which type of trend is happening. Ending trend can be seen when the price goes over the higher Bands (Red or Green Dots) and sometimes when the higher Band crosses the small Band, in both cases the trend can have a reversal, time to exit.
Photo:
https%3A//i.imgur.com/PlUWpzP.png[/img]']
script:
As a main idea of trading, I got price crossing the 20MA (Up or Down). I used the small moving average with Wilders calculation and Wilders ATR and on the higher moving average I used Simple calculation with Weighted ATR.
The small deviation can be used as a way to read which type of trend is happening. Ending trend can be seen when the price goes over the higher Bands (Red or Green Dots) and sometimes when the higher Band crosses the small Band, in both cases the trend can have a reversal, time to exit.
Photo:
https%3A//i.imgur.com/PlUWpzP.png[/img]']
script:
Code:
# HiLoBands by mbarcala for useThinkscript.com
######### Keltner
input length = 20;
input lDev = 1.2;
input averageType = AverageType.WILDERS;
input trueRangeAverageType = AverageType.WILDERS;
input hDev = 3.0;
input SecondaverageType = AverageType.SIMPLE;
input SecondtrueRangeAverageType = AverageType.WEIGHTED;
DefineGlobalColor("Blue", CreateColor(0,101,255));
DefineGlobalColor("dBlue", CreateColor(0,0,255));
DefineGlobalColor("Gray", CreateColor(50,50,50));
DefineGlobalColor("dGray", CreateColor(90,90,90));
DefineGlobalColor("Red", CreateColor(102,0,5));
DefineGlobalColor("Burg", CreateColor(230, 17, 125));
plot MidLine = MovingAverage(averageType, close, length);
MidLine.SetDefaultColor(Color.GRAY);
MidLine.SetLineWeight(2);
MidLine.HideBubble();
MidLine.HideTitle();
######## Lower Band ###
def lowerBand = lDev * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
plot sUpBand = MidLine + lowerBand;
sUpBand.SetStyle(Curve.MEDIUM_DASH);
sUpBand.SetDefaultColor(GlobalColor("dGray"));
sUpBand.HideBubble();
sUpBand.HideTitle();
plot sDnBand = MidLine - lowerBand;
sDnBand.SetStyle(Curve.MEDIUM_DASH);
sDnBand.SetDefaultColor(GlobalColor("dGray"));
sDnBand.HideBubble();
sDnBand.HideTitle();
######### Higher Band ###
def mBand = MovingAverage(SecondaverageType, close, length);
def highBand = hDev * MovingAverage(SecondtrueRangeAverageType, TrueRange(high, close, low), length);
plot hUpBand = mBand + highBand;
hUpBand.SetStyle(Curve.LONG_DASH);
hUpBand.SetDefaultColor(GlobalColor("Red"));
hUpBand.HideBubble();
hUpBand.HideTitle();
plot hDnBand = mBand - highBand;
hDnBand.SetStyle(Curve.LONG_DASH);
hDnBand.SetDefaultColor(GlobalColor("Red"));
hDnBand.HideBubble();
hDnBand.HideTitle();
### Dots Positions ##
def prange = high - low;
def phigh = high + prange * .2;
def plow = low - prange * .2;
def dcUp = if close[1] crosses below midLine and close crosses above midLine or close crosses above midLine then 1 else 0;
def dcDn = if close[1] crosses above midLine and close crosses below midLine or close crosses below midLine then 1 else 0;
## Dots Direction ##
def viUpDn = if dcUp or dcDn then 1 else if viUpDn[1] == 1 and dcUp or dcDn then 1 else 0;
def debug = yes;
plot x = if !debug then Double.NaN else viUpDn;
x.Hide();
plot diDots = if dcUp and viUpDn[-1] == 0 then low else
if dcDn and viUpDn[-1] == 0 then high else Double.NaN;
diDots.SetDefaultColor(GlobalColor("Burg"));
diDots.SetStyle(Curve.POINTS);
diDots.SetLineWeight(2);
diDots.HideTitle();
diDots.HideBubble();
##### Band Dots Signals ###
plot obHighLow = if close > hUpBand or high > hUpBand then phigh else
if close < hDnBand or low < hDnBand then plow else Double.NaN;
obHighLow.SetStyle(Curve.POINTS);
obHighLow.SetDefaultColor(Color.BLACK);
obHighLow.SetLineWeight(1);
obHighLow.HideTitle();
obHighLow.HideBubble();
plot obHighLowbg = if close > hUpBand or high > hUpBand then phigh else
if close < hDnBand or low < hDnBand then plow else Double.NaN;
obHighLowbg.SetStyle(Curve.POINTS);
obHighLowbg.SetLineWeight(5);
obHighLowbg.AssignValueColor(if close > hUpBand or high > hUpBand then Color.RED else Color.GREEN);
obHighLowbg.HideTitle();
obHighLowbg.HideBubble();
##### Candles Color ###
AssignPriceColor(if dcUp then GlobalColor("Blue") else
if dcDn then GlobalColor("dBlue") else GlobalColor("Gray"));
#####
plot exitUpDn = if hUpBand crosses below sUpBand then hUpBand else
if hDnBand crosses above sDnBand then hDnBand else Double.NaN;
exitUpDn.SetPaintingStrategy(PaintingStrategy.SQUARES);
exitUpDn.SetLineWeight(3);
exitUpDn.AssignValueColor(if hUpBand crosses below sUpBand then Color.GREEN else Color.RED);
exitUpDn.HideTitle();
exitUpDn.HideBubble();