Weekly break out Fib extension script

imran79

New member
Hello, I am a new member here. Can anyone write me a script for a weekly high and low breakout of the last weekly candle to set targets of 1.27, 0.618, 200, and 261.7 fib ext.? If I can get an alert that a new high was made, then I can follow the trade from there.
I appreciate it.

Thank you.
Imran
 
Solution
Hello, I am a new member here. Can anyone write me a script for a weekly high and low breakout of the last weekly candle to set targets of 1.27, 0.618, 200, and 261.7 fib ext.? If I can get an alert that a new high was made, then I can follow the trade from there.
I appreciate it.

Thank you.
Imran

is this what you are looking for ?
find high/low of previous week and plot lines on current week. ( dashed )
then using the range between the lines, times a factor, and set as 100% , draw lines at fib levels.
. 0.618, 1.27, 2.00, 2.617
sound an alert if a line is crossed.


Code:
#Weekly_breakout_Fib_ext
#https://usethinkscript.com/threads/weekly-break-out-fib-extension-script.20507/
#Weekly break out Fib extension script

def na =...
Hello, I am a new member here. Can anyone write me a script for a weekly high and low breakout of the last weekly candle to set targets of 1.27, 0.618, 200, and 261.7 fib ext.? If I can get an alert that a new high was made, then I can follow the trade from there.
I appreciate it.

Thank you.
Imran

is this what you are looking for ?
find high/low of previous week and plot lines on current week. ( dashed )
then using the range between the lines, times a factor, and set as 100% , draw lines at fib levels.
. 0.618, 1.27, 2.00, 2.617
sound an alert if a line is crossed.


Code:
#Weekly_breakout_Fib_ext
#https://usethinkscript.com/threads/weekly-break-out-fib-extension-script.20507/
#Weekly break out Fib extension script

def na = double.nan;
def bn = barnumber();

input agg = aggregationperiod.week;
def hi = high(period=agg);
def lo = low(period=agg);

input week_rng_factor = 1.0;
def rng = (hi[1]-lo[1]);
def midpr = rng/2 + lo[1];
def rngf = rng * week_rng_factor;
def hif = midpr + (rngf/2);
def lof = midpr - (rngf/2);


#def isprevweek = (!isnan(close(period=agg)[-1]) and isnan(close(period=agg)[-2]));
# only true on 1st bar??
#def islastweek = getweek() == getlastweek();
# this weeks
def iscurrentweek = (!isnan(close(period=agg)[0]) and isnan(close(period=agg)[-1]));

# plot lines on 2nd last week
#plot zhi = if iscurrentweek then hi[1] else na;
#plot zlo = if iscurrentweek then lo[1] else na;
plot zhi = if iscurrentweek then hif else na;
plot zlo = if iscurrentweek then lof else na;
#zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zhi.SetDefaultColor(Color.light_gray);
zhi.SetStyle(Curve.MEDIUM_DASH);
zhi.setlineweight(2);
#zhi.hidebubble();
zlo.SetDefaultColor(Color.light_gray);
zlo.SetStyle(Curve.MEDIUM_DASH);
zlo.setlineweight(2);
#zlo.hidebubble();

# calc 100% based on range of prev week x factor
#   0.618, 1.27, 2.00, 2.617 ,  fib ext.
def f1 = 0.618;
def f2 = 1.27;
def f3 = 2.0;
def f4 = 2.617;

plot h1 = zlo + (f1*rngf);
plot h2 = zlo + (f2*rngf);
plot h3 = zlo + (f3*rngf);
plot h4 = zlo + (f4*rngf);
plot l1 = zhi - (f1*rngf);
plot l2 = zhi - (f2*rngf);
plot l3 = zhi - (f3*rngf);
plot l4 = zhi - (f4*rngf);
h1.SetDefaultColor(Color.magenta);
h2.SetDefaultColor(Color.green);
h3.SetDefaultColor(Color.blue);
h4.SetDefaultColor(Color.orange);
l1.SetDefaultColor(Color.magenta);
l2.SetDefaultColor(Color.green);
l3.SetDefaultColor(Color.blue);
l4.SetDefaultColor(Color.orange);

def xup = close crosses zhi
or close crosses h1
or close crosses h2
or close crosses h3
or close crosses h4;

def xdwn = close crosses zlo
or close crosses l1
or close crosses l2
or close crosses l3
or close crosses l4;

alert(xup, "crossed upper line" ,alert.BAR, sound.DING);
alert(xdwn, "crossed lower line" ,alert.BAR, sound.bell);
#
 

Attachments

  • img1.JPG
    img1.JPG
    44.2 KB · Views: 24
Solution

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