FVG Within Fib Range

johnwood34

New member
VIP
Can someone help me?
The conditions are as follows:
First, I need to see a break in market structure.
Second is an imbalance has been created.
Then, i'm looking for price to retrace back into the 71% and 79% fib level (my buy and or sell signal). Stop loss is the 0% fib level.
Take profit is the 100% fib level.

Was really looking for the script to automatically plot, once the new high/low is created, these fib lines. (From bullish/bearish order block to new high/low)

Oh! Would also like the script to adapt to each timeframe if at all possible...

20250119_183425.jpg
20250119_192752.jpg
 
Last edited by a moderator:
Can someone help me with this script? This is as much as I could get figured out using chatgpt. The conditions are as follows: First, I need to see a break in market structure. Second is an imbalance has been created. Then, i'm looking for price to retrace back into the 71% and 79% fib level (my buy and or sell signal). Stop loss is the 0% fib level. Take profit is the 100% fib level. Was really looking for the script to automatically plot, once the new high/low is created, these fib lines. (From bullish/bearish order block to new high/low) Based on the pic provided, i'm close, but the buy and sell signals are not showing up. I don't even believe the fair value gaps are highlighting as they should. Hope this makes sense. Pic provided and any help would be GREATLY appreciated...Oh! Would also like the script to adapt to each timeframe if at all possible...

View attachment 23890View attachment 23891
Code:
#Golden Zone Strategy (Created using ChatGPT)
# This script highlights the candles that have detected imbalances (Fair Value Gaps),
# plots Golden Zone Fibonacci levels (71% and 79%), and includes Take Profit (at 100% Fibonacci)
# and Stop Loss (at 0% Fibonacci) levels.
# The Fibonacci levels are calculated dynamically based on the highest high and lowest low of the most recent price action.

# Define the lookback period for high/low calculation
input lookbackBars = 50;

# Calculate the highest high and lowest low over the lookback period
def highestHigh = highest(high, lookbackBars);
def lowestLow = lowest(low, lookbackBars);

# Calculate Fibonacci retracement levels (71% and 79%)
def fib0 = lowestLow;
def fib100 = highestHigh;
def fib71 = fib0 + 0.71 * (fib100 - fib0); # 71% retracement level
def fib79 = fib0 + 0.79 * (fib100 - fib0); # 79% retracement level

# Detect Imbalances (Fair Value Gap)
def imbalanceUp = high[1] < low; # Bullish imbalance (gap down)
def imbalanceDown = low[1] > high; # Bearish imbalance (gap up)

# Market Structure Breaks (Swing High / Swing Low Breaks)
# Market structure break for bullish trend: Current price must break above the previous swing high
def breakOfStructureUp = close > highestHigh[1]; # Break above previous swing high

# Market structure break for bearish trend: Current price must break below the previous swing low
def breakOfStructureDown = close < lowestLow[1]; # Break below previous swing low

# Condition 1: Break of structure (for both bullish and bearish)
def breakStructure = breakOfStructureUp or breakOfStructureDown;

# Condition 2: Imbalance (gap up or gap down)
def gapUp = low[1] > high; # Bearish imbalance (gap up)
def gapDown = high[1] < low; # Bullish imbalance (gap down)

# Condition 3: Retracement to Golden Zone (between 71% and 79% Fibonacci)
def withinGoldenZone = close >= fib71 and close <= fib79;

# Combine all conditions
def buySignalCondition = breakOfStructureUp and gapDown and withinGoldenZone; # Buy signal
def sellSignalCondition = breakOfStructureDown and gapUp and withinGoldenZone; # Sell signal

# Plot Fibonacci retracement levels as horizontal lines (always visible)
plot fib71Line = fib71;
plot fib79Line = fib79;

# Set appearance of the Fibonacci levels
fib71Line.SetDefaultColor(Color.CYAN);
fib79Line.SetDefaultColor(Color.GREEN);

# Highlight the Golden Zone area (between 71% and 79% retracement)
AddCloud(fib71Line, fib79Line, Color.YELLOW, Color.YELLOW);

# Highlight Take Profit (100% Fibonacci) and Stop Loss (0% Fibonacci) levels
plot takeProfitLine = fib100; # Take Profit at 100% Fibonacci (Swing High)
plot stopLossLine = fib0; # Stop Loss at 0% Fibonacci (Swing Low)

# Set the appearance of Take Profit and Stop Loss lines
takeProfitLine.SetDefaultColor(Color.BLUE);
stopLossLine.SetDefaultColor(Color.RED);

# Set line weight for better visibility
fib71Line.SetLineWeight(2);
fib79Line.SetLineWeight(2);
takeProfitLine.SetLineWeight(2);
stopLossLine.SetLineWeight(2);

# Optional: Plot the swing high and low for reference
plot swingHighLine = highestHigh;
plot swingLowLine = lowestLow;

swingHighLine.SetDefaultColor(Color.RED);
swingLowLine.SetDefaultColor(Color.RED);

# Set line weight for better visibility
swingHighLine.SetLineWeight(1);
swingLowLine.SetLineWeight(1);

# Highlight candles with imbalances (gap up or gap down)
# Bullish imbalance (gap down) — green candle
AssignPriceColor(if buySignalCondition then Color.GREEN else Color.CURRENT);

# Bearish imbalance (gap up) — red candle
AssignPriceColor(if sellSignalCondition then Color.RED else Color.CURRENT);

# Add Buy and Sell signals as arrows or labels
plot buySignalArrow = if buySignalCondition then low - 0.1 else Double.NaN;
plot sellSignalArrow = if sellSignalCondition then high + 0.1 else Double.NaN;

buySignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buySignalArrow.SetDefaultColor(Color.GREEN);
buySignalArrow.SetLineWeight(3);

sellSignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sellSignalArrow.SetDefaultColor(Color.RED);
sellSignalArrow.SetLineWeight(3);

350....

learn how to describe what price on which bar, has to do something.

these words are opinions and are useless,
. see a break in market structure
. an imbalance has been created

what has to really happen with a price for those descriptions to happen?
 
Can someone help me with this script? This is as much as I could get figured out using chatgpt. The conditions are as follows: First, I need to see a break in market structure. Second is an imbalance has been created. Then, i'm looking for price to retrace back into the 71% and 79% fib level (my buy and or sell signal). Stop loss is the 0% fib level. Take profit is the 100% fib level. Was really looking for the script to automatically plot, once the new high/low is created, these fib lines. (From bullish/bearish order block to new high/low) Based on the pic provided, i'm close, but the buy and sell signals are not showing up. I don't even believe the fair value gaps are highlighting as they should. Hope this makes sense. Pic provided and any help would be GREATLY appreciated...Oh! Would also like the script to adapt to each timeframe if at all possible...

View attachment 23890View attachment 23891
Code:
#Golden Zone Strategy (Created using ChatGPT)
# This script highlights the candles that have detected imbalances (Fair Value Gaps),
# plots Golden Zone Fibonacci levels (71% and 79%), and includes Take Profit (at 100% Fibonacci)
# and Stop Loss (at 0% Fibonacci) levels.
# The Fibonacci levels are calculated dynamically based on the highest high and lowest low of the most recent price action.

# Define the lookback period for high/low calculation
input lookbackBars = 50;

# Calculate the highest high and lowest low over the lookback period
def highestHigh = highest(high, lookbackBars);
def lowestLow = lowest(low, lookbackBars);

# Calculate Fibonacci retracement levels (71% and 79%)
def fib0 = lowestLow;
def fib100 = highestHigh;
def fib71 = fib0 + 0.71 * (fib100 - fib0); # 71% retracement level
def fib79 = fib0 + 0.79 * (fib100 - fib0); # 79% retracement level

# Detect Imbalances (Fair Value Gap)
def imbalanceUp = high[1] < low; # Bullish imbalance (gap down)
def imbalanceDown = low[1] > high; # Bearish imbalance (gap up)

# Market Structure Breaks (Swing High / Swing Low Breaks)
# Market structure break for bullish trend: Current price must break above the previous swing high
def breakOfStructureUp = close > highestHigh[1]; # Break above previous swing high

# Market structure break for bearish trend: Current price must break below the previous swing low
def breakOfStructureDown = close < lowestLow[1]; # Break below previous swing low

# Condition 1: Break of structure (for both bullish and bearish)
def breakStructure = breakOfStructureUp or breakOfStructureDown;

# Condition 2: Imbalance (gap up or gap down)
def gapUp = low[1] > high; # Bearish imbalance (gap up)
def gapDown = high[1] < low; # Bullish imbalance (gap down)

# Condition 3: Retracement to Golden Zone (between 71% and 79% Fibonacci)
def withinGoldenZone = close >= fib71 and close <= fib79;

# Combine all conditions
def buySignalCondition = breakOfStructureUp and gapDown and withinGoldenZone; # Buy signal
def sellSignalCondition = breakOfStructureDown and gapUp and withinGoldenZone; # Sell signal

# Plot Fibonacci retracement levels as horizontal lines (always visible)
plot fib71Line = fib71;
plot fib79Line = fib79;

# Set appearance of the Fibonacci levels
fib71Line.SetDefaultColor(Color.CYAN);
fib79Line.SetDefaultColor(Color.GREEN);

# Highlight the Golden Zone area (between 71% and 79% retracement)
AddCloud(fib71Line, fib79Line, Color.YELLOW, Color.YELLOW);

# Highlight Take Profit (100% Fibonacci) and Stop Loss (0% Fibonacci) levels
plot takeProfitLine = fib100; # Take Profit at 100% Fibonacci (Swing High)
plot stopLossLine = fib0; # Stop Loss at 0% Fibonacci (Swing Low)

# Set the appearance of Take Profit and Stop Loss lines
takeProfitLine.SetDefaultColor(Color.BLUE);
stopLossLine.SetDefaultColor(Color.RED);

# Set line weight for better visibility
fib71Line.SetLineWeight(2);
fib79Line.SetLineWeight(2);
takeProfitLine.SetLineWeight(2);
stopLossLine.SetLineWeight(2);

# Optional: Plot the swing high and low for reference
plot swingHighLine = highestHigh;
plot swingLowLine = lowestLow;

swingHighLine.SetDefaultColor(Color.RED);
swingLowLine.SetDefaultColor(Color.RED);

# Set line weight for better visibility
swingHighLine.SetLineWeight(1);
swingLowLine.SetLineWeight(1);

# Highlight candles with imbalances (gap up or gap down)
# Bullish imbalance (gap down) — green candle
AssignPriceColor(if buySignalCondition then Color.GREEN else Color.CURRENT);

# Bearish imbalance (gap up) — red candle
AssignPriceColor(if sellSignalCondition then Color.RED else Color.CURRENT);

# Add Buy and Sell signals as arrows or labels
plot buySignalArrow = if buySignalCondition then low - 0.1 else Double.NaN;
plot sellSignalArrow = if sellSignalCondition then high + 0.1 else Double.NaN;

buySignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buySignalArrow.SetDefaultColor(Color.GREEN);
buySignalArrow.SetLineWeight(3);

sellSignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sellSignalArrow.SetDefaultColor(Color.RED);
sellSignalArrow.SetLineWeight(3);
maybe this is what you are looking for? I did not make the FIBS dynamic not exactly sure if that is what you wanted: https://tos.mx/!VxDxRhv2
1737545176714.png
 
Can someone help me with this script? This is as much as I could get figured out using chatgpt. The conditions are as follows: First, I need to see a break in market structure. Second is an imbalance has been created. Then, i'm looking for price to retrace back into the 71% and 79% fib level (my buy and or sell signal). Stop loss is the 0% fib level. Take profit is the 100% fib level. Was really looking for the script to automatically plot, once the new high/low is created, these fib lines. (From bullish/bearish order block to new high/low) Based on the pic provided, i'm close, but the buy and sell signals are not showing up. I don't even believe the fair value gaps are highlighting as they should. Hope this makes sense. Pic provided and any help would be GREATLY appreciated...Oh! Would also like the script to adapt to each timeframe if at all possible...

View attachment 23890View attachment 23891
Code:
#Golden Zone Strategy (Created using ChatGPT)
# This script highlights the candles that have detected imbalances (Fair Value Gaps),
# plots Golden Zone Fibonacci levels (71% and 79%), and includes Take Profit (at 100% Fibonacci)
# and Stop Loss (at 0% Fibonacci) levels.
# The Fibonacci levels are calculated dynamically based on the highest high and lowest low of the most recent price action.

# Define the lookback period for high/low calculation
input lookbackBars = 50;

# Calculate the highest high and lowest low over the lookback period
def highestHigh = highest(high, lookbackBars);
def lowestLow = lowest(low, lookbackBars);

# Calculate Fibonacci retracement levels (71% and 79%)
def fib0 = lowestLow;
def fib100 = highestHigh;
def fib71 = fib0 + 0.71 * (fib100 - fib0); # 71% retracement level
def fib79 = fib0 + 0.79 * (fib100 - fib0); # 79% retracement level

# Detect Imbalances (Fair Value Gap)
def imbalanceUp = high[1] < low; # Bullish imbalance (gap down)
def imbalanceDown = low[1] > high; # Bearish imbalance (gap up)

# Market Structure Breaks (Swing High / Swing Low Breaks)
# Market structure break for bullish trend: Current price must break above the previous swing high
def breakOfStructureUp = close > highestHigh[1]; # Break above previous swing high

# Market structure break for bearish trend: Current price must break below the previous swing low
def breakOfStructureDown = close < lowestLow[1]; # Break below previous swing low

# Condition 1: Break of structure (for both bullish and bearish)
def breakStructure = breakOfStructureUp or breakOfStructureDown;

# Condition 2: Imbalance (gap up or gap down)
def gapUp = low[1] > high; # Bearish imbalance (gap up)
def gapDown = high[1] < low; # Bullish imbalance (gap down)

# Condition 3: Retracement to Golden Zone (between 71% and 79% Fibonacci)
def withinGoldenZone = close >= fib71 and close <= fib79;

# Combine all conditions
def buySignalCondition = breakOfStructureUp and gapDown and withinGoldenZone; # Buy signal
def sellSignalCondition = breakOfStructureDown and gapUp and withinGoldenZone; # Sell signal

# Plot Fibonacci retracement levels as horizontal lines (always visible)
plot fib71Line = fib71;
plot fib79Line = fib79;

# Set appearance of the Fibonacci levels
fib71Line.SetDefaultColor(Color.CYAN);
fib79Line.SetDefaultColor(Color.GREEN);

# Highlight the Golden Zone area (between 71% and 79% retracement)
AddCloud(fib71Line, fib79Line, Color.YELLOW, Color.YELLOW);

# Highlight Take Profit (100% Fibonacci) and Stop Loss (0% Fibonacci) levels
plot takeProfitLine = fib100; # Take Profit at 100% Fibonacci (Swing High)
plot stopLossLine = fib0; # Stop Loss at 0% Fibonacci (Swing Low)

# Set the appearance of Take Profit and Stop Loss lines
takeProfitLine.SetDefaultColor(Color.BLUE);
stopLossLine.SetDefaultColor(Color.RED);

# Set line weight for better visibility
fib71Line.SetLineWeight(2);
fib79Line.SetLineWeight(2);
takeProfitLine.SetLineWeight(2);
stopLossLine.SetLineWeight(2);

# Optional: Plot the swing high and low for reference
plot swingHighLine = highestHigh;
plot swingLowLine = lowestLow;

swingHighLine.SetDefaultColor(Color.RED);
swingLowLine.SetDefaultColor(Color.RED);

# Set line weight for better visibility
swingHighLine.SetLineWeight(1);
swingLowLine.SetLineWeight(1);

# Highlight candles with imbalances (gap up or gap down)
# Bullish imbalance (gap down) — green candle
AssignPriceColor(if buySignalCondition then Color.GREEN else Color.CURRENT);

# Bearish imbalance (gap up) — red candle
AssignPriceColor(if sellSignalCondition then Color.RED else Color.CURRENT);

# Add Buy and Sell signals as arrows or labels
plot buySignalArrow = if buySignalCondition then low - 0.1 else Double.NaN;
plot sellSignalArrow = if sellSignalCondition then high + 0.1 else Double.NaN;

buySignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buySignalArrow.SetDefaultColor(Color.GREEN);
buySignalArrow.SetLineWeight(3);

sellSignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sellSignalArrow.SetDefaultColor(Color.RED);
sellSignalArrow.SetLineWeight(3);
Hey John, I worked it several different ways I just could not see any added value but it's not my eyes that are important. the buy and sell areas can be an issue on higher volatility and high liquidity stocks, and its a pretty good lagging indicator. I paired it with some volume and the Ichi Moku but there are better signaling indicators in here.
1737547753561.png
 
Hey John, I worked it several different ways I just could not see any added value but it's not my eyes that are important. the buy and sell areas can be an issue on higher volatility and high liquidity stocks, and its a pretty good lagging indicator. I paired it with some volume and the Ichi Moku but there are better signaling indicators in here. View attachment 23940
Attached is a pic of what I was looking to somewhat accomplish. Looking for the study to automatically plot the current trading range, via the fib retracement levels (pictured) once there has been a break of structure (bullish or bearish), an imbalance has been created, and a low/high has been formed. As well as automatically adapt to price action should there be some consolidation and another low/high has been formed. A continuous adaptation until a range has been solidified. Should there be a significant retracement back toward my 71%/79% poi (gz in the pic), the fib levels will lock into place. Would also like it to adapt to any time i'd like to apply it to.
 

Attachments

  • GZ Study.JPG
    GZ Study.JPG
    464 KB · Views: 60
Hey John, I worked it several different ways I just could not see any added value but it's not my eyes that are important. the buy and sell areas can be an issue on higher volatility and high liquidity stocks, and its a pretty good lagging indicator. I paired it with some volume and the Ichi Moku but there are better signaling indicators in here. View attachment 23940
I do GREATLY appreciate you taking the time to give it a go!! I replied with a pic to your first response. Would like it to look very similar, if at all possible, to cut back on the price action overlay...
 
Last edited:

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