Gap Trade Buy/Sell Indicator for ThinkorSwim

isaacramsay

New member
2019 Donor
Found this strat and gave it a go at scripting it. It's not perfect, but it works. Please let me know what you guys see, I'd love feedback and to fix any errors.

Gap Trade Buy:
  • Setup- today's open is less than yesterday's low
  • Trigger- today's price action crosses above yesterday's low + penetration amount(yesterday's range*.05)

Gap Trade Sell:
  • Setup- today's open is greater than yesterday's high
  • Trigger- today's price action crosses below yesterday's high - penetration amount(yesterday's range*.05)

It is only meant for daily charts so that's where the arrows show up. When a gap trade is set up, a label will pop up top left corner, green if gap buy, red if gap sell. On the minute charts, a line will show up at the penetration amount. When the PA is being crossed, there is an alert, because why not.

thinkScript Code

Code:
# DEFS

def range = Round((high(period = AggregationPeriod.DAY)[1] - low(period = AggregationPeriod.DAY)[1]), 2);

def pa = range * .05;

#addlabel(yes, "pa: " + pa, color.gray);

def timeframe = AggregationPeriod.DAY;

# 1Y1D CHART ARROWS

# GAB BUY

plot GTB = open(period = AggregationPeriod.DAY) is less than low(period = AggregationPeriod.DAY)[1] and close(period = AggregationPeriod.DAY) > low(period = AggregationPeriod.DAY)[1] + pa;

GTB.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

GTB.SetDefaultColor(color = Color.LIGHT_GREEN);

GTB.SetHiding(GetAggregationPeriod() != AggregationPeriod.DAY);

#AddChartBubble(GTB, open - 1, "GTB", Color.DARK_GREEN, no); #helps backtest but be careful

# BTS

plot GTS = open(period = AggregationPeriod.DAY) is greater than high(period = AggregationPeriod.DAY)[1] and close(period = AggregationPeriod.DAY) < high(period = AggregationPeriod.DAY)[1] - pa;

GTS.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

GTS.SetDefaultColor(Color.LIGHT_RED);

GTS.SetHiding(GetAggregationPeriod() != AggregationPeriod.DAY);

#AddChartBubble(GTS, open + 1, "GTS", Color.DARK_RED, yes); #helps backtest but I warned you

# ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

# GAP BUY SETUP - TODAYS OPEN IS LESS THAN YESTERDAY'S LOW

def buysetup = open(period = AggregationPeriod.DAY) is less than low(period = AggregationPeriod.DAY)[1];

AddLabel(if buysetup then yes else no, "GTB SETUP", Color.GREEN);

# GAB BUY TRIGGER - PRICE ACTION CROSSES ABOVE (YESTERDAYS CLOSE + PENETRATION_AMOUNT)

def buytrigger = close(period = AggregationPeriod.DAY) crosses above low(period = AggregationPeriod.DAY)[1] + pa and buysetup;

def bpa = Round(low(period = AggregationPeriod.DAY)[1] + pa, 2);

plot buypa = if buysetup then bpa else Double.NaN;

buypa.SetStyle(Curve.SHORT_DASH);

buypa.SetDefaultColor(Color.LIGHT_GREEN);

AddLabel(if buytrigger then yes else no, "GTB TRIGGER", Color.GREEN);

AddLabel(if buysetup then yes else no, "BUY_PA: " + bpa, Color.LIGHT_GREEN);

Alert(condition = close(period = AggregationPeriod.DAY) crosses above bpa and buysetup, text = "GTBuy TRIGGER", Alert.BAR, Sound.Bell);

# GAP SELL SETUP - TODAYS OPEN IS GREATER THAN YESTERDAY'S HIGH

def sellsetup = open(period = AggregationPeriod.DAY) is greater than high(period = AggregationPeriod.DAY)[1] ;

AddLabel(if sellsetup then yes else no, "GTS SETUP", Color.RED);

# GAP SELL TRIGGER - PRICE ACTION CROSSES BELOW (YESTERDAYS HIGH - PENETRATION_AMOUNT)

def selltrigger = close(period = AggregationPeriod.DAY) crosses below high(period = AggregationPeriod.DAY)[1] - pa and sellsetup;

def spa = Round(high(period = AggregationPeriod.DAY)[1] - pa, 2);

plot sellpa = if sellsetup then spa else Double.NaN;

sellpa.SetStyle(Curve.SHORT_DASH);

sellpa.SetDefaultColor(Color.LIGHT_RED);

AddLabel(if selltrigger then yes else no, "GTS TRIGGER", Color.RED);

AddLabel(if sellsetup then yes else no, "Sell_PA: " + spa, Color.LIGHT_RED);

Alert(close(period = AggregationPeriod.DAY) crosses below spa and sellsetup, "GTSell TRIGGER", Alert.BAR, Sound.Bell);

Shareable Link

https://tos.mx/CGsveH
unknown.png
 
Last edited by a moderator:

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