Potential Breakout (PBO) Indicator for ThinkorSwim

gravityflyer

New member
Hi all,

I just wanted to share my first thinkScript indicator and kindly seeking your assistance in refining the code.

Code:
# Potential Breakout (PBO) indicator
# gravityflyer
# v1.0 - 2021.04.05

declare lower;
declare real_size;

#Input Price Line
input priceType = PriceType.LAST;
plot LastPrice = close(priceType = priceType);
LastPrice.SetDefaultColor(GetColor(7));

#Input Bolinger Band Width
input averageType = AverageType.Simple;
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -1.0;
input Num_Dev_Up = 1.0;
input BulgeLength = 150;
input SqueezeLength = 150;

def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).LowerBand;
def midLine = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).MidLine;

plot Bandwidth = (upperBand - lowerBand) / midLine * 100;
Bandwidth.SetDefaultColor(Color.WHITE);

#Painting Strategy
LastPrice.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
LastPrice.DefineColor("Normal", Color.GRAY);
LastPrice.DefineColor("BuySignal", Color.GREEN);
LastPrice.DefineColor("SellSignal", Color.RED);
LastPrice.AssignValueColor(if LastPrice > upperBand then LastPrice.Color("BuySignal") else if LastPrice < lowerBand then LastPrice.Color("SellSignal") else LastPrice.Color("Normal"));

#Input Reference Line
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(8));
ZeroLine.setStyle(Curve.SHORT_DASH);

In short, the indicator works as I intended. Yay for me! :giggle: That said, the presentation needs more refinement. Some issues I'm having:
  • The scale is obviously not consistent with the price/BB superimposed. I thought "declare real_size" would fix the issue?
  • How do I fill the upper and lower bands with a color, ideally with a lower opacity? Would that be with the "Add.Cloud" code? As indicated by the code, buy/sell signals would occur above/below such values.
  • In terms of painting strategy, you'll notice it's painting the LastPrice and thus the signal is slightly delayed (see pic below). Is there a way to repaint on the current price or should I not worry about it?
xKuJkIc.png

  • Finally, how can I add buy/sell signals at the bottom of the indicator below the 0 reference line?
Thank you in advance for your assistance!
 
interesting. this actually looks pretty good on the 2min chart

Glad you're enjoying it! Here's v2 of my script if interested...

Code:
# Potential Breakout (PBO) indicator
# gravityflyer
# v1.0 - 2021.04.05
# v2.0 - 2021.04.07: Converted indicator into single line.

declare lower;

#Input Bolinger Band Width
input averageType = AverageType.Simple;
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -1.0;
input Num_Dev_Up = 1.0;
input BulgeLength = 150;
input SqueezeLength = 150;


def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).LowerBand;
def midLine = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).MidLine;

#plot Bandwidth = (upperBand - lowerBand) / midLine * 100;
#Bandwidth.SetDefaultColor(Color.WHITE);

#Input Price Line
#input priceType = PriceType.LAST;
#plot LastPrice = close(priceType = priceType);
#LastPrice.SetDefaultColor(GetColor(7));

#PBO Painting Strategy
plot PBO = If(IsNaN(close), Double.NaN, 0);
PBO.DefineColor("Normal", Color.GRAY);
PBO.DefineColor("BuySignal", Color.GREEN);
PBO.DefineColor("SellSignal", Color.RED);
PBO.AssignValueColor(if price > upperBand then PBO.Color("BuySignal") else if price < lowerBand then PBO.Color("SellSignal") else PBO.Color("Normal"));
PBO.SetPaintingStrategy(PaintingStrategy.POINTS);
PBO.SetLineWeight(3);

#Arrows#
plot BUY = 0;
plot TakeProfit = 0;
plot UpSignal = if price crosses above upperBand then BUY else Double.NaN;
plot DownSignal = if price crosses below lowerBand then TakeProfit else Double.NaN;

input showBreakoutSignals = yes;
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

UpSignal.SetDefaultColor(Color.GREEN);
DownSignal.SetDefaultColor(Color.RED);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
I was trying out .... its works great for scalp ... i am in tick chart , don't know about higher time frame ... works great on Nadex to scalp 20 - 30 / per contract on ES for 20 min exp. (please dont take your trading decision based off only this indicator... you have to have NADEX strategy )
 
I've been backtesting and this has helped with some false signals from other indicators. Thank you for sharing :)
 
Nice indicator, thanks for sharing. Novice coder (that's being generous) looking to see if I could make a watchlist column out of this study by comparing yours to a column I found from somewhere that gave a thumbs up/thumbs down in what looks like to be off the ATR indicator. Anyhoo...code's comparison and comprehension is beyond my level.

There anyway someone could make a watchlist column using this PBO indicator? I'd like to set it to check on the one min candle and paint the Arrows if a PBO hits.

Much gracious in advance.
 
I saw this PBO posted by another member and was wondering how to add labels? I am a novice to programming and wanted to ask some of you veterans. Thank you for any responses.

Code:
# Potential Breakout (PBO) indicator
# gravityflyer
# v1.0 - 2021.04.05
# v2.0 - 2021.04.07: Converted indicator into single line.

declare lower;

#Input Bolinger Band Width
input averageType = AverageType.Simple;
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -1.0;
input Num_Dev_Up = 1.0;
input BulgeLength = 150;
input SqueezeLength = 150;


def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).LowerBand;
def midLine = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).MidLine;

#plot Bandwidth = (upperBand - lowerBand) / midLine * 100;
#Bandwidth.SetDefaultColor(Color.WHITE);

#Input Price Line
#input priceType = PriceType.LAST;
#plot LastPrice = close(priceType = priceType);
#LastPrice.SetDefaultColor(GetColor(7));

#PBO Painting Strategy
plot PBO = If(IsNaN(close), Double.NaN, 0);
PBO.DefineColor("Normal", Color.GRAY);
PBO.DefineColor("BuySignal", Color.GREEN);
PBO.DefineColor("SellSignal", Color.RED);
PBO.AssignValueColor(if price > upperBand then PBO.Color("BuySignal") else if price < lowerBand then PBO.Color("SellSignal") else PBO.Color("Normal"));
PBO.SetPaintingStrategy(PaintingStrategy.POINTS);
PBO.SetLineWeight(3);

#Arrows#
plot BUY = 0;
plot TakeProfit = 0;
plot UpSignal = if price crosses above upperBand then BUY else Double.NaN;
plot DownSignal = if price crosses below lowerBand then TakeProfit else Double.NaN;

input showBreakoutSignals = yes;
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

UpSignal.SetDefaultColor(Color.GREEN);
DownSignal.SetDefaultColor(Color.RED);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 

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