The Typical Fibonacci Average For ThinkOrSwim

Jman831

Member
This is the code for my Typical Fib Average. It is basically used as support/resistance.
The upward /downward slope of the average lines helps determine the overall direction of price.
When price crosses the Fibonacci average, it can be a sign of a change in trend.

It is a combination of 8 averages (lengths are adjustable) that are each multiplied by a Fibonacci number, added up, and then divided by the sum of those Fibonacci numbers.

It's used the same way you'd use a moving average. At it's default settings, it pairs well with charts of the index etfs like SPY, QQQ, and DIA.

I've updated the original post to show what the average looks like on a daily chart of the SPY at it's default settings. You can mess around with the average types and lengths to get different averages, but it's important to understand that AverageLength1 is weighted the most (x34) and AverageLength8 is weighted the least (x1).

Code:
input AverageTypes = AverageType.EXPONENTIAL;
input AveragePrices = close;
input AverageLength1 = 144;
input AverageLength2 = 126;
input AverageLength3 = 108;
input AverageLength4 = 90;
input AverageLength5 = 72;
input AverageLength6 = 54;
input AverageLength7 = 27;
input AverageLength8 = 18;

def avg1 = MovingAverage(AverageTypes, AveragePrices, AverageLength1) * 34;
def avg2 = MovingAverage(AverageTypes, AveragePrices, AverageLength2) * 21;
def avg3 = MovingAverage(AverageTypes, AveragePrices, AverageLength3) * 13;
def avg4 = MovingAverage(AverageTypes, AveragePrices, AverageLength4) * 8;
def avg5 = MovingAverage(AverageTypes, AveragePrices, AverageLength5) * 5;
def avg6 = MovingAverage(AverageTypes, AveragePrices, AverageLength6) * 3;
def avg7 = MovingAverage(AverageTypes, AveragePrices, AverageLength7) * 2;
def avg8 = MovingAverage(AverageTypes, AveragePrices, AverageLength8);
def typfibavg = (avg1 + avg2 + avg3 + avg4 + avg5 + avg6 + avg7 + avg8) / 87;

plot TypicalFibAverage = typfibavg;

Below is a screenshot of the Typical Fib Average at it's default settings on a daily chart of the SPY:

Typical-Fib-Average-SPY-Daily-9-2-22.png
 
Last edited by a moderator:
Someone asked in another thread if I could share the code for my Typical Fib Average. It is a combination of 8 averages (lengths are adjustable) that are each multiplied by a Fibonacci number, added up, and then divided by the sum of those Fibonacci numbers. Here is the code:

Code:
input AverageTypes = AverageType.EXPONENTIAL;
input AveragePrices = close;
input AverageLength1 = 144;
input AverageLength2 = 126;
input AverageLength3 = 108;
input AverageLength4 = 90;
input AverageLength5 = 72;
input AverageLength6 = 54;
input AverageLength7 = 27;
input AverageLength8 = 18;

def avg1 = MovingAverage(AverageTypes, AveragePrices, AverageLength1) * 34;
def avg2 = MovingAverage(AverageTypes, AveragePrices, AverageLength2) * 21;
def avg3 = MovingAverage(AverageTypes, AveragePrices, AverageLength3) * 13;
def avg4 = MovingAverage(AverageTypes, AveragePrices, AverageLength4) * 8;
def avg5 = MovingAverage(AverageTypes, AveragePrices, AverageLength5) * 5;
def avg6 = MovingAverage(AverageTypes, AveragePrices, AverageLength6) * 3;
def avg7 = MovingAverage(AverageTypes, AveragePrices, AverageLength7) * 2;
def avg8 = MovingAverage(AverageTypes, AveragePrices, AverageLength8);
def typfibavg = (avg1 + avg2 + avg3 + avg4 + avg5 + avg6 + avg7 + avg8) / 87;

plot TypicalFibAverage = typfibavg;
Hi Jman, how do I use this Indicator line? Thank you :)
 
Hi Jman, how do I use this Indicator line? Thank you :)
Hey Jdoc, it's used the same way you'd use a moving average. At it's default settings, it pairs well with charts of the index etfs like SPY, QQQ, and DIA. I've updated the original post to show what the average looks like on a daily chart of the SPY at it's default settings. You can mess around with the average types and lengths to get different averages, but it's important to understand that AverageLength1 is weighted the most (x34) and AverageLength8 is weighted the least (x1). If you're unsure what moving averages are for, they're basically used as support/resistance and the angle of the average lines help determine the overall direction of price. When price crosses a moving average, it can sometimes be a sign of a change in trend. One moving average crossing another is sometimes a sign of a change in trend as well.
 
Hey Jdoc, it's used the same way you'd use a moving average. At it's default settings, it pairs well with charts of the index etfs like SPY, QQQ, and DIA. I've updated the original post to show what the average looks like on a daily chart of the SPY at it's default settings. You can mess around with the average types and lengths to get different averages, but it's important to understand that AverageLength1 is weighted the most (x34) and AverageLength8 is weighted the least (x1). If you're unsure what moving averages are for, they're basically used as support/resistance and the angle of the average lines help determine the overall direction of price. When price crosses a moving average, it can sometimes be a sign of a change in trend. One moving average crossing another is sometimes a sign of a change in trend as well.
Thank you Jman. Very kind of you to respond as I know time is valuable. Best, Jeff
 
here is my version. I used a butterworth Filter instead of EMA's I assigned a value color to the middle line. Then I added ATR Bands
Code:
declare upper;
input period1 = 144;
input period2 = 126;
input period3 = 108;
input period4 = 90;
input period5 = 72;
input period6 = 54;
input period7 = 27;
input period8 = 18;

def price = (open + close) / 2;
def a1A = Exp(-1.414 * 3.14159 / period1);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / period1);
def coef2A = b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec ButterA = if BarNumber() < 3 then price else coef1A * (price + 2 * price[1] + price[2]) + coef2A * ButterA[1] + coef3A * ButterA[2];
def a1B = Exp(-1.414 * 3.14159 / period2);
def b1B = 2 * a1B * Cos(1.414 * 3.14159 / period2);
def coef2B = b1B;
def coef3B = -a1B * a1B;
def coef1B = (1 – b1B + a1B * a1B) / 4;
rec ButterB = if BarNumber() < 3 then price else coef1B * (price + 2 * price[1] + price[2]) + coef2B * ButterB[1] + coef3B * ButterB[2];
def a1C = Exp(-1.414 * 3.14159 / period3);
def b1C = 2 * a1C * Cos(1.414 * 3.14159 / period3);
def coef2C = b1C;
def coef3C = -a1C * a1C;
def coef1C = (1 – b1C + a1C * a1C) / 4;
rec ButterC = if BarNumber() < 3 then price else coef1C * (price + 2 * price[1] + price[2]) + coef2C * ButterC[1] + coef3C * ButterC[2];
def a1D = Exp(-1.414 * 3.14159 / period4);
def b1D = 2 * a1D * Cos(1.414 * 3.14159 / period4);
def coef2D = b1D;
def coef3D = -a1D * a1D;
def coef1D = (1 – b1D + a1D * a1D) / 4;
rec ButterD = if BarNumber() < 3 then price else coef1D * (price + 2 * price[1] + price[2]) + coef2D * ButterD[1] + coef3D * ButterD[2];
def a1E = Exp(-1.414 * 3.14159 / period5);
def b1E = 2 * a1E * Cos(1.414 * 3.14159 / period5);
def coef2E = b1E;
def coef3E = -a1E * a1E;
def coef1E = (1 – b1E + a1E * a1E) / 4;
rec ButterE = if BarNumber() < 3 then price else coef1E * (price + 2 * price[1] + price[2]) + coef2E * ButterE[1] + coef3E * ButterE[2];
def a1F = Exp(-1.414 * 3.14159 / period6);
def b1F = 2 * a1F * Cos(1.414 * 3.14159 / period6);
def coef2F = b1F;
def coef3F = -a1F * a1F;
def coef1F = (1 – b1F + a1F * a1F) / 4;
rec ButterF = if BarNumber() < 3 then price else coef1F * (price + 2 * price[1] + price[2]) + coef2F * ButterF[1] + coef3F * ButterF[2];
def a1G = Exp(-1.414 * 3.14159 / period7);
def b1G = 2 * a1G * Cos(1.414 * 3.14159 / period7);
def coef2G = b1G;
def coef3G = -a1G * a1G;
def coef1G = (1 – b1G + a1G * a1G) / 4;
rec ButterG = if BarNumber() < 3 then price else coef1G * (price + 2 * price[1] + price[2]) + coef2G * ButterG[1] + coef3G * ButterG[2];
def a1H = Exp(-1.414 * 3.14159 / period8);
def b1H = 2 * a1H * Cos(1.414 * 3.14159 / period8);
def coef2H = b1H;
def coef3H = -a1H * a1H;
def coef1H = (1 – b1H + a1H * a1H) / 4;
rec ButterH = if BarNumber() < 3 then price else coef1H * (price + 2 * price[1] + price[2]) + coef2H * ButterH[1] + coef3H * ButterH[2];

def typfibavg = (ButterA * 34 + ButterB * 21 + ButterC * 13 + ButterD * 8 + ButterE * 5 + ButterF * 3 + ButterG * 2 + ButterH) / 87;

plot TFA = typfibavg;
TFA.SetPaintingStrategy(PaintingStrategy.Dashes);
TFA.AssignValueColor(if TFA >= TFA[1] then Color.CYAN else Color.MAGENTA);
TFA.SetLineWeight(2);
input atrPeriod = 20;
input atrMultiplierUpper1 =  1.5;
input atrMultiplierLower1  = 1.5;
input atrMultiplierUpper2 =  2.5;
input atrMultiplierLower2  = 2.5;
input atrMultiplierUpper3 =  3.5;
input atrMultiplierLower3  = 3.5;
input atrMultiplierUpper4 =  4.5;
input atrMultiplierLower4  = 4.5;
input averageType = AverageType.WILDERS;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), atrPeriod);

plot UpperATR1 = typfibavg + (ATR * atrMultiplierUpper1);
 UpperATR1.setDefaultColor(Color.GREEN);
plot LowerATR1 = typfibavg - (ATR * atrMultiplierLower1);
 LowerATR1.setDefaultColor(Color.RED);
plot UpperATR2 = typfibavg + (ATR * atrMultiplierUpper2);
 UpperATR2.setDefaultColor(Color.GREEN);
plot LowerATR2 = typfibavg - (ATR * atrMultiplierLower2);
 LowerATR2.setDefaultColor(Color.RED);
plot UpperATR3 = typfibavg + (ATR * atrMultiplierUpper3);
 UpperATR3.setDefaultColor(Color.GREEN);
plot LowerATR3 = typfibavg - (ATR * atrMultiplierLower3);
 LowerATR3.setDefaultColor(Color.RED);
plot UpperATR4 = typfibavg + (ATR * atrMultiplierUpper4);
 UpperATR4.setDefaultColor(Color.GREEN);
plot LowerATR4 = typfibavg - (ATR * atrMultiplierLower4);
 LowerATR4.setDefaultColor(Color.RED);
 
here is my version. I used a butterworth Filter instead of EMA's I assigned a value color to the middle line. Then I added ATR Bands
Code:
declare upper;
input period1 = 144;
input period2 = 126;
input period3 = 108;
input period4 = 90;
input period5 = 72;
input period6 = 54;
input period7 = 27;
input period8 = 18;

def price = (open + close) / 2;
def a1A = Exp(-1.414 * 3.14159 / period1);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / period1);
def coef2A = b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec ButterA = if BarNumber() < 3 then price else coef1A * (price + 2 * price[1] + price[2]) + coef2A * ButterA[1] + coef3A * ButterA[2];
def a1B = Exp(-1.414 * 3.14159 / period2);
def b1B = 2 * a1B * Cos(1.414 * 3.14159 / period2);
def coef2B = b1B;
def coef3B = -a1B * a1B;
def coef1B = (1 – b1B + a1B * a1B) / 4;
rec ButterB = if BarNumber() < 3 then price else coef1B * (price + 2 * price[1] + price[2]) + coef2B * ButterB[1] + coef3B * ButterB[2];
def a1C = Exp(-1.414 * 3.14159 / period3);
def b1C = 2 * a1C * Cos(1.414 * 3.14159 / period3);
def coef2C = b1C;
def coef3C = -a1C * a1C;
def coef1C = (1 – b1C + a1C * a1C) / 4;
rec ButterC = if BarNumber() < 3 then price else coef1C * (price + 2 * price[1] + price[2]) + coef2C * ButterC[1] + coef3C * ButterC[2];
def a1D = Exp(-1.414 * 3.14159 / period4);
def b1D = 2 * a1D * Cos(1.414 * 3.14159 / period4);
def coef2D = b1D;
def coef3D = -a1D * a1D;
def coef1D = (1 – b1D + a1D * a1D) / 4;
rec ButterD = if BarNumber() < 3 then price else coef1D * (price + 2 * price[1] + price[2]) + coef2D * ButterD[1] + coef3D * ButterD[2];
def a1E = Exp(-1.414 * 3.14159 / period5);
def b1E = 2 * a1E * Cos(1.414 * 3.14159 / period5);
def coef2E = b1E;
def coef3E = -a1E * a1E;
def coef1E = (1 – b1E + a1E * a1E) / 4;
rec ButterE = if BarNumber() < 3 then price else coef1E * (price + 2 * price[1] + price[2]) + coef2E * ButterE[1] + coef3E * ButterE[2];
def a1F = Exp(-1.414 * 3.14159 / period6);
def b1F = 2 * a1F * Cos(1.414 * 3.14159 / period6);
def coef2F = b1F;
def coef3F = -a1F * a1F;
def coef1F = (1 – b1F + a1F * a1F) / 4;
rec ButterF = if BarNumber() < 3 then price else coef1F * (price + 2 * price[1] + price[2]) + coef2F * ButterF[1] + coef3F * ButterF[2];
def a1G = Exp(-1.414 * 3.14159 / period7);
def b1G = 2 * a1G * Cos(1.414 * 3.14159 / period7);
def coef2G = b1G;
def coef3G = -a1G * a1G;
def coef1G = (1 – b1G + a1G * a1G) / 4;
rec ButterG = if BarNumber() < 3 then price else coef1G * (price + 2 * price[1] + price[2]) + coef2G * ButterG[1] + coef3G * ButterG[2];
def a1H = Exp(-1.414 * 3.14159 / period8);
def b1H = 2 * a1H * Cos(1.414 * 3.14159 / period8);
def coef2H = b1H;
def coef3H = -a1H * a1H;
def coef1H = (1 – b1H + a1H * a1H) / 4;
rec ButterH = if BarNumber() < 3 then price else coef1H * (price + 2 * price[1] + price[2]) + coef2H * ButterH[1] + coef3H * ButterH[2];

def typfibavg = (ButterA * 34 + ButterB * 21 + ButterC * 13 + ButterD * 8 + ButterE * 5 + ButterF * 3 + ButterG * 2 + ButterH) / 87;

plot TFA = typfibavg;
TFA.SetPaintingStrategy(PaintingStrategy.Dashes);
TFA.AssignValueColor(if TFA >= TFA[1] then Color.CYAN else Color.MAGENTA);
TFA.SetLineWeight(2);
input atrPeriod = 20;
input atrMultiplierUpper1 =  1.5;
input atrMultiplierLower1  = 1.5;
input atrMultiplierUpper2 =  2.5;
input atrMultiplierLower2  = 2.5;
input atrMultiplierUpper3 =  3.5;
input atrMultiplierLower3  = 3.5;
input atrMultiplierUpper4 =  4.5;
input atrMultiplierLower4  = 4.5;
input averageType = AverageType.WILDERS;

def ATR = MovingAverage(averageType, TrueRange(high, close, low), atrPeriod);

plot UpperATR1 = typfibavg + (ATR * atrMultiplierUpper1);
 UpperATR1.setDefaultColor(Color.GREEN);
plot LowerATR1 = typfibavg - (ATR * atrMultiplierLower1);
 LowerATR1.setDefaultColor(Color.RED);
plot UpperATR2 = typfibavg + (ATR * atrMultiplierUpper2);
 UpperATR2.setDefaultColor(Color.GREEN);
plot LowerATR2 = typfibavg - (ATR * atrMultiplierLower2);
 LowerATR2.setDefaultColor(Color.RED);
plot UpperATR3 = typfibavg + (ATR * atrMultiplierUpper3);
 UpperATR3.setDefaultColor(Color.GREEN);
plot LowerATR3 = typfibavg - (ATR * atrMultiplierLower3);
 LowerATR3.setDefaultColor(Color.RED);
plot UpperATR4 = typfibavg + (ATR * atrMultiplierUpper4);
 UpperATR4.setDefaultColor(Color.GREEN);
plot LowerATR4 = typfibavg - (ATR * atrMultiplierLower4);
 LowerATR4.setDefaultColor(Color.RED);
I just now got around to looking at this. lol. I like it, good job! One thing I don't understand though is why the average is drastically off from mine. Yours seems to move more with the price than mine and sticks closer to it. I like the ATR bands. I'm assuming the cyan color is for uptrend and purple for downtrend?

Edit: I realize now the reason that it's drastically off from mine is probably because you used a butterworth filter instead of EMAs. In any case, it looks good. Shows a lot of "buy-the-dip" opportunities in an uptrend.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
301 Online
Create Post

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