RedKTrader

TA Basics: Creating a Fibonacci Weighted Moving Average

RedKTrader 已更新   
In the previous 2 posts in this series, we played around with simple math concepts to create a zero-lag moving average that can deliver fast response and less lag - that we can use to enable better trend following, or as filter / signal.

here we take a step further - instead of using equal weight for the moving average (as in the Simple moving average) or linear weights (as in the weighted moving average), we get to pick THE MAGIC SEQUENCE, Fibonacci.
we will use the Fibonacci Sequence as weights to produce our moving average - so practically, we create a "Fibonacci Weighted Moving Average" (let's call it FiMA) - and compare the result with other commonly-used moving averages of the same length

in a Fibonacci moving average, the data will be weighted based on the Fibonacci Series starting from 1 (for the furthest data point)
so for example, if we use a length of 10, the weights will be 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 with the 55 being the weight applied to the most recent / current bar's selected value (close, hl2, hc3..etc) and moving backward

before i posted this script, i searched around to see if someone else has already wrote this - i found a couple, but the approach we use here in this code is different - i can't claim it to be more efficient - i honestly don't know - but the resulting code here, IMHO, is more compact and easier to integrate in other studies that you may like to put together to leverage this idea, to create your own indicators and strategies.

the reason the code here is more compact, is that it utilizes a shorter formula to calculate the FIb(n) - i included the source where i found that formula, and i tested it before using it in the code.
i also added an optional "extra smoothing" for the resulting MA, by simply calling the fima() function a second time (so like doing a 2-pass filter), with a smaller length on the result of the 1st pass. keep this smoothing small not to produce too much lag.


i like the outcome when compared to other moving averages - it has a fast response to data/trend change and less overshoot - but honesty i didn't see any real "Fibonacci Magic" :) .. but i'll leave the final judgement to those who use it - this is more of an experimental code in all cases - please feel free to use, change and share feedback.

版本注释:
- no code change - just updated the commentary to explain the build up of the FiMA() function
版本注释:
- Just a quick update with the following notes

1. we removed the round() function from the calculation of the Fib Weights. it only makes a small difference until Fib(9) but it causes a side effect of the FiMA behaving erratically after length = 92 (this is where the function hits the maximum integer value in Pine)

2. thanks to feedback - yes, as the FiMA length increases, the Fib ratios become too large .. at around length = 15 to 20, the last 5 data points will always have ~91% of the sum of weights - any length changes after that will have no effect on the FiMA line plot. if this MA is used, it's suggested that it is used only for short lengths below 15 - otherwise, a weighted moving average will be a lot more efficient.
at the end, this was an experimental TA exercise - maybe someone gets inspired and makes something out of it :)

- thanks to those who provided feedback and helped diagnose the behavior with high value of lengths
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?