m_b_round

Centred Moving Average

m_b_round Actualizado   
Based around the Centered Moving Average as published by Vailant-Hero this script is revised and improved to aid with execution time & server load. For full description follow the link as above, as Valiant-Hero explains the idea perfectly well.

While the original script worked fine for small values of length, once length was extended significantly or chart timeframe set to short values then the script is prone to exceeding computation requirements. The original script was attempting to delete and re-draw (length x 3) lines on the chart for each tick. In addition to server load, once length is greater than 167 (500/3) then the first drawn lines start disappearing, so the predicted values no longer appear connected to the offset averages calculated from the candle data. A further error resulted with larger values of "length" and future data selected, in that the script would try and move lines more than 500 bars into the future.

Improvements and major code changes
  • All values for the predicted moving average lines are calculated from a single run through of the data, rather than having to loop back through the data "length" times (and then through it again "length" times if you selected double moving average). Each loop also inefficiently calculated the sum of "length" values by recalling each one individually.
  • Number of lines are thus reduced so that we're never attempting to plot more than "max_lines_count" onto the chart. User is able to select the granularity of the lines - more sections will mean a smoother line but at the expense of processing speed.
  • No matter the combination of "length" and the selected granularity of the lines, no line will be drawn if its endpoint would be more than 500 bars in the future.
  • Code for "Double SMA" only affected the predicted data values, rather than affecting the historic calculations (and standard deviation calcs) as well as the predictions. This has been included and results in much smoother lines when "Double Moving Average" is selected.
  • Striped lines for the predicted values - firstly to make it obvious where the "predictions" begin, and also because they look funky.
Notas de prensa:
Minor code update such that predicted values are only calculated on the last bar - as they're not needed before that point. Hopefully further improve execution times.
Notas de prensa:
Thanks to BarefootJoey for the bug report - odd values for length now calculate without throwing an error.

Also built in some more configuration options from a screenshot they showed me where the lines were dashed rather than striped. So there's now a config option for dashed lines, which will also reduce the script overhead.

Still seeing occasional errors with the amount of computing power when length is set to huge numbers (> 1000) so the next edition may be a rewrite to only delete / move lines if they have actually changed position rather than needlessly deleting and redrawing on each tick.
Script de código abierto

Siguiendo el verdadero espíritu de TradingView, el autor de este script lo ha publicado en código abierto, para que los traders puedan entenderlo y verificarlo. ¡Un hurra por el autor! Puede utilizarlo de forma gratuita, aunque si vuelve a utilizar este código en una publicación, debe cumplir con lo establecido en las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.

¿Quiere utilizar este script en un gráfico?