TA Basics: further "Steps" with our Moving Average

So far in this series of posts, we have worked thru creating a basic zero-lag moving average, then moved forward all the way to coding a "Fibonacci" Weighted Moving Average .

in this post we take a look at a technique that can help traders minimize noise in the underlying data and get better insight on the changes that are happening in the data series represented by the moving average. we'll look at adding "stepping" to our Fibonacci Moving Average as an example. we introduce the Stepping Fibonacci Moving Average , or Step_FiMA

note that you can use the same technique with any plot you may have. feel free to copy or leverage the relevant parts of the script - the script is commented to make this easier.

How is this useful?
with "stepping", you get your indicator to "round" the outcome into pre-specified bands or ranges. this works very similar to how, for example, range or Renko charts work. you can easily see the difference in the chart above once we look at a non-stepped and a stepping moving average of the same length side-by-side

the more granular your timeframe is, you will see the effect of the stepping clearer - here's how the same chart looks when we go into the 1-hr aggregation

Notes about this script
there are couple of pieces i wanted to highlight in the script if you plan to use some of it :

1 - the step(x) function is meant to try to automatically pick the best "suitable" step size based on the range of the underlying series (for example, the closing price). these ranges i included here in the code are just my own "best choices" - you are totally welcome to adjust these ranges and the resulting step size to your own preference

2 - we applied the stepping as a user-choice. user can choose a manual entry, or "0" to get the code to automatically pick the step size, or enter -1 (or actually any value below zero) to cancel the stepping option altogether - this gives us some flexibility on how to use the stepping in an indicator

3 - very important (and somehow confusing): on the "rounding" approach:

the magic math formula that actually creates the stepping is this one
result = round(input / step) * step

now, this tells the script to "round" the result up or down (the basic rounding) -- so for example, a price of 17 with a step of 5 would be rounded (down) to 15, where as a price of 18 would be rounded "up" to 20 -- this is not the way some of us would expect or want, cause the price never reached 20 and they would want an 18 to still be rounded to 15 - and the stepping line not to show 20 *until* the price actually hits or exceeds 20 -- in that case, you would need to replace the function "round" with the function "floor" --
so the new formula becomes: floor(input / step) * step
-- in an ideal world, we can make this rounding choice a user-option in the settings -- maybe in an improved version

4 - we kept the smoothing option, and it takes place before the stepping is applied - we continue to use that smoothing to further minimize the level changes in the FiMA line.

I hope you find this script useful in your journey with technical analysis and DIY scripting, and good luck in your trading.