Auto Fibonacci Combo For ThinkOrSwim

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

Hello!
Does anyone have a conversion script for Auto Fibonacci Combo TV indicator ?

https://www.tradingview.com/script/IyzgHa86-Auto-Fibonacci-Combo/

@samer800,
If you have time, could you please assist me in converting this from Tradingview into Thinkscript? I would really appreciate it!

Thank you in advance!
try the below

CSS:
#// © informanerd
#study("Auto Fibonacci Combo", "Auto Fibo Combo", true)//, max_labels_count = 500, max_lines_count = 500)
# Converted and mod by Sam4Cok@Samer800    - 12/2023

#// inputs {
input maType = {"EMA", "HMA", "LSMA", default "MAEMA", "SMA", "TMA"};# "MA Type","Fibo Moving Averages Ribbon"
input movAvgSrc = close;#, "MA Source", group = "Fibo Moving Averages Ribbon")
input FiboLookbackPeriod = 424; #, "Fibo Lookback Period", minval = 1)
input FiboRetracement = {default "Show Lines", "Show Levels", "Show Lines & Levels", "Don't Show"};
input extendLines = no;
input smothType = {"EMA", "HMA", "LSMA", "MAEMA", "SMA", default "TMA"};# "Smoothing Type"
input smoothFR = yes;#(true, "Smooth", inline = "SM", group = "Smoothing")
input smoothLength = 1;#, "Length", minval = 0, group = "Smoothing")
input RibbonDisply = {default "Cloud", "Lines", "Cloud & Lines", "Don't Show"};

def na = Double.NaN;
def both = FiboRetracement == FiboRetracement."Show Lines & Levels";
def level = FiboRetracement == FiboRetracement."Show Levels";
def line = FiboRetracement == FiboRetracement."Show Lines";
def RibBoth = RibbonDisply == RibbonDisply."Cloud & Lines";
def RibCloud = RibbonDisply == RibbonDisply."Cloud";
def RibLines = RibbonDisply == RibbonDisply."Lines";
def showFE = both or line;
def showFR = both or level;
def showFMA = RibBoth or RibLines;
def showCloud = RibBoth or RibCloud;

#-- Color
DefineGlobalColor("dup", CreateColor(0, 78, 78));#CreateColor(10, 62, 92));
DefineGlobalColor("up0", CreateColor(0, 128, 0));
DefineGlobalColor("up1", CreateColor(28, 142, 0));
DefineGlobalColor("up2", CreateColor(57, 156, 0));
DefineGlobalColor("up3", CreateColor(85, 170, 0));
DefineGlobalColor("up4", CreateColor(113, 184, 0));
DefineGlobalColor("up5", CreateColor(142, 199, 0));
DefineGlobalColor("up6", CreateColor(170, 213, 0));
DefineGlobalColor("up7", CreateColor(198, 227, 0));
DefineGlobalColor("up8", CreateColor(227, 241, 0));
DefineGlobalColor("up9", CreateColor(255, 255, 0));
DefineGlobalColor("ddn", CreateColor(78, 0, 78));
DefineGlobalColor("dn0", CreateColor(255, 0, 0));
DefineGlobalColor("dn1", CreateColor(255, 28, 0));
DefineGlobalColor("dn2", CreateColor(255, 57, 0));
DefineGlobalColor("dn3", CreateColor(255, 85, 0));
DefineGlobalColor("dn4", CreateColor(255, 113, 0));
DefineGlobalColor("dn5", CreateColor(255, 142, 0));
DefineGlobalColor("dn6", CreateColor(255, 170, 0));
DefineGlobalColor("dn7", CreateColor(255, 198, 0));
DefineGlobalColor("dn8", CreateColor(255, 227, 0));
DefineGlobalColor("dn9", CreateColor(255, 255, 0));
script swma {
    input x = close;
    def swma = x[3] * 1 / 6 + x[2] * 2 / 6 + x[1] * 2 / 6 + x[0] * 1 / 6;
    plot out = swma;
}
script MAEMA {
    input src = close;
    input len = 21;
    def goldenRatio = (1 + Sqrt(5)) / 2;
    def momentumLen = Round(len / goldenRatio, 0);
    def momentum = src - src[momentumLen];
    def probLen = len / goldenRatio / goldenRatio;
    def probLenRound = Max(Round(probLen, 0), 1);
    def srcChange = src - src[1];
    def momChnage = momentum - momentum[momentumLen];
    def sumChnage = Sum(if srcChange > 0 then 1 else 0, probLenRound);
    def MAEMA = ExpAverage(src + (momentum + momChnage * 0.5) * sumChnage / probLen, len);
    plot out = MAEMA;
}
#// moving average function {
script ma {
    input type = "MAEMA";
    input src = close;
    input len = 21;
    def ma =
    if type == "EMA" then ExpAverage(src, len) else
    if type == "HMA" then HullMovingAvg(src, len) else
    if type == "LSMA" then Inertia(src, len) else
    if type == "MAEMA" then MAEMA(src, len) else
    if type == "SMA" then Average(src, len) else
    if type == "TMA" then swma(WMA(src, len)) else Average(src, len);
    plot out = ma;
}
def ratio1 = 23.6;
def ratio2 = 38.2;
def ratio3 = 50.0;
def ratio4 = 61.8;
def ratio5 = 78.6;
def ratio6 = 100.0;

def ma0 = ma(maType, movAvgSrc, 24);
def ma1 = ma(maType, movAvgSrc, 38);
def ma2 = ma(maType, movAvgSrc, 50);
def ma3 = ma(maType, movAvgSrc, 62);
def ma4 = ma(maType, movAvgSrc, 79);
def ma5 = ma(maType, movAvgSrc, 100);
def ma6 = ma(maType, movAvgSrc, 162);
def ma7 = ma(maType, movAvgSrc, 200);
def ma8 = ma(maType, movAvgSrc, 262);
def ma9 = ma(maType, movAvgSrc, 424);

#// fibo retracements {
def peak = Highest(high, FiboLookbackPeriod);
def trough = Lowest(low, FiboLookbackPeriod);
def highestBar = GetMaxValueOffset(high, FiboLookbackPeriod);
def lowestBar  = GetMinValueOffset(low, FiboLookbackPeriod);
def up = highestBar < lowestBar;

def range = peak - trough;

def descPrice1 = if up then peak - (range * ratio1) / 100 else na;
def descPrice2 = if up then peak - (range * ratio2) / 100 else na;
def descPrice3 = if up then peak - (range * ratio3) / 100 else na;
def descPrice4 = if up then peak - (range * ratio4) / 100 else na;
def descPrice5 = if up then peak - (range * ratio5) / 100 else na;
def ascPrice1  = if up then na else trough + (range * ratio1) / 100;
def ascPrice2  = if up then na else trough + (range * ratio2) / 100;
def ascPrice3  = if up then na else trough + (range * ratio3) / 100;
def ascPrice4  = if up then na else trough + (range * ratio4) / 100;
def ascPrice5  = if up then na else trough + (range * ratio5) / 100;

def hiSmooth = ma(smothType, peak, smoothLength);
def desSmooth1 = ma(smothType, descPrice1, smoothLength);
def ascSmooth1 = ma(smothType, ascPrice1, smoothLength);
def desSmooth2 = ma(smothType, descPrice2, smoothLength);
def ascSmooth2 = ma(smothType, ascPrice2, smoothLength);
def desSmooth3 = ma(smothType, descPrice3, smoothLength);
def ascSmooth3 = ma(smothType, ascPrice3, smoothLength);
def desSmooth4 = ma(smothType, descPrice4, smoothLength);
def ascSmooth4 = ma(smothType, ascPrice4, smoothLength);
def desSmooth5 = ma(smothType, descPrice5, smoothLength);
def ascSmooth5 = ma(smothType, ascPrice5, smoothLength);
def loSmooth = ma(smothType, trough, smoothLength);

def hiL0  = HighestAll(InertiaAll(peak, 2));
def desL1 = HighestAll(InertiaAll(descPrice1, 2));
def desL2 = HighestAll(InertiaAll(descPrice2, 2));
def desL4 = HighestAll(InertiaAll(descPrice4, 2));
def desL5 = HighestAll(InertiaAll(descPrice5, 2));
def midL0 = HighestAll(InertiaAll(descPrice3, 2));
def ascL1 = HighestAll(InertiaAll(ascPrice1, 2));
def ascL2 = HighestAll(InertiaAll(ascPrice2, 2));
def ascL4 = HighestAll(InertiaAll(ascPrice4, 2));
def ascL5 = HighestAll(InertiaAll(ascPrice5, 2));
def loL0  = HighestAll(InertiaAll(trough, 2));

def highLine = InertiaAll(hiL0, FiboLookbackPeriod);
def desLine1 = InertiaAll(desL1, FiboLookbackPeriod);
def desLine2 = InertiaAll(desL2, FiboLookbackPeriod);
def desLine4 = InertiaAll(desL4, FiboLookbackPeriod);
def desLine5 = InertiaAll(desL5, FiboLookbackPeriod);
def midLine0 = InertiaAll(midL0, FiboLookbackPeriod);
def ascLine1 = InertiaAll(ascL1, FiboLookbackPeriod);
def ascLine2 = InertiaAll(ascL2, FiboLookbackPeriod);
def ascLine4 = InertiaAll(ascL4, FiboLookbackPeriod);
def ascLine5 = InertiaAll(ascL5, FiboLookbackPeriod);
def loLine   = InertiaAll(loL0, FiboLookbackPeriod);

#// drawings {
plot hLine = if showFE then if extendLines then hiL0 else highLine else na;
plot desDn1 = if showFE then if extendLines then desL1 else desLine1 else na;
plot desDn2 = if showFE then if extendLines then desL2 else desLine2 else na;
plot desDn4 = if showFE then if extendLines then desL4 else desLine4 else na;
plot desDn5 = if showFE then if extendLines then desL5 else desLine5 else na;
plot midLine = if showFE then if extendLines then midL0 else midLine0 else na;
plot ascUp1 = if showFE then if extendLines then ascL1 else ascLine1 else na;
plot ascUp2 = if showFE then if extendLines then ascL2 else ascLine2 else na;
plot ascUp4 = if showFE then if extendLines then ascL4 else ascLine4 else na;
plot ascUp5 = if showFE then if extendLines then ascL5 else ascLine5 else na;
plot lLine = if showFE then if extendLines then loL0 else loLine else na;

midLine.SetStyle(Curve.SHORT_DASH);
hLine.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);
desDn1.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);
desDn2.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);
desDn4.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);
desDn5.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);
midLine.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);
ascUp1.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);
ascUp2.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);
ascUp4.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);
ascUp5.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);
lLine.AssignValueColor(if up then Color.CYAN else Color.MAGENTA);

plot plotLo = if showFR then if smoothFR then loSmooth else trough else na;#, "Low"
plot des23 = if showFR then if smoothFR then desSmooth1 else descPrice1 else na;
plot des38 = if showFR then if smoothFR then desSmooth2 else descPrice2 else na;
plot des50 = if showFR then if smoothFR then desSmooth3 else descPrice3 else na;
plot des61 = if showFR then if smoothFR then desSmooth4 else descPrice4 else na;
plot des78 = if showFR then if smoothFR then desSmooth5 else descPrice5 else na;
plot plotHi = if showFR then if smoothFR then hiSmooth else peak else na;#, "Low"
plot asc23 = if showFR then if smoothFR then ascSmooth1 else ascPrice1 else na;
plot asc38 = if showFR then if smoothFR then ascSmooth2 else ascPrice2 else na;
plot asc50 = if showFR then if smoothFR then ascSmooth3 else ascPrice3 else na;
plot asc61 = if showFR then if smoothFR then ascSmooth4 else ascPrice4 else na;
plot asc78 = if showFR then if smoothFR then ascSmooth5 else ascPrice5 else na;

plotLo.SetDefaultColor(Color.DARK_GREEN);
des23.SetDefaultColor(Color.DARK_GREEN);
des38.SetDefaultColor(Color.DARK_GREEN);
des50.SetDefaultColor(Color.DARK_GREEN);
des61.SetDefaultColor(Color.DARK_GREEN);
des78.SetDefaultColor(Color.DARK_GREEN);
plotHi.SetDefaultColor(Color.DARK_RED);
asc23.SetDefaultColor(Color.DARK_RED);
asc38.SetDefaultColor(Color.DARK_RED);
asc50.SetDefaultColor(Color.DARK_RED);
asc61.SetDefaultColor(Color.DARK_RED);
asc78.SetDefaultColor(Color.DARK_RED);

plot ma0Plot = if showFMA then ma0 else na;#, "23.6"
plot ma1Plot = if showFMA then ma1 else na;# "38.2"
plot ma2Plot = if showFMA then ma2 else na;# "50.0"
plot ma3Plot = if showFMA then ma3 else na;# "61.8"
plot ma4Plot = if showFMA then ma4 else na;# "78.6"
plot ma5Plot = if showFMA then ma5 else na;# "100.0"
plot ma6Plot = if showFMA then ma6 else na;# "161.8"
plot ma7Plot = if showFMA then ma7 else na;# "200.0"
plot ma8Plot = if showFMA then ma8 else na;# "261.8"
plot ma9Plot = if showFMA then ma9 else na;# "423.6"

ma0Plot.AssignValueColor(if ma0 < movAvgSrc then GlobalColor("up0") else GlobalColor("dn0"));
ma1Plot.AssignValueColor(if ma1 < movAvgSrc then GlobalColor("up1") else GlobalColor("dn1"));
ma2Plot.AssignValueColor(if ma2 < movAvgSrc then GlobalColor("up2") else GlobalColor("dn2"));
ma3Plot.AssignValueColor(if ma3 < movAvgSrc then GlobalColor("up3") else GlobalColor("dn3"));
ma4Plot.AssignValueColor(if ma4 < movAvgSrc then GlobalColor("up4") else GlobalColor("dn4"));
ma5Plot.AssignValueColor(if ma5 < movAvgSrc then GlobalColor("up5") else GlobalColor("dn5"));
ma6Plot.AssignValueColor(if ma6 < movAvgSrc then GlobalColor("up6") else GlobalColor("dn6"));
ma7Plot.AssignValueColor(if ma7 < movAvgSrc then GlobalColor("up7") else GlobalColor("dn7"));
ma8Plot.AssignValueColor(if ma8 < movAvgSrc then GlobalColor("up8") else GlobalColor("dn8"));
ma9Plot.AssignValueColor(if ma9 < movAvgSrc then GlobalColor("up9") else GlobalColor("dn9"));

AddCloud(if !showCloud then na else ma0, ma1, GlobalColor("dup"), GlobalColor("ddn"));
AddCloud(if !showCloud then na else ma1, ma2, GlobalColor("dup"), GlobalColor("ddn"));
AddCloud(if !showCloud then na else ma2, ma3, GlobalColor("dup"), GlobalColor("ddn"));
AddCloud(if !showCloud then na else ma3, ma4, GlobalColor("dup"), GlobalColor("ddn"));
AddCloud(if !showCloud then na else ma4, ma5, GlobalColor("dup"), GlobalColor("ddn"));
AddCloud(if !showCloud then na else ma5, ma6, GlobalColor("dup"), GlobalColor("ddn"));
AddCloud(if !showCloud then na else ma6, ma7, GlobalColor("dup"), GlobalColor("ddn"));
AddCloud(if !showCloud then na else ma7, ma8, GlobalColor("dup"), GlobalColor("ddn"));
AddCloud(if !showCloud then na else ma8, ma9, GlobalColor("dup"), GlobalColor("ddn"));

#-- END of CODE
 
Here is one that I use that works pretty well with my 5 min

def per = aggregationperiod.day;
def five_min = getaggregationperiod() <= aggregationperiod.five_min;

input Bubbles = yes;
input Bearish_Only = no;
input Bullish_Only = no;

def time = 1600;

def offset = 10;

def price = if five_min then close else double.nan;

def time_value = If(SecondsTillTime(time) == 0, price, time_value[1]);

def h = if !isNAN(time_value) then if high(period = per) < time_value then time_value else high(period = per) else high(period = per);
def l = if !isNAN(time_value) then if low(period = per) > time_value and five_min then time_value else low(period = per) else low(period = per);
def range = h - l;

def today = if (GetDay() == GetLastDay()) or (GetLastDay() - 1 == GetDay()) then yes else no;

def BubbleSpot = if !IsNaN(close[offset]) && IsNaN(close[offset-1]) && IsNaN(close) then (BarNumber() - 1) else double.nan;

plot high_ext = if today and !Bearish_only then h-(range*-.272) else double.nan;
plot high = if today and !Bearish_only then h else double.nan;
plot fib1 = if today and !Bearish_only then h-(range*.113) else double.nan;
plot fib2 = if today and !Bearish_only then h-(range*.236) else double.nan;
plot fib3 = if today and !Bearish_only then h-(range*.382) else double.nan;
plot fib4 = if today then h-(range*.5) else double.nan;
plot fib5 = if today and !Bullish_only then h-(range*.618) else double.nan;
plot fib6 = if today and !Bullish_only then h-(range*.764) else double.nan;
plot fib7 = if today and !Bullish_only then h-(range*.887) else double.nan;
plot low = if today and !Bullish_only then l else double.nan;
plot low_ext = if today and !Bullish_only then h-(range*1.272) else double.nan;

high_ext.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN);
high.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN or h == time_value);
fib1.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN);
fib2.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN);
fib3.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN);
fib4.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN);
fib5.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN);
fib6.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN);
fib7.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN);
low.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN or l == time_value);
low_ext.sethiding(getaggregationperiod() > aggregationperiod.THIRTY_MIN);

high_ext.setPaintingStrategy(paintingStrategy.HORIZONTAL);
high.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib1.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib2.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib3.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib4.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib5.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib6.setPaintingStrategy(paintingStrategy.HORIZONTAL);
fib7.setPaintingStrategy(paintingStrategy.HORIZONTAL);
low.setPaintingStrategy(paintingStrategy.HORIZONTAL);
low_ext.setPaintingStrategy(paintingStrategy.HORIZONTAL);

AddChartBubble(bubbles and bubblespot and today and !Bearish_only, fib1,"11.3%", CreateColor(209, 150, 155), close[offset] < fib1);
AddChartBubble(bubbles and bubblespot and today and !Bearish_only, fib2,"23.6%", CreateColor(209, 150, 155), close[offset] < fib2);
AddChartBubble(bubbles and bubblespot and today and !Bearish_only, fib3,"38.2%", CreateColor(209, 150, 155), close[offset] < fib3);
AddChartBubble(bubbles and bubblespot and today, fib4,"50%", CreateColor(209, 150, 155), close[offset] < fib4);
AddChartBubble(bubbles and bubblespot and today and !Bullish_only, fib5,"61.8%", CreateColor(209, 150, 155), close[offset] < fib5);
AddChartBubble(bubbles and bubblespot and today and !Bullish_only, fib6,"76.4%", CreateColor(209, 150, 155), close[offset] < fib6);
AddChartBubble(bubbles and bubblespot and today and !Bullish_only, fib7,"88.7%", CreateColor(209, 150, 155), close[offset] < fib7);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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