Repaints Fair Value Gap (FVG) For ThinkOrSwim

Repaints
This is great, is there any way to include possibly a gray dashed 50% ?
I would check out Samer800's post above, it has CE built into it.

Otherwise

Add this under the section that Plots the FVG values.

Def CEDown = fvgBearMem1 - ((fvgBearMem1 - fvgBearMem2)/2);

Def CEUp = fvgBullMem1 - ((fvgBullMem1 - fvgBullMem2)/2);

plot CEBear = CEDown;
CEBEAR.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
CEBEAR.SetLineWeight(1);
CEBEAR.SetdefaultColor(Color.gray);
plot CEBull = CEup;
CEBull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
CEBull.SetLineWeight(1);
CEBull.SetdefaultColor(Color.gray);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I want to draw a zone for the GAP between the high value H and Low L. Instead of just drawing a horizontal line, highlight that price area. Can anyone can help me?

The below code is drawing the FVG with the high value H and Low L. I want to highlight this instead of drawing the HORIZONTAL line

Code:
input OrMeanS  = 0930.0; #hint OrMeanS: Begin Mean Period.
input ShowTodayOnly = {"No", default "Yes"};   
  def s = ShowTodayOnly;
  def today = if s == 0
              or getDay() == getLastDay() and
                 secondsFromTime(OrMeanS) >= 0
              then 1
              else 0;

input timeFrame = AggregationPeriod.DAY;

def lowN3 = low(period = timeFrame);

def highN1 = high(period = timeFrame)[2];

def priceIsIncreasing = lowN3 > highN1;
def fvgIncrease = if priceIsIncreasing then lowN3 - highN1 else Double.NaN;

Plot H = if today and priceIsIncreasing then lowN3 else 0 ;

Plot L =  if today and priceIsIncreasing then highN1 else 0 ;

alert(priceIsIncreasing, "", Alert.Bar, Sound.Bell);

AddLabel(yes, " H: " + round(H,2) +" L: "+ round(L,2),  if today and priceIsIncreasing then  Color.GREEN  else Color.white );

H.setpaintingStrategy(paintingStrategy.HORIZONTAL);
H.setdefaultColor(color.green);
H.HideBubble();
H.HideTitle();

L.setpaintingStrategy(paintingStrategy.HORIZONTAL);
L.setdefaultColor(color.red);
L.HideBubble();
L.HideTitle();
 
Last edited:
I want to draw a zone for the GAP between the high value H and Low L. Instead of just drawing a horizontal line, highlight that price area. Can anyone can help me?

The below code is drawing the FVG with the high value H and Low L. I want to highlight this instead of drawing the HORIZONTAL line

Code:
input OrMeanS  = 0930.0; #hint OrMeanS: Begin Mean Period.
input ShowTodayOnly = {"No", default "Yes"}; 
  def s = ShowTodayOnly;
  def today = if s == 0
              or getDay() == getLastDay() and
                 secondsFromTime(OrMeanS) >= 0
              then 1
              else 0;

input timeFrame = AggregationPeriod.DAY;

def lowN3 = low(period = timeFrame);

def highN1 = high(period = timeFrame)[2];

def priceIsIncreasing = lowN3 > highN1;
def fvgIncrease = if priceIsIncreasing then lowN3 - highN1 else Double.NaN;

Plot H = if today and priceIsIncreasing then lowN3 else 0 ;

Plot L =  if today and priceIsIncreasing then highN1 else 0 ;

alert(priceIsIncreasing, "", Alert.Bar, Sound.Bell);

AddLabel(yes, " H: " + round(H,2) +" L: "+ round(L,2),  if today and priceIsIncreasing then  Color.GREEN  else Color.white );

H.setpaintingStrategy(paintingStrategy.HORIZONTAL);
H.setdefaultColor(color.green);
H.HideBubble();
H.HideTitle();

L.setpaintingStrategy(paintingStrategy.HORIZONTAL);
L.setdefaultColor(color.red);
L.HideBubble();
L.HideTitle();

I modified your script by deleting what appeared to be unnecessary code and added a cloud.

The modifications: H and L were extended through recursive, plotted as H1 and L1, then hidden and used in the addcloud. H1 and L1 were needed as addcloud does not accept recursives.

Screenshot 2024-02-11 075851.png
Code:
input OrMeanS  = 0930.0; #hint OrMeanS: Begin Mean Period.

input timeFrame = AggregationPeriod.DAY;

def lowN3 = low(period = timeFrame);

def highN1 = high(period = timeFrame)[2];

def priceIsIncreasing = lowN3 > highN1;
def fvgIncrease = if priceIsIncreasing then lowN3 - highN1 else Double.NaN;

def H = if priceIsIncreasing then lowN3 else H[1];
def L =  if  priceIsIncreasing then highN1 else L[1] ;

alert(priceIsIncreasing, "", Alert.Bar, Sound.Bell);

AddLabel(yes, " H: " + round(H,2) +" L: "+ round(L,2),  if priceIsIncreasing then  Color.GREEN  else Color.white );

plot H1=H;
plot L1=L;
H1.sethiding(yes);
L1.sethiding(yes);
addcloud(H1,L1, color1 = Color.LIGHT_GREEN, color2 = Color.LIGHT_GREEN);

;
 
I modified your script by deleting what appeared to be unnecessary code and added a cloud.

The modifications: H and L were extended through recursive, plotted as H1 and L1, then hidden and used in the addcloud. H1 and L1 were needed as addcloud does not accept recursives.
you are an expert. Thank you very much. Here I have added the part to calculate FVG down in the code. Please give me your opinion.

CODE:
Code:
input timeFrame = AggregationPeriod.DAY;

# Get the low of the last 3 periods
def lowN3 = low(period = timeFrame);

# Get the high of the first period 2 periods ago
def highN1 = high(period = timeFrame)[2];

# Check if the price is increasing
def priceIsIncreasing = lowN3 > highN1;

# Calculate the Fractal Vertical Gap (FVG) for increasing prices
def fvgIncrease = if priceIsIncreasing then lowN3 - highN1 else Double.NaN;

# Get the high of the last 3 periods
def highN3 = high(period = timeFrame);

# Get the low of the first period 2 periods ago
def lowN1 = low(period = timeFrame)[2];

# Check if the price is decreasing
def priceIsDecreasing = lowN1 > highN3;

# Calculate the Fractal Vertical Gap (FVG) for decreasing prices
def fvgDecrease = if priceIsDecreasing then lowN1 - highN3 else Double.NaN;

# Determine the highest high (H) and lowest low (L) among the given conditions
def H = if priceIsIncreasing then lowN3 else if priceIsDecreasing then lowN1 else H[1];
def L = if priceIsIncreasing then highN1 else if priceIsDecreasing then highN3 else L[1];

# Alert if the price is increasing or decreasing
alert(priceIsIncreasing or priceIsDecreasing, "", Alert.Bar, Sound.Bell);

# Add labels to display H and L
AddLabel(yes, " H: " + round(H,2) +" L: "+ round(L,2), if priceIsIncreasing then Color.GREEN else if priceIsDecreasing then Color.red else Color.white);

# Plot H and L
plot H1 = H;
plot L1 = L;
H1.SetHiding(yes);
L1.SetHiding(yes);

# Add cloud to highlight the area between H and L
AddCloud(H1, L1, color1 = Color.LIGHT_GREEN, color2 = Color.LIGHT_GREEN);
 
you are an expert. Thank you very much. Here I have added the part to calculate FVG down in the code. Please give me your opinion.

CODE:
Code:
input timeFrame = AggregationPeriod.DAY;

# Get the low of the last 3 periods
def lowN3 = low(period = timeFrame);

# Get the high of the first period 2 periods ago
def highN1 = high(period = timeFrame)[2];

# Check if the price is increasing
def priceIsIncreasing = lowN3 > highN1;

# Calculate the Fractal Vertical Gap (FVG) for increasing prices
def fvgIncrease = if priceIsIncreasing then lowN3 - highN1 else Double.NaN;

# Get the high of the last 3 periods
def highN3 = high(period = timeFrame);

# Get the low of the first period 2 periods ago
def lowN1 = low(period = timeFrame)[2];

# Check if the price is decreasing
def priceIsDecreasing = lowN1 > highN3;

# Calculate the Fractal Vertical Gap (FVG) for decreasing prices
def fvgDecrease = if priceIsDecreasing then lowN1 - highN3 else Double.NaN;

# Determine the highest high (H) and lowest low (L) among the given conditions
def H = if priceIsIncreasing then lowN3 else if priceIsDecreasing then lowN1 else H[1];
def L = if priceIsIncreasing then highN1 else if priceIsDecreasing then highN3 else L[1];

# Alert if the price is increasing or decreasing
alert(priceIsIncreasing or priceIsDecreasing, "", Alert.Bar, Sound.Bell);

# Add labels to display H and L
AddLabel(yes, " H: " + round(H,2) +" L: "+ round(L,2), if priceIsIncreasing then Color.GREEN else if priceIsDecreasing then Color.red else Color.white);

# Plot H and L
plot H1 = H;
plot L1 = L;
H1.SetHiding(yes);
L1.SetHiding(yes);

# Add cloud to highlight the area between H and L
AddCloud(H1, L1, color1 = Color.LIGHT_GREEN, color2 = Color.LIGHT_GREEN);

Since H and L were used to define either condition (isincreasing and isdecreasing)). 2 clouds were needed to get the separate colors for each condition.

Screenshot 2024-02-12 061826.png
Code:
input timeFrame = AggregationPeriod.DAY;

# Get the low of the last 3 periods
def lowN3 = low(period = timeFrame);

# Get the high of the first period 2 periods ago
def highN1 = high(period = timeFrame)[2];

# Check if the price is increasing
def priceIsIncreasing = lowN3 > highN1;

# Calculate the Fractal Vertical Gap (FVG) for increasing prices
def fvgIncrease = if priceIsIncreasing then lowN3 - highN1 else Double.NaN;

# Get the high of the last 3 periods
def highN3 = high(period = timeFrame);

# Get the low of the first period 2 periods ago
def lowN1 = low(period = timeFrame)[2];

# Check if the price is decreasing
def priceIsDecreasing = lowN1 > highN3;

# Calculate the Fractal Vertical Gap (FVG) for decreasing prices
def fvgDecrease = if priceIsDecreasing then lowN1 - highN3 else Double.NaN;

# Determine the highest high (H) and lowest low (L) among the given conditions
def H = if priceIsIncreasing then lowN3 else if priceIsDecreasing then lowN1 else H[1];
def L = if priceIsIncreasing then highN1 else if priceIsDecreasing then highN3 else L[1];

# Alert if the price is increasing or decreasing
alert(priceIsIncreasing or priceIsDecreasing, "", Alert.Bar, Sound.Bell);

# Add labels to display H and L
AddLabel(yes, " H: " + round(H,2) +" L: "+ round(L,2), if priceIsIncreasing then Color.GREEN else if priceIsDecreasing then Color.red else Color.white);

# Plot H and L
plot H1 = H;
plot L1 = L;
H1.SetHiding(yes);
L1.SetHiding(yes);

# Add cloud to highlight the area between H and L
AddCloud(if priceisincreasing then H1 else double.nan, L1, color1 = Color.LIGHT_GREEN, color2 = Color.LIGHT_GREEN);
AddCloud(if priceisdecreasing then H1 else double.nan, L1, color1 = Color.LIGHT_red, color2 = Color.LIGHT_red);

#
 
Since H and L were used to define either condition (isincreasing and isdecreasing)). 2 clouds were needed to get the separate colors for each condition.

I revised the above code to allow the clouds to extend.

Screenshot 2024-02-12 071823.png
Code:
input timeFrame = AggregationPeriod.DAY;

# Get the low of the last 3 periods
def lowN3 = low(period = timeFrame);

# Get the high of the first period 2 periods ago
def highN1 = high(period = timeFrame)[2];

# Check if the price is increasing
def priceIsIncreasing = lowN3 > highN1;

# Calculate the Fractal Vertical Gap (FVG) for increasing prices
def fvgIncrease = if priceIsIncreasing then lowN3 - highN1 else Double.NaN;

# Get the high of the last 3 periods
def highN3 = high(period = timeFrame);

# Get the low of the first period 2 periods ago
def lowN1 = low(period = timeFrame)[2];

# Check if the price is decreasing
def priceIsDecreasing = lowN1 > highN3;

# Calculate the Fractal Vertical Gap (FVG) for decreasing prices
def fvgDecrease = if priceIsDecreasing then lowN1 - highN3 else Double.NaN;

# Determine the highest high (H) and lowest low (L) among the given conditions
def H = if priceIsIncreasing then lowN3 else H[1];
def L = if priceIsIncreasing then highN1 else L[1];
def HD = if priceIsDecreasing then lowN1 else HD[1];
def LD = if priceIsDecreasing then highN3 else LD[1];

# Alert if the price is increasing or decreasing
Alert(priceIsIncreasing or priceIsDecreasing, "", Alert.BAR, Sound.Bell);

# Add labels to display H and L
AddLabel(yes, " H: " + Round(H, 2) + " L: " + Round(L, 2), if priceIsIncreasing then Color.GREEN else if priceIsDecreasing then Color.RED else Color.WHITE);

# Plot H and L
plot H1 = H;
plot L1 = L;
H1.SetHiding(yes);
L1.SetHiding(yes);
plot H2 = HD;
plot L2 = LD;
H2.SetHiding(yes);
L2.SetHiding(yes);

# Add cloud to highlight the area between H and L
AddCloud(H1, L1, color1 = Color.LIGHT_GREEN, color2 = Color.LIGHT_GREEN);
AddCloud(H2, L2, color1 = Color.LIGHT_RED, color2 = Color.LIGHT_RED);

#
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
238 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