HiLoBands Upper Indicator For ThinkOrSwim

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]']
PlUWpzP.png


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();
 

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
423 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