Fibonacci Progression with Breaks [LUX] For ThinkOrSwim

@MichaelR
TOS can't handle arrays. However, below is my best conversion. try it.

CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International
#// © LuxAlgo
#https://www.tradingview.com/script/xyCba4gl-Fibonacci-Progression-with-Breaks-LUX/
#indicator("Fibonacci Progression With Breaks [LuxAlgo]",
# Converted by Sam4Cok@Samer800 - 10/2022 "Not exact conversion"
input src = close;
input ShowBubble = yes;
input ShowSequence = no;
input method = {default ATR, Manual};#,inline='inline1')
input size   = 1.0;#(1.,'',inline='inline1')
input max    = 3;#(3,'Sequence Length')
#//----
def na= Double.NaN;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if isNaN(data) then repl else data;
    plot return = ret_val;
}

#var fib = array.from(1,1)
def dist; def avg; def fib_n; def fib_n1;

#//----

if method == method.ATR {
    dist = fold i = 1 to max with p do
           ATR(length=200) * size * GetValue(fib_n, if((i-1)==0,1,i));
} else {
    dist = fold j = 1 to max with q do
        size * (GetValue(fib_n, if((j-1)==0,1,j)));#+ GetValue(fib_n, if((j-1)==0,1,j-1)));
}

fib_n1 = if AbsValue(src-avg[1]) > dist then fib_n1[1]+1 else fib_n[1];
fib_n = if fib_n[1] > max+1 then 1 else fib_n1;
avg = nz(if fib_n1 > max+1 then src else avg[1],src);


def buy  = avg > avg[1];
def sell = avg < avg[1];
def os = if buy then 1 else if sell then 0 else os[1];

def tp = if avg != avg[1] then na else if os == 1 then avg + dist else avg - dist;
def sl = if avg != avg[1] then na else if os == 0 then avg + dist else avg - dist;

#//----
def css = if os == 1 then 1 else 0;
def "0" = ohlc4;
plot "1" = avg;
"1".SetHiding(yes);
AddCloud(if css then "0" else na,"1",Color.DARK_GREEN,Color.DARK_GREEN);
AddCloud(if !css then "0" else na,"1",Color.DARK_RED,Color.DARK_RED);
#//----
AddChartBubble(ShowBubble and buy, low,"B", Color.GREEN,no);
AddChartBubble(ShowBubble and sell,high,"S", Color.RED,yes);

AddChartBubble(ShowSequence and fib_n > fib_n[1] and os == 1 and src > avg, low,fib_n-1, Color.DARK_GREEN,no);
AddChartBubble(ShowSequence and fib_n > fib_n[1] and os == 1 and src < avg, high,fib_n-1, Color.DARK_RED,YES);
AddChartBubble(ShowSequence and fib_n > fib_n[1] and os == 0 and src < avg, low,fib_n-1, Color.DARK_GREEN,no);
AddChartBubble(ShowSequence and fib_n > fib_n[1] and os == 0 and src > avg, high,fib_n-1, Color.DARK_RED,YES);

plot Target = tp;   # 'Target'
Target.SetDefaultColor(Color.GREEN);

plot Stop = sl;     # 'Stop'
Stop.SetDefaultColor(Color.RED);


#----END CODE---
 
Last edited by a moderator:

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