fair value gap / imbalance
Full information refer to below link - I add MTF option as well
https://www.tradingview.com/v/96ZstKf8/
Full information refer to below link - I add MTF option as well
https://www.tradingview.com/v/96ZstKf8/
CSS:
#/ © DojiEmoji
#// This script is tailored towards experienced traders who prefer to view raw price charts during live execution.
#// It searches for a three-bar pattern of what is colloquially called "fair value gap", or "imbalance" and uses
#// a single line to plot the results. The goal is to display price in a way that is as simple as possible so that
#// chart readers who don't prefer to add indicators on their screen will still find this indicator as an
#// acceptable option to consider for.
#indicator("3 Bar Gap [DojiEmoji]", overlay=true)
# Converted and mod by Sam4Cok@Samer800 - 02/2023
input ShowCloud = yes;
input UseChartTimeFrame = yes;
input ManualTimeFrame = AggregationPeriod.HOUR;
input atr_Length = 20; # "ATR Length"
input atr_multi = 0.65; # "Multi"
def na = Double.NaN;
def last = isNaN(Close);
def hTF; def cTF; def lTF;
if UseChartTimeFrame {
htf = high;
ctf = close;
ltf = low;
} else {
htf = high(Period=ManualTimeFrame);
ctf = close(Period=ManualTimeFrame);
ltf = low(Period=ManualTimeFrame);
}
#
script insert_gap {
input price_t_minustwo = high;
input price_t_zero = low;
def pivot_upper = max(price_t_minustwo, price_t_zero);
def pivot_lower = min(price_t_minustwo, price_t_zero);
def pivot_mid = (pivot_upper+ pivot_lower)/2;
def linecolor = if price_t_minustwo < price_t_zero then 1 else
if price_t_minustwo > price_t_zero then -1 else 0;
plot mid = pivot_mid;
plot Color = linecolor;
}
def tr = TrueRange(htf, ctf, ltf);
def nATR = WildersAverage(tr, atr_Length);
def threshold = nATR * atr_multi;
def PivotUpMain = insert_gap(htf[2], ltf[0]).mid;
def PivotUpColo = insert_gap(htf[2], ltf[0]).Color;
def PivotUpThre = PivotUpMain + threshold;
def PivotDnMain = insert_gap(ltf[2], htf[0]).mid;
def PivotDnColo = insert_gap(ltf[2], htf[0]).Color;
def PivotDnThre = PivotDnMain - threshold;
def main_pivot;def linecolor; def PivUp; def PivDn;
def displacement_up = ltf[0] - htf[2];
def displacement_dn = htf[0] - ltf[2];
if AbsValue(displacement_up) > threshold and displacement_up > 0 {
main_pivot = PivotUpMain;
linecolor = PivotUpColo;
PivUp = PivotUpThre;#main_pivot + threshold;
PivDn = PivDn[1];
} else
if AbsValue(displacement_dn) > threshold and displacement_dn < 0 {
main_pivot = PivotDnMain;
linecolor = PivotDnColo;
PivUp = PivUp[1];
PivDn = PivotDnThre;#main_pivot - threshold;
} else {
main_pivot = main_pivot[1];
linecolor = linecolor[1];
PivUp = PivUp[1];
PivDn = PivDn[1];
}
def Pivot = if linecolor==0 or main_pivot!=main_pivot[1] or last then na else main_pivot;
def PivotUp = if linecolor<=0 or main_pivot!=main_pivot[1] or last then na else PivUp;
def PivotDn = if linecolor>=0 or main_pivot!=main_pivot[1] or last then na else PivDn;
plot PivotMid = Pivot[-1];
PivotMid.AssignValueColor(if linecolor>0 then Color.Green else Color.RED);
AddCloud(if ShowCloud then PivotUp[-1] else na, Pivot[-1], Color.DARK_GREEN, Color.DARK_RED);
AddCloud(if ShowCloud then PivotDn[-1] else na, Pivot[-1], Color.DARK_GREEN, Color.DARK_RED);
#---END CODE
Last edited by a moderator: