Fibonacci Retracement Accuracy For ThinkOrSwim

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

Can someone help me convert a tradingview indicator/script into a ThinkorSwim custom script?

The name of the trading view indicator is called "FIBONNACI RETRACEMENT ACCURACY" by FelixBrusch
https://www.tradingview.com/script/zPqlhhdD-Fibonacci-Retracement-Accuracy/

Can it be converted to Tos?


Thank you.
Cheers.
Chris
check the below:
CSS:
#//@version=3
#study("Reversal","Fibbonaci Accuracy",overlay=false)
# Converted by sam4Cok@Samer800    - 01/2024
declare lower;

input trend_candles = 5;#,"#Trend Candles")
input lookbackPeriod = 1000;

def na = Double.NaN;
def last = isNaN(close);
def fib0 = lowest(low, lookbackPeriod);    # "#FibMin"
def fib100 = highest(high, lookbackPeriod);# "FibMax"
def fibRange = (fib100 - fib0);


script closest_fib {
    input x = close;
    input fib0 = low;
    input fib100 = high;
    def fibRange = (fib100 - fib0);
    def fib23 = fib0 + fibRange * 0.236;
    def fib38 = fib0 + fibRange * 0.382;
    def fib50 = fib0 + fibRange * 0.50;
    def fib61 = fib0 + fibRange * 0.618;
    def fib78 = fib0 + fibRange * 0.786;
    def closest_fib = if AbsValue(fib0 - x) < AbsValue(fib23 - x) then fib0 else
                      if AbsValue(fib23 - x) < AbsValue(fib38 - x) then fib23 else
                      if AbsValue(fib38 - x) < AbsValue(fib50 - x) then fib38 else
                      if AbsValue(fib50 - x) < AbsValue(fib61 - x) then fib50 else
                      if AbsValue(fib61 - x) < AbsValue(fib78 - x) then fib61 else
                      if AbsValue(fib78 - x) < AbsValue(fib100 - x) then fib78 else fib100;
    plot out = closest_fib;
}
Script Pivot {
input series    = close;
input leftBars  = 10;
input rightBars = 10;
input isHigh = yes;
    def na = Double.NaN;
    def HH = series == Highest(series, leftBars + 1);
    def LL = series == Lowest(series, leftBars + 1);
    def pivotRange = (leftBars + rightBars + 1);
    def leftEdgeValue = if series[pivotRange] == 0 then na else series[pivotRange];
    def pvtCond = !IsNaN(series) and leftBars > 0 and rightBars > 0 and !IsNaN(leftEdgeValue);
    def barIndexH = if pvtCond then
                    fold i = 1 to rightBars + 1 with p=1 while p do
                    series > GetValue(series, - i) else na;
    def barIndexL = if pvtCond then
                    fold j = 1 to rightBars + 1 with q=1 while q do
                    series < GetValue(series, - j) else na;
    def PivotPoint;
if isHigh {
    PivotPoint = if HH and barIndexH then series else na;
    } else {
    PivotPoint = if LL and barIndexL then series else na;
}
    plot pvt = if IsNaN(PivotPoint) then 0 else PivotPoint;
}

#// get Pivot High/Low
def last_high = pivot(high, trend_candles, trend_candles, yes);
def last_low  = pivot(low, trend_candles, trend_candles, no);

def rel_close = if last_high then high else if last_low then low else na;
def points_step = if (last_high or last_low) then rel_close else na;
def fobLevel = closest_fib(points_step, fib0, fib100);
def closest_steps = if (last_high or last_low) then fobLevel else na;
def pointsp = (points_step - fib0) * 100/fibRange;
def stepsp  = (closest_steps - fib0) * 100/fibRange;
def diffp = pointsp - stepsp;

plot diffPnt = diffp;
diffPnt.SetLineWeight(3);
diffPnt.SetPaintingStrategy(PaintingStrategy.SQUARES);
diffPnt.AssignValueColor(if last_low then Color.red else Color.GREEN);

plot zero = if last then na else 0;
zero.SetDefaultColor(Color.GRAY);

#-- END of CODE
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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