#// © 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