Repaints ICT Implied Fair Value Gaps (IFVG) For ThinkOrSwim

Repaints

Chemmy

Active member
Hi all, recently Lux Algo came out with a new ICT-related study, and it looked useful so I brought it over to ThinkScript.
The original study can be found here: https://www.tradingview.com/script/1KtO6NVA-ICT-Implied-Fair-Value-Gap-IFVG-LuxAlgo/

"An Implied Fair Value Gap (IFVG) is a three candles imbalance formation conceptualized by ICT that is based on detecting a larger candle body & then measuring the average between the two adjacent candle shadows.

This indicator automatically detects this imbalance formation on your charts and can be extended by a user set number of bars."

I've added just about all of the functionality with the exception of extending the IFVG average and the IFVG zone separately -- the only thing to note is that this study does paint two bars back, so you won't see the zones until two bars later-- it confirms on the third bar and paints back to the first. This likely shouldn't be a real issue in your daily trading though, as any real "gap" almost certainly won't be broken within just two bars.

All study options should be pretty self-explanatory other than the threshold, where raising the threshold should find more significant gaps.

vXstp3W.png


Here is the link, and the code below: http://tos.mx/tH3dzB2

Code:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
#// © LuxAlgo version=5
#indicator("ICT Implied Fair Value Gap (IFVG) [LuxAlgo]", overlay = true
## Ported by Chemmy at usethinkscript.com

## Settings

input thr    = 0.30;
input ext    = 20;
input extend_gap = no;
input add_cloud = yes;

#//Style
input showBull = yes;
input showBear = yes;

## Detection Rules

#n = bar_index
def bn = BarNumber();
def range = high - low;
def b = AbsValue(close - open);
def na = double.nan;
def showbar = bn - ext;

##//Bullish IFVG
def bull_top = (Min(close, open) + low)/2;
def bull_btm = (Max(close[2], open[2]) + high[2])/2;

def bull_ifvg = ( b[1] >Max(b, b[2]) )
  and (low < high[2] )
  and ((Min(close, open) - low) / range > thr)
  and ((high[2] - Max(close[2], open[2])) / range > thr)
  and (bull_top > bull_btm);

def bullbar = if bull_ifvg then bn else bullbar[1];

## //Bearish IFVG
def bear_top = (Min(close[2], open[2]) + low[2]) / 2;
def bear_btm = (Max(close, open) + high) /2;

def bear_ifvg = (b[1] >Max(b, b[2]) )
  and (high > low[2])
  and ( (high -Max(close, open)) / range > thr )
  and ((Min(close[2], open[2]) - low[2]) / range > thr)
  and (bear_top > bear_btm);

def bearbar = if bear_ifvg then bn else bearbar[1];

##//Display IFVG's
## Bull Gaps
def bull_ifvg_avg = if  showBull  then (bull_top + bull_btm)/2 else na;

def bull_mid = if extend_gap then (if bull_ifvg then bull_ifvg_avg[2] else bull_mid[1]) else if bullbar>=showbar then (if bull_ifvg then bull_ifvg_avg[2] else bull_mid[1]) else na;
def bull_high = if extend_gap then (if bull_ifvg then bull_top[2] else bull_high[1]) else if bullbar>=showbar then (if bull_ifvg then bull_top[2] else bull_high[1]) else na;
def bull_low = if extend_gap then (if bull_ifvg then bull_btm[2] else bull_low[1]) else if bullbar>=showbar then (if bull_ifvg then bull_btm[2] else bull_low[1]) else na;

plot blm = bull_mid ;
plot blh = bull_high ;
plot bll = bull_low ;

blm.setdefaultcolor(color.cyan);
blm.setpaintingstrategy(paintingstrategy.horizontal);
blh.setdefaultcolor(color.light_green);
blh.setpaintingstrategy(paintingstrategy.horizontal);
bll.setdefaultcolor(color.light_green);
bll.setpaintingstrategy(paintingstrategy.horizontal);

addcloud(if add_cloud then bll else na, blh, color.light_green, color.light_green);


## Bear Gaps
def bear_ifvg_avg = if showBear then(bear_top + bear_btm)/2 else na;

def bear_mid = if extend_gap then (if bear_ifvg then bear_ifvg_avg[2] else bear_mid[1]) else if bearbar>=showbar then (if bear_ifvg then bear_ifvg_avg[2] else bear_mid[1]) else na;
def bear_high = if extend_gap then (if bear_ifvg then bear_top[2] else bear_high[1]) else if bearbar>=showbar then (if bear_ifvg then bear_top[2] else bear_high[1]) else na;
def bear_low = if extend_gap then (if bear_ifvg then bear_btm[2] else bear_low[1]) else if bearbar>=showbar then (if bear_ifvg then bear_btm[2] else bear_low[1]) else na;

plot brm = bear_mid  ;
plot brh = bear_high;
plot brl = bear_low;

brm.setdefaultcolor(color.orange);
brm.setpaintingstrategy(paintingstrategy.horizontal);
brh.setdefaultcolor(color.light_red);
brh.setpaintingstrategy(paintingstrategy.horizontal);
brl.setdefaultcolor(color.light_red);
brl.setpaintingstrategy(paintingstrategy.horizontal);

addcloud(if add_cloud then brl else na, brh, color.light_red, color.light_red);


## END CODE
 
Last edited:
any chance you can convert this to be use in any time frame, I mean chart time frame?
thanks
Absolutely, I actually had converted this before and forgot to update this post. Here is the link to the MTF version of the study:
http://tos.mx/WWMOFbr

And here is the code for it:
Code:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
#// © LuxAlgo

#//@version=5
#indicator("ICT Implied Fair Value Gap (IFVG) [LuxAlgo]", overlay = true

## Settings

input thr    = 0.30;
input ext    = 20;
input extend_gap = no;
input add_cloud = yes;
input usecharttime = yes;

input agg = AggregationPeriod.FIFTEEN_MIN;

def o;
def h;
def l;
def c;

if UseChartTime
then {
    c=close;
    h=high;
    l=low;
    o=open;
} else {
    o = open(period = agg);
    h = high(period = agg);
    l = low(period = agg);
    c = close(period = agg);
}



#//Style
input showBull = yes;
input showBear = yes;

## Detection Rules

#n = bar_index
def bn = BarNumber();
def range = h - l;
def b = AbsValue(c - o);
def na = double.nan;
def showbar = bn - ext;

##//Bullish IFVG
def bull_top = (Min(c, o) + l)/2;
def bull_btm = (Max(c[2], o[2]) + h[2])/2;

def bull_ifvg = ( b[1] >Max(b, b[2]) )
  and (l < h[2] )
  and ((Min(c, o) - l) / range > thr)
  and ((h[2] - Max(c[2], o[2])) / range > thr)
  and (bull_top > bull_btm);

def bullbar = if bull_ifvg then bn else bullbar[1];

## //Bearish IFVG
def bear_top = (Min(c[2], o[2]) + l[2]) / 2;
def bear_btm = (Max(c, o) + h) /2;

def bear_ifvg = (b[1] >Max(b, b[2]) )
  and (h > l[2])
  and ( (h -Max(c, o)) / range > thr )
  and ((Min(c[2], o[2]) - l[2]) / range > thr)
  and (bear_top > bear_btm);

def bearbar = if bear_ifvg then bn else bearbar[1];

##//Display IFVG's
## Bull Gaps
def bull_ifvg_avg = if  showBull  then (bull_top + bull_btm)/2 else na;

def bull_mid = if extend_gap then (if bull_ifvg then bull_ifvg_avg[2] else bull_mid[1]) else if bullbar>=showbar then (if bull_ifvg then bull_ifvg_avg[2] else bull_mid[1]) else na;
def bull_high = if extend_gap then (if bull_ifvg then bull_top[2] else bull_high[1]) else if bullbar>=showbar then (if bull_ifvg then bull_top[2] else bull_high[1]) else na;
def bull_low = if extend_gap then (if bull_ifvg then bull_btm[2] else bull_low[1]) else if bullbar>=showbar then (if bull_ifvg then bull_btm[2] else bull_low[1]) else na;

plot blm = bull_mid ;
plot blh = bull_high ;
plot bll = bull_low ;

blm.setdefaultcolor(color.cyan);
blm.setpaintingstrategy(paintingstrategy.horizontal);
blh.setdefaultcolor(color.light_green);
blh.setpaintingstrategy(paintingstrategy.horizontal);
bll.setdefaultcolor(color.light_green);
bll.setpaintingstrategy(paintingstrategy.horizontal);

addcloud(if add_cloud then bll else na, blh, color.light_green, color.light_green);


## Bear Gaps
def bear_ifvg_avg = if showBear then(bear_top + bear_btm)/2 else na;

def bear_mid = if extend_gap then (if bear_ifvg then bear_ifvg_avg[2] else bear_mid[1]) else if bearbar>=showbar then (if bear_ifvg then bear_ifvg_avg[2] else bear_mid[1]) else na;
def bear_high = if extend_gap then (if bear_ifvg then bear_top[2] else bear_high[1]) else if bearbar>=showbar then (if bear_ifvg then bear_top[2] else bear_high[1]) else na;
def bear_low = if extend_gap then (if bear_ifvg then bear_btm[2] else bear_low[1]) else if bearbar>=showbar then (if bear_ifvg then bear_btm[2] else bear_low[1]) else na;

plot brm = bear_mid  ;
plot brh = bear_high;
plot brl = bear_low;

brm.setdefaultcolor(color.orange);
brm.setpaintingstrategy(paintingstrategy.horizontal);
brh.setdefaultcolor(color.light_red);
brh.setpaintingstrategy(paintingstrategy.horizontal);
brl.setdefaultcolor(color.light_red);
brl.setpaintingstrategy(paintingstrategy.horizontal);

addcloud(if add_cloud then brl else na, brh, color.light_red, color.light_red);


## END CODE
 

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