Fibonacci retracement on 30 minute bar

hectorgasm

Member
Hello, would someone help me plot a fibonacci 50% retracement when the following condition is met?

close < close[20]
 
Hello, would someone help me plot a fibonacci 50% retracement when the following condition is met?

close < close[20]

Not exactly sure what you expected, but maybe this will give you some ideas of one way to view your request. A little more description and a chart image mocked up will likely get more responses..

This excludes the current bar and when the condition is met, it will find the highs and lows to compute the retrace. The plot of these can be hidden.

A vertical line plots at the lookback point and a label will be green if the condition is met and gray otherwise.
Screenshot 2023-07-08 160316.png

Code:
input lookback = 20;
input vertical = yes;
input hl_plots = yes;
input label    = yes;

def bn        = BarNumber();
def lastbar   = HighestAll(if !IsNaN(close) then bn else 0);
def c         = if bn == lastbar then close else c[1];
def hh        = if IsNaN(c) then hh[1]
                else if bn == (lastbar - lookback) then high
                else if bn < (lastbar - 1 ) then Max(high, hh[1])
                else hh[1];

def ll        = if IsNaN(close) then ll[1]
                else if bn == (lastbar - lookback) then low
                else if bn < (lastbar - 1 ) then Min(low, ll[1])
                else ll[1];
def retrace50 = (hh + ll) / 2;

plot lookbackhigh = if bn >= lastbar and c < close[lookback] then hh
                    else Double.NaN;
plot lookbacklow  = if bn >= lastbar and c < close[lookback] then ll
                    else Double.NaN;
plot fib50        = if bn >= lastbar and c < close[lookback] then retrace50
                    else Double.NaN;
lookbackhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lookbacklow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib50.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lookbackhigh.SetHiding(!hl_plots);
lookbacklow.SetHiding(!hl_plots);

AddLabel(label, " Close: " + c + (if c < close[lookback] then "  <  " else "  >=  ") + "C[" + lookback + "]: " + close[lookback] , if c < close[lookback] then Color.LIGHT_GREEN else Color.GRAY);
;
AddVerticalLine(vertical and bn == (lastbar - lookback), "", Color.WHITE);
 

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