# Creating a Fibonacci Moving Average to Assist in Trend Detection

#### Joseph Patrick 18

##### Active member
Was wondering if anyone would be interested in looking into this?...Thanks in advance!

Creating a Fibonacci Moving Average to Assist in Trend Direction.

FMA: "This indicator will do the same job as a normal moving average but with improved reactivity and faster response to market moves as well as a better support and resistance level."

Here is the link to the article:

And here is a copy of the article in 2 pics:

Apologies bottom got cut of from copy of picture:

Last edited:

#### Ninja Bull

##### Member
Interesting, wished a good coder can chip in with this code

#### Joseph Patrick 18

##### Active member
Interesting, wished a good coder can chip in with this code
Me too!!

#### The Bataylor

##### New member
VIP
Wonder if this would work in tandem well with an HMA or if it'd be "too" reactive. Either way, I'd be interested to see this come to fruition

#### Joseph Patrick 18

##### Active member
Wonder if this would work in tandem well with an HMA or if it'd be "too" reactive. Either way, I'd be interested to see this come to fruition
Me too!! Hopefully someone that codes can have some sort of feedback or input...

#### SleepyZ

##### Well-known member
Me too!! Hopefully someone that codes can have some sort of feedback or input...
See if this helps.
Code:
``````#Fibonacci Moving Average
script fib{
input d     = close;
def ema2    = ExpAverage(d, 2);
def ema3    = ExpAverage(d, 3);
def ema5    = ExpAverage(d, 5);
def ema8    = ExpAverage(d, 8);
def ema13   = ExpAverage(d, 13);
def ema21   = ExpAverage(d, 21);
def ema34   = ExpAverage(d, 34);
def ema55   = ExpAverage(d, 55);
def ema89   = ExpAverage(d, 89);
def ema144  = ExpAverage(d, 144);
def ema233  = ExpAverage(d, 233);
def ema377  = ExpAverage(d, 377);
def ema610  = ExpAverage(d, 610);
def ema987  = ExpAverage(d, 987);
def ema1597 = ExpAverage(d, 1597);
def sumema  = ema2 + ema3 + ema5 + ema8 + ema13 + ema21 + ema34 + ema55 + ema89 + ema144 + ema233 + ema377 + ema610 + ema987 + ema1597;
plot fibavg = sumema / 15;
}
plot fibma_close = fib(close);
plot fibma_high  = fib(high);
plot fibma_low   = fib(low);``````

#### Joseph Patrick 18

##### Active member
Thanks @SleepyZ appreciate your help and input, I'll check it out and get back to you!

It looks pretty darn good on the daily chart...any feedback or input is greatly appreciated!!

Last edited:

#### netarchitech

##### Well-known member
VIP
Interesting idea...I like how the FibMAs creates a "zone" of support, as opposed to a traditional MA providing just a "line"...

Thanks to @Joseph Patrick 18 for the documentation and @SleepyZ for the initial coding...Just added a little more color to the end result...

Code:
``````#Fibonacci Moving Average
script fib{
input d     = close;
def ema2    = ExpAverage(d, 2);
def ema3    = ExpAverage(d, 3);
def ema5    = ExpAverage(d, 5);
def ema8    = ExpAverage(d, 8);
def ema13   = ExpAverage(d, 13);
def ema21   = ExpAverage(d, 21);
def ema34   = ExpAverage(d, 34);
def ema55   = ExpAverage(d, 55);
def ema89   = ExpAverage(d, 89);
def ema144  = ExpAverage(d, 144);
def ema233  = ExpAverage(d, 233);
def ema377  = ExpAverage(d, 377);
def ema610  = ExpAverage(d, 610);
def ema987  = ExpAverage(d, 987);
def ema1597 = ExpAverage(d, 1597);
def sumema  = ema2 + ema3 + ema5 + ema8 + ema13 + ema21 + ema34 + ema55 + ema89 + ema144 + ema233 + ema377 + ema610 + ema987 + ema1597;
plot fibavg = sumema / 15;
fibavg.hide();
}

plot fibma_close = fib(close);
fibma_close.hide();

plot fibma_high  = fib(high);
fibma_high.SetDefaultColor(Color.GREEN);
fibma_high.SetLineWeight(3);

plot fibma_low   = fib(low);
fibma_low.SetDefaultColor(Color.RED);
fibma_low.SetLineWeight(3);

#### Joseph Patrick 18

##### Active member
Interesting idea...I like how the FibMAs creates a "zone" of support, as opposed to a traditional MA providing just a "line"...

Thanks to @Joseph Patrick 18 for the documentation and @SleepyZ for the initial coding...Just added a little more color to the end result...

Code:
``````#Fibonacci Moving Average
script fib{
input d     = close;
def ema2    = ExpAverage(d, 2);
def ema3    = ExpAverage(d, 3);
def ema5    = ExpAverage(d, 5);
def ema8    = ExpAverage(d, 8);
def ema13   = ExpAverage(d, 13);
def ema21   = ExpAverage(d, 21);
def ema34   = ExpAverage(d, 34);
def ema55   = ExpAverage(d, 55);
def ema89   = ExpAverage(d, 89);
def ema144  = ExpAverage(d, 144);
def ema233  = ExpAverage(d, 233);
def ema377  = ExpAverage(d, 377);
def ema610  = ExpAverage(d, 610);
def ema987  = ExpAverage(d, 987);
def ema1597 = ExpAverage(d, 1597);
def sumema  = ema2 + ema3 + ema5 + ema8 + ema13 + ema21 + ema34 + ema55 + ema89 + ema144 + ema233 + ema377 + ema610 + ema987 + ema1597;
plot fibavg = sumema / 15;
fibavg.hide();
}

plot fibma_close = fib(close);
fibma_close.hide();

plot fibma_high  = fib(high);
fibma_high.SetDefaultColor(Color.GREEN);
fibma_high.SetLineWeight(3);

plot fibma_low   = fib(low);
fibma_low.SetDefaultColor(Color.RED);
fibma_low.SetLineWeight(3);

@netarchitech SWEET Thanks for your input...

Pretty sweet move to the upside today on BYND up over 4 dollars today so far...

#### Joseph Patrick 18

##### Active member
Quick scan if anyone needs..(Pic 1) I have it set to SP 100 no other criteria and once it starts to bounce off FMA cloud and I used it in conjunction with @Chuck Balanced BB Breakout (Pic 2)

#### jpmcewen

##### New member
VIP
Hey @Joseph Patrick 18 @SleepyZ and @netarchitech. I was looking at this indicator and came across the MyEMA example for script(). It says,
This code defines the MyEma script where the first EMA value is calculated as SMA in contrast to the ExpAverage function whose first value is assigned the closing price. The main section of the code creates an oscillator based on the MyEMA difference for different lengths.

I left out the oscillator and I added it to your indicator and compared both:
• Blue - w/o MyEMA
• Pink - w/ MyEMA
I'm still new to thinkscript and scripting in general so be sure to review but there does seem to be a noticeable difference.

Code:
``````script MyEMA {
input data = close;
input length = 15;
def EMA = CompoundValue(1, 2 / (length + 1) * data + (length - 1) / (length + 1) * EMA[1], Average(data, length));
plot MyEma = EMA;
}

script fib{
input d     = close;
def ema2    = MyEMA(d, 2);
def ema3    = MyEMA(d, 3);
def ema5    = MyEMA(d, 5);
def ema8    = MyEMA(d, 8);
def ema13   = MyEMA(d, 13);
def ema21   = MyEMA(d, 21);
def ema34   = MyEMA(d, 34);
def ema55   = MyEMA(d, 55);
def ema89   = MyEMA(d, 89);
def ema144  = MyEMA(d, 144);
def ema233  = MyEMA(d, 233);
def ema377  = MyEMA(d, 377);
def ema610  = MyEMA(d, 610);
def ema987  = MyEMA(d, 987);
def ema1597 = MyEMA(d, 1597);
def sumema  = ema2 + ema3 + ema5 + ema8 + ema13 + ema21 + ema34 + ema55 + ema89 + ema144 + ema233 + ema377 + ema610 + ema987 + ema1597;
plot fibavg = sumema / 15;
fibavg.hide();
}

plot fibma_close = fib(close);``````

#### Joseph Patrick 18

##### Active member
Hey @Joseph Patrick 18 @SleepyZ and @netarchitech. I was looking at this indicator and came across the MyEMA example for script(). It says,

I left out the oscillator and I added it to your indicator and compared both:
• Blue - w/o MyEMA
• Pink - w/ MyEMA
I'm still new to thinkscript and scripting in general so be sure to review but there does seem to be a noticeable difference.

Code:
``````script MyEMA {
input data = close;
input length = 15;
def EMA = CompoundValue(1, 2 / (length + 1) * data + (length - 1) / (length + 1) * EMA[1], Average(data, length));
plot MyEma = EMA;
}

script fib{
input d     = close;
def ema2    = MyEMA(d, 2);
def ema3    = MyEMA(d, 3);
def ema5    = MyEMA(d, 5);
def ema8    = MyEMA(d, 8);
def ema13   = MyEMA(d, 13);
def ema21   = MyEMA(d, 21);
def ema34   = MyEMA(d, 34);
def ema55   = MyEMA(d, 55);
def ema89   = MyEMA(d, 89);
def ema144  = MyEMA(d, 144);
def ema233  = MyEMA(d, 233);
def ema377  = MyEMA(d, 377);
def ema610  = MyEMA(d, 610);
def ema987  = MyEMA(d, 987);
def ema1597 = MyEMA(d, 1597);
def sumema  = ema2 + ema3 + ema5 + ema8 + ema13 + ema21 + ema34 + ema55 + ema89 + ema144 + ema233 + ema377 + ema610 + ema987 + ema1597;
plot fibavg = sumema / 15;
fibavg.hide();
}

plot fibma_close = fib(close);``````
Okay thanks for your input and help regarding this script! I will check it out and get back to you. Thanks again

#### jpmcewen

##### New member
VIP
Okay thanks for your input and help regarding this script! I will check it out and get back to you. Thanks again
The image of the chart is off I believe. I didn't realize until later that Left-axis should probably be checked, when you do that, there is a large difference to both.

#### Joseph Patrick 18

##### Active member
The image of the chart is off I believe. I didn't realize until later that Left-axis should probably be checked, when you do that, there is a large difference to both.
Ok whether I have left axis checked or unchecked on mine it doesn't change your FMA...but what does change your FMA is when you input diff time frames...Daily is normal while 1 min you see the difference of the diff FMA's...

Last edited:

#### jpmcewen

##### New member
VIP
I don't know why you aren't seeing anything different. Code I shared above. Blue is left-axis checked. Pink is left-axis unchecked.

#### Joseph Patrick 18

##### Active member
Hi can you provide a pic because when I check and uncheck left axis I do not see a difference (was looking on Daily chart) thanks.
I don't know why you aren't seeing anything different. Code I shared above. Blue is left-axis checked. Pink is left-axis unchecked.

So sorry I got it now....I had left axis unchecked in main settings... I see the same exact thing....

#### Joseph Patrick 18

##### Active member
I don't know why you aren't seeing anything different. Code I shared above. Blue is left-axis checked. Pink is left-axis unchecked.

So what's your suggestion concerning the noticible differece between the two? Thx

#### jpmcewen

##### New member
VIP
So what's your suggestion concerning the noticible differece between the two? Thx
I'm new to this, but I think this means you need the Left-axis checked (not being an ass) for this just because the unchecked is so low from the candlesticks. I don't know if changes to the script may change that. I just took what someone else wrote and added the MyEMA. After digging into this a little today, I'm not so sure if I know this is useful at least by itself. By the look of it (on a longer term chart), it gets progressively tighter. My guess is it becomes more useful on smaller timeframes for very specific purposes but I don't know how to test that theory properly. You gotta get one of the big boys to look into this.

#### Joseph Patrick 18

##### Active member
I'm new to this, but I think this means you need the Left-axis checked (not being an ass) for this just because the unchecked is so low from the candlesticks. I don't know if changes to the script may change that. I just took what someone else wrote and added the MyEMA. After digging into this a little today, I'm not so sure if I know this is useful at least by itself. By the look of it (on a longer term chart), it gets progressively tighter. My guess is it becomes more useful on smaller timeframes for very specific purposes but I don't know how to test that theory properly. You gotta get one of the big boys to look into this.
Lol I'm probably more new to this or more inexperienced than you trust me....I am actually on phone with TOS Tech and he is going to look into it because it changes the Fibonacci Moving Average (pic 1 below)...He will call me back once someone has looked into why the FMA is being manipulated...my guess is because of the custom script (pic 2)...because if you use an actual TOS script like Keltner Channels it just shifts the screen slightly and not the FMA with related to price action.

pic 1

pic 2

I'll let you know what TOS tech sup says when they figure it out...thanks

#### jpmcewen

##### New member
VIP
Lol I'm probably more new to this or more inexperienced than you trust me....I am actually on phone with TOS Tech and he is going to look into it because it changes the Fibonacci Moving Average (pic 1 below)...He will call me back once someone has looked into why the FMA is being manipulated...my guess is because of the custom script (pic 2)...because if you use an actual TOS script like Keltner Channels it just shifts the screen slightly and not the FMA with related to price action.

pic 1

pic 2

I'll let you know what TOS tech sup says when they figure it out...thanks
Sometimes you just gotta do what you gotta do.