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:

https://medium.datadriveninvestor.c...e-new-trading-horizons-in-python-f2d0f8c86222


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




Apologies bottom got cut of from copy of picture:
 
Last edited:

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
#Based Upon https://medium.datadriveninvestor.c...e-new-trading-horizons-in-python-f2d0f8c86222
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);
Capture.jpg
 

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... :cool:

20210406-Fib-MA.png


Code:
#Fibonacci Moving Average
#Based Upon https://medium.datadriveninvestor.c...e-new-trading-horizons-in-python-f2d0f8c86222
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);

AddCloud(fibma_high, fibma_low, Color.GREEN, Color.RED);
 

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... :cool:

20210406-Fib-MA.png


Code:
#Fibonacci Moving Average
#Based Upon https://medium.datadriveninvestor.c...e-new-trading-horizons-in-python-f2d0f8c86222
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);

AddCloud(fibma_high, fibma_low, Color.GREEN, Color.RED);
@netarchitech SWEET Thanks for your input...

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

 

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.

AqIL6pr.png


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.

AqIL6pr.png


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 :)
 

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:

Joseph Patrick 18

Active member

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.
 

Similar threads

Top