Repaints FVG Positioning Average [LuxAlgo] for ThinkOrSwim

Repaints

samer800

Moderator - Expert
VIP
Lifetime
iE3EzPv.png


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
 

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