OPEN-SOURCE SCRIPT

Decimal EMA

123
Imagine you want a moving average line, but you want its "length" or "period" to be super precise, like 2.7 days instead of just 2 days or 3 days.

This script lets you do that. Here's the simple idea:

You Pick a Decimal Number: In the settings, you can type in a period with a decimal, say, 2.7.
The Script Does a Smart Blend:

It first calculates two regular EMAs: one for the whole number below your choice (EMA for 2 days) and one for the whole number above (EMA for 3 days).

Then, it cleverly mixes these two EMA lines. Since 2.7 is closer to 3 than to 2, it takes more from the "3-day EMA" and a bit less from the "2-day EMA." (Specifically, it takes 70% from the 3-day EMA and 30% from the 2-day EMA).

You Get a Decimal EMA Line: The result is a new EMA line that acts as if its period was exactly 2.7. This line is drawn on your chart.

Why do this?

It allows for very fine-tuned adjustments to how responsive your moving average is, giving a smoother change if you're testing slightly different period lengths.

In Short:

This script calculates an EMA for a period like "2.7" by intelligently blending the results of an EMA for "2" and an EMA for "3".

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.