
Author Message:
The FVG Positioning Average indicator aims to uncover potential price levels of interest by averaging together recent Fair Value Gap (FVG) initiation levels.
This indicator is grounded in the theory that significant buying or selling activity is the primary catalyst for creating FVGs.
By averaging together the prices where each FVG initiated, we may potentially reveal where major participants are positioned.
CODE:
CSS:
#// Indicator for TOS
#// © LuxAlgo
#indicator("FVG Positioning Average [LuxAlgo]", shorttitle = "LuxAlgo - FVG Positioning Average"
# Converted by Sam4Cok@Samer800 - 09/2024
input timeframe = AggregationPeriod.MIN;
input fvgLookback = 30; #Hint fvgLookback: "Determines how many FVGs to consider for calculating the averages.
input LookbackType = {default "Bar Count", "FVG Count"};
#Hint LookbackType: Bar Count => Uses any FVGs within this Bar Lookback\nFVG Count => Uses only this amount of recent FVGs.
input atrMultiplier = 0.25; #Hint atrMultiplier: Only uses FVGs that are greater than ATR * Multiplier.
input showfvgBars = no; # "Show FVGs on Chart"
input showFills = yes;
def na = Double.NaN;
def current = GetAggregationPeriod();
def tf = Max(current, timeframe);
#//ATR
def tr = TrueRange(high(Period = tf), close(Period = tf), low(Period = tf));
def nATR = WildersAverage(tr, 200);
def atr = nATR * atrMultiplier;
#//FVG Detection
def fvg_up = low (Period = tf) > high(Period = tf)[2] and close(Period = tf)[1] > high(Period = tf)[2]
and (low (Period = tf) - high(Period = tf)[2]) > atr;
def fvg_dn = high(Period = tf) < low(Period = tf)[2] and close(Period = tf)[1] < low[2]
and (low (Period = tf)[2] - high(Period = tf)) > atr;
#//Highest/Lowest
def hst = Highest(high(Period = tf), 5);
def lst = Lowest(low(Period = tf), 5);
def fvgUpSize = if fvg_up then fvgUpSize[1] + 1 else fvgUpSize[1];
def fvgDnSize = if fvg_dn then fvgDnSize[1] + 1 else fvgDnSize[1];
def condUp = fvgUpSize >= highestAll(fvgUpSize) - fvgLookback;
def condDn = fvgDnSize >= highestAll(fvgDnSize) - fvgLookback;
def fvgCntUp = if condUp then if fvg_up then fvgCntUp[1] + high(Period = tf)[2] else fvgCntUp[1] else 0;
def cntCntUp = if condUp then if fvg_up then cntCntUp[1] + 1 else cntCntUp[1] else 0;
def fvgCntDn = if condDn then if fvg_dn then fvgCntDn[1] + low(Period = tf)[2] else fvgCntDn[1] else 0;
def cntCntDn = if condDn then if fvg_dn then cntCntDn[1] + 1 else cntCntDn[1] else 0;
def fvgBarUp = Sum(if fvg_up then high(Period = tf)[2] else 0, fvgLookback);
def cntBarUp = Sum(if fvg_up then 1 else 0, fvgLookback);
def fvgBarDn = Sum(if fvg_dn then low(Period = tf)[2] else 0, fvgLookback);
def cntBarDn = Sum(if fvg_dn then 1 else 0, fvgLookback);
def up_cnt_avg = fvgCntUp / cntCntUp;
def dn_cnt_avg = fvgCntDn / cntCntDn;
def up_bar_avg = fvgBarUp / cntBarUp;
def dn_bar_avg = fvgBarDn / cntBarDn;
def up_avg; def dn_avg;
Switch (LookbackType) {
Case "FVG Count" :
up_avg = up_cnt_avg;
dn_avg = dn_cnt_avg;
Default :
up_avg = up_bar_avg;
dn_avg = dn_bar_avg;
}
#//Points to use for gradients
def oc = (open + close) / 2;
def c_mid_h = if showFills then max((oc + up_avg)/2 ,up_avg) else na;
def c_mid_l = if showFills then min((oc + dn_avg)/2 ,dn_avg) else na;
def avgUp = if hst < up_avg then na else if up_avg then up_avg else na;
def avgDn = if lst > dn_avg then na else if dn_avg then dn_avg else na;
plot up = avgUp;
plot dn = avgDn;
up.SetDefaultColor(Color.GREEN);
dn.SetDefaultColor(Color.RED);
AddCloud(if c_mid_h<=up_avg then na else c_mid_h, up, Color.DARK_GREEN);
AddCloud(if c_mid_l>=dn_avg then na else dn, c_mid_l, Color.DARK_RED);
AssignPriceColor(if !showfvgBars then Color.CURRENT else
if fvg_up[-1] then Color.CYAN else
if fvg_dn[-1] then Color.MAGENTA else Color.CURRENT);
#-- END of CODE