RedKTrader

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.
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?