Repaints MTF First Gap of the Day For ThinkOrSwim

Repaints

FutureTony

Well-known member
VIP
This simple indicator is based on the ICT 'Silver Bullet' concept. The idea is that the first gap created after the New York open becomes an important price area that price will react to in the future. This is really just a refined version of opening range price as it attempts to find the 'most sensitive' area in the opening range. See this description from ICT for more information. This is intended to be used on index futures and only on timeframes of 5 minutes or less.

7f89Oic.png


As per the link above, the idea is that you've done higher timeframe analysis and are expecting price to move to an obvious area. You can use the first gap area as an entry to move into your expected direction. The study allows you to select a time period to search for the first gap - it defaults to the first 30 minutes. You can also specify how large the gap needs to be to qualify - it defaults to 2 ticks. It will print a cloud for the gap area until 4pm. If you were a curious sort and traded different hours, you could try to identify the first gap after the Euro or Asian open and backtest their performance.

Ruby:
# Created by @tony_futures inspired by the ICT 'Silver Bullet' concept

input agg = AggregationPeriod.FIVE_MIN;
input NY_Open = 0930; 
input Gap_End = 1000; 
input NY_Close = 1600;
input requiredTicks = 2; # minimum gap size
def xH = high(period = agg);
def xL = low(period = agg);
def xH2 = high(period = agg)[2];
def xL2 = low(period = agg)[2];
def currentAgg = agg / 60000;

Assert(currentAgg <= 5,"This study is meant to work on timeframes of 5 minutes or less");

def Gap_Start = NY_Open + (currentAgg * 2);
def rth = SecondsFromTime(Gap_Start) >= 0 and SecondsTillTime(Gap_End) >= 0;
def paint = SecondsFromTime(Gap_Start)[1] >= 0 and SecondsTillTime(NY_Close) >= 0;

def bearishGap = xH < xL[2] and (AbsValue(xH - xL[2]) >= (requiredTicks * tickSize()));
def bullishGap = xH[2] < xL and (AbsValue(xH[2] - xL) >= (requiredTicks * tickSize()));

def firstCandle = SecondsFromTime(0930) == 0;
def firstGapHigh = if firstCandle then 0 else if firstGapHigh[1] == 0 and rth and bullishGap then xL else if firstGapHigh[1] == 0 and rth and bearishGap then xL2 else  firstGapHigh[1];
def firstGapLow = if firstCandle then 0 else if firstGapLow[1] == 0 and rth and bullishGap then xH2  else if firstGapLow[1] == 0 and rth and bearishGap then xH else firstGapLow[1];

def bGH = firstGapHigh;
def bGL = firstGapLow[1];

DefineGlobalColor("CloudColor", Color.GRAY);
AddCloud(if paint and bGH[1] != 0 then bGH else Double.NaN,bGL,GlobalColor("CloudColor"), GlobalColor("CloudColor"));
 
This simple indicator is based on the ICT 'Silver Bullet' concept. The idea is that the first gap created after the New York open becomes an important price area that price will react to in the future. This is really just a refined version of opening range price as it attempts to find the 'most sensitive' area in the opening range. See this description from ICT for more information. This is intended to be used on index futures and only on timeframes of 5 minutes or less.

7f89Oic.png


As per the link above, the idea is that you've done higher timeframe analysis and are expecting price to move to an obvious area. You can use the first gap area as an entry to move into your expected direction. The study allows you to select a time period to search for the first gap - it defaults to the first 30 minutes. You can also specify how large the gap needs to be to qualify - it defaults to 2 ticks. It will print a cloud for the gap area until 4pm. If you were a curious sort and traded different hours, you could try to identify the first gap after the Euro or Asian open and backtest their performance.

Ruby:
# Created by @tony_futures inspired by the ICT 'Silver Bullet' concept

input agg = AggregationPeriod.FIVE_MIN;
input NY_Open = 0930;
input Gap_End = 1000;
input NY_Close = 1600;
input requiredTicks = 2; # minimum gap size
def xH = high(period = agg);
def xL = low(period = agg);
def xH2 = high(period = agg)[2];
def xL2 = low(period = agg)[2];
def currentAgg = agg / 60000;

Assert(currentAgg <= 5,"This study is meant to work on timeframes of 5 minutes or less");

def Gap_Start = NY_Open + (currentAgg * 2);
def rth = SecondsFromTime(Gap_Start) >= 0 and SecondsTillTime(Gap_End) >= 0;
def paint = SecondsFromTime(Gap_Start)[1] >= 0 and SecondsTillTime(NY_Close) >= 0;

def bearishGap = xH < xL[2] and (AbsValue(xH - xL[2]) >= (requiredTicks * tickSize()));
def bullishGap = xH[2] < xL and (AbsValue(xH[2] - xL) >= (requiredTicks * tickSize()));

def firstCandle = SecondsFromTime(0930) == 0;
def firstGapHigh = if firstCandle then 0 else if firstGapHigh[1] == 0 and rth and bullishGap then xL else if firstGapHigh[1] == 0 and rth and bearishGap then xL2 else  firstGapHigh[1];
def firstGapLow = if firstCandle then 0 else if firstGapLow[1] == 0 and rth and bullishGap then xH2  else if firstGapLow[1] == 0 and rth and bearishGap then xH else firstGapLow[1];

def bGH = firstGapHigh;
def bGL = firstGapLow[1];

DefineGlobalColor("CloudColor", Color.GRAY);
AddCloud(if paint and bGH[1] != 0 then bGH else Double.NaN,bGL,GlobalColor("CloudColor"), GlobalColor("CloudColor"));
There was no gap yesterday. But today was a nice one:

JjrBaor.png


Two points of drawdown and then it ran 14 points in our direction.
 
@FutureTony , hi bro, thank you for the script. May I check where should you put you stop loss? Cheers
The 'gap' is a 3 candle formation. You should place your stop (at least) above the highest of the 3 candles if bearish or below the lowest of the 3 candles if bullish. I would encourage you to backtest this indicator and see how price typically behaves around these areas.
 
@FutureTony , I am little confused. on 04/18 on your picture at 9.30 EST in the morning price is around 4164 while in my chart it is showing as 4188. i am using the same /ES symbol too. and i do not see any GAP Cloud at that area nor on 04/20. do you mind sharing your chart once ? Thanks
 
Code:
def ConsequentEncroachment = Round((((bGH-bGL)/2) + bGL) / 0.25,0) * 0.25;
Plot CE = consequentEncroachment;
CE.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
#CE.SetdefaultColor(Color.gray);
CE.Setlineweight(1);
CE.SetHiding(!ShowCE);
CE.AssignValuecolor(if Close > CE then color.green else if Close < CE then color.red else color.gray);
I Added a Consequent Encroachment value to the gap. Yet I was wondering if someone could help me draw a plot across to the current time for Consequent Encroachment Values.
I'd like to have the C.E. plotted until traded through and gap "filled" (consolidation type behavior within the gap) or simply a plot that draws across until the next (Current) firstgap/C.E. is plotted.
The first gap and C.E. may remain Points of interest beyond the initial session so it would be nice to be able to refer to previous levels more conveniently.
 
does this repaint?

This is an MTF (multi-timeframe) indicator.
It overlays a higher timeframe on your lower timeframe chart.

As it is not possible to know what the close of the higher timeframe candle is going to be; it will repaint in the interim.
The overlay of 5min candles on a 1min chart, will cause five 1min candles to repaint until the 5min candle closes.
 
Last edited:
Curious is a watchlist column can be created for the ICT Silver Bullet script using a 5 minute chart and have labels that indicates "Bull" and colored green when price is above when the indicator is triggered and "Bear" and colored red when price is below when the indicator is triggerd?
 
Curious is a watchlist column can be created for the ICT Silver Bullet script using a 5 minute chart and have labels that indicates "Bull" and colored green when price is above when the indicator is triggered and "Bear" and colored red when price is below when the indicator is triggerd?
First Gap Of The Day Watchlist
shared watchlist column script link: http://tos.mx/P71fVbL Click here for --> Easiest way to load shared links
dNwV0Tg.png
ENeLgBP.png

Ruby:
# Created by @tony_futures inspired by the ICT 'Silver Bullet' concept
# WATCHLIST SCRIPT only
input agg = AggregationPeriod.FIVE_MIN;
input NY_Open = 0930;
input Gap_End = 1000;
input NY_Close = 1600;
input requiredTicks = 2; # minimum gap size
def xH = high(period = agg);
def xL = low(period = agg);
def xH2 = high(period = agg)[2];
def xL2 = low(period = agg)[2];
def currentAgg = agg / 60000;

Assert(currentAgg <= 5,"This study is meant to work on timeframes of 5 minutes or less");

def Gap_Start = NY_Open + (currentAgg * 2);
def rth = SecondsFromTime(Gap_Start) >= 0 and SecondsTillTime(Gap_End) >= 0;
def paint = SecondsFromTime(Gap_Start)[1] >= 0 and SecondsTillTime(NY_Close) >= 0;

def bearishGap = xH < xL[2] and (AbsValue(xH - xL[2]) >= (requiredTicks * tickSize()));
def bullishGap = xH[2] < xL and (AbsValue(xH[2] - xL) >= (requiredTicks * tickSize()));

def firstCandle = SecondsFromTime(0930) == 0;
def firstGapHigh = if firstCandle then 0 else if firstGapHigh[1] == 0 and rth and bullishGap then xL else if firstGapHigh[1] == 0 and rth and bearishGap then xL2 else  firstGapHigh[1];
def firstGapLow = if firstCandle then 0 else if firstGapLow[1] == 0 and rth and bullishGap then xH2  else if firstGapLow[1] == 0 and rth and bearishGap then xH else firstGapLow[1];

def bGH = firstGapHigh;
def bGL = firstGapLow[1];

AddLabel(bGH[1] != 0,
 if close > bGH then "bull" else
 if close < bGL then "bear" else " ",
 if close > bGH then color.green else
 if close < bGL then color.red else color.black);
 
Does anyone know if it's possible to extend the cloud into the current day? Like the green cloud in the picture here:
 

Attachments

  • Screenshot 2024-03-12 231511.png
    Screenshot 2024-03-12 231511.png
    117.1 KB · Views: 42
Does anyone know if it's possible to extend the cloud into the current day? Like the green cloud in the picture here:
I'm sure there might be more eloquent solutions, but if you add this to the bottom of the code, you get clouds going until the next day at 4pm. There is a small gap at the 9:30 open but should work well enough for you:

Ruby:
def sec1 = SecondsFromTime(NY_Close);
def sec2 = SecondsFromTime(NY_Open);
def NY_Open_Time = SecondsFromTime(NY_Open) == 0;
def paint2 = SecondsFromTime(NY_Open)[1] >= 0 and SecondsTillTime(NY_Close) >= 0;
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);
def inRange = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else inRange[1], 0);
def active = inRange;
AddCloud(if active and bGH[1] != 0 then bGH else Double.NaN,bGL,GlobalColor("CloudColor"), GlobalColor("CloudColor"));
def bghOld = if NY_Open_Time then bgh[1] else bghOld[1];
def bglOld = if NY_Open_Time then bgl[1] else bglOld[1];
def bghOld1 = bghOld[1];
def bglOld1 = bglOld[1];
AddCloud(if paint2 and bGHOld1 != 0 then bGHOld1 else Double.NaN,bGLOld1,GlobalColor("CloudColor"), GlobalColor("CloudColor"));
 
I'm sure there might be more eloquent solutions, but if you add this to the bottom of the code, you get clouds going until the next day at 4pm. There is a small gap at the 9:30 open but should work well enough for you:

Ruby:
def sec1 = SecondsFromTime(NY_Close);
def sec2 = SecondsFromTime(NY_Open);
def NY_Open_Time = SecondsFromTime(NY_Open) == 0;
def paint2 = SecondsFromTime(NY_Open)[1] >= 0 and SecondsTillTime(NY_Close) >= 0;
def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);
def inRange = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else inRange[1], 0);
def active = inRange;
AddCloud(if active and bGH[1] != 0 then bGH else Double.NaN,bGL,GlobalColor("CloudColor"), GlobalColor("CloudColor"));
def bghOld = if NY_Open_Time then bgh[1] else bghOld[1];
def bglOld = if NY_Open_Time then bgl[1] else bglOld[1];
def bghOld1 = bghOld[1];
def bglOld1 = bglOld[1];
AddCloud(if paint2 and bGHOld1 != 0 then bGHOld1 else Double.NaN,bGLOld1,GlobalColor("CloudColor"), GlobalColor("CloudColor"));
This works great. Thank you for your help!
 

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