Gap Trade Buy/Sell Indicator for ThinkorSwim

I

isaacramsay

New member
VIP
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


 
Last edited by a moderator:

Top