Volume Imbalance MTF

SymmetricalM

New member
VIP
I'm currently working on a volume imbalance indicator which seems to be executing quite well.

This started as a result of me discovering this TradingView study: https://www.tradingview.com/script/MDxlrsRo-ICT-GAPs-and-Volume-Imbalance/

My idea is that once the a bar has closed above or below the corresponding gaps, it indicates that this imbalance has been corrected. However, I have run into an issue where the previous VI stops plotting before hitting the intended condition if a new loop starts for another VI gap. I would like for these VI to stay plotted until they have been corrected despite new VI forming.

Code:
#Volume Imbalance Indicator
#SymmetricalM
#V.01

#START
declare upper;
input Time_Frame = AggregationPeriod.FIFTEEN_MIN;
input ShowClouds = yes;

def H = high(period = Time_Frame);
def L = low(period = Time_Frame);
def O = open(period = Time_Frame);
def C = close(period = Time_Frame);

input tick = 0.25;
input FirstAGG = yes;
def na = double.nan;

input crossed_line = {"invisible", default "dashes", "solid"};

def cross;
if crossed_line == crossed_line."invisible" then {
    cross = 1;
} else if crossed_line == crossed_line."dashes" then {
    cross = 2;
} else if crossed_line == crossed_line."solid" then {
    cross= 3;
} else {
    cross = 0;
};

#--------------Bearish VI---------------#
#Bearish conditions:
def B1 = C[1] < o; #Main criteria
def B2 = c > o; #Current Bar criteria
def B3 = c[1] > o[1] and (o - c[1]) >= tick; #Previous Bar criteria

def triggerBe = if B1 and B2 and B3 then 1 else 0;

def bearish_bot = if triggerBe == 1 and FirstAGG then c[1] else bearish_bot[1];
def bearish_top = if triggerBe == 1 and FirstAGG then o else bearish_top[1];

# Flag to track if the condition has been met
def stopCondBe = c < bearish_top;

def holdBe = if triggerBe == 1 then 0
  else if holdBe[1] == 1 then holdBe[1]
  else if stopCondBe then 1
  else holdBe[1];

plot bear_imbalance_top_line = if holdBe[1] == 1 then cross else bearish_top;
plot bear_imbalance_bot_line = if holdBe[1] == 1 then cross else bearish_bot;

bear_imbalance_top_line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bear_imbalance_bot_line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bear_imbalance_top_line.SetDefaultColor(color.plum);
bear_imbalance_bot_line.SetDefaultColor(color.plum);

def bearish_bot1 = if triggerBe == 1 and FirstAGG then c[1] else na;
def bearish_top1 = if triggerBe == 1 and FirstAGG then o else na;

plot bear_imbalance_top_line1 = If (bearish_top1, o, na);
bear_imbalance_top_line1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bear_imbalance_top_line1.SetDefaultColor(color.plum);
bear_imbalance_top_line1.SetLineWeight(1);
bear_imbalance_top_line1.HideBubble();
#addCloud(bear_imbalance_top_line, bear_imbalance_bot_line, color.red, color.red);


plot bear_imbalance_bot_line1 = If (bearish_bot1, c[1], na);
bear_imbalance_bot_line1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bear_imbalance_bot_line1.SetDefaultColor(color.plum);
bear_imbalance_bot_line1.SetLineWeight(1);
bear_imbalance_bot_line1.HideBubble();


#--------------Bullish VI---------------#
#Bullish conditions:
def Bu1 = C[1] > O; #Main criteria
def Bu2 = o > c; #Current Bar criteria
def Bu3 = o[1] > c[1] and (c[1] - o) >= tick; #Previous Bar criteria

def triggerBu = if Bu1 and Bu2 and Bu3 then 1 else 0;

def bullish_top = if triggerBu == 1 and FirstAGG then c[1] else bullish_top[1];
def bullish_bot = if triggerBu == 1 and FirstAGG then o else bullish_bot[1];


# Flag to track if the condition has been met
def stopCondBu = c > bullish_bot;

def holdBu = if triggerBu == 1 then 0
  else if holdBu[1] == 1 then holdBu[1]
  else if stopCondBu then 1
  else holdBu[1];

plot bull_imbalance_top_line = if holdBu[1] == 1 then cross else bullish_top;
plot bull_imbalance_bot_line = if holdBu[1] == 1 then cross else bullish_bot;

bull_imbalance_top_line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bull_imbalance_bot_line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bull_imbalance_top_line.SetDefaultColor(color.plum);
bull_imbalance_bot_line.SetDefaultColor(color.plum);
#addCloud(bull_imbalance_top_line, bull_imbalance_bot_line, color.green, color.green);

def bullish_top1 = if triggerBu == 1 and FirstAGG then c[1] else na;
def bullish_bot1 = if triggerBu == 1 and FirstAGG then o else na;

plot bull_imbalance_top_line1 = If (bullish_top1, c[1], na);
bull_imbalance_top_line1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bull_imbalance_top_line1.SetDefaultColor(color.plum);
bull_imbalance_top_line1.SetLineWeight(1);
bull_imbalance_top_line1.HideBubble();

plot bull_imbalance_bot_line1 = If (bullish_bot1, o, na);
bull_imbalance_bot_line1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bull_imbalance_bot_line1.SetDefaultColor(color.plum);
bull_imbalance_bot_line1.SetLineWeight(1);
bull_imbalance_bot_line1.HideBubble();

#END

share link: http://tos.mx/JDtTM3L

Any help is appreciated! Thank you.
 

Attachments

  • VI.PNG
    VI.PNG
    50.3 KB · Views: 476

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