The script calculates an plots first and second derivatives of a EMA of "length" periods, with a default value of 21 periods.
Aug 18, 2020The script calculates an plots first and second derivatives of a EMA of "length" periods, with a default value of 21 periods.
- Blue curve is the first derivative of the EMA, which can be interpreted as the "speed" , "slope", or percentage of gains (or loses) walking over the EMA, measured in % per period. If timeframe is Days, it will show a %/day on the scale @ the right of graphic.
- Fuchsia curve is the second derivative of the EMA, and can be assumed to be the "acceleration" or driving force that could augment or diminish the EMA Speed.
When Speed & Acceleration ar both >=0, EMA is in positive rally, and becoming stepper, so the bacground is colored green.
First and second derivatoves are performed using "basis functions", as are applied in FEM implementation.
El Script calcula y plotea la primera y segunga derivada de una EMA de "length" períodos, con un valor por defecto de 21.
- La curva azul es la primera derivada de la EMA; que puede ser interpretada conmo su "velocidad", "pendiente" o % de ganancia o pérdida que se tendría sobre la EMA. Cuando la unidad de tiempo del gráfico es Días, permite visualizar en la escala de la derecha el % de ganancia o pérdida por día.
- La curva Fucsia muestra la segunda derivada, o "Aceleración", que se puede interpretar como la fuerza que puede aumentar o dismu¿inuir la pendiente de la EMA.
Cuando la Velocidad y Aceleración son mayores que cero, las ganancias aumentan cada período, y el findo de colorea de verde.
Las derivadas primera y segunda se calculan usando técnicas de funciones de forma, como las aplicadas en el MEF.
Oct 5, 2020
Release Notes
Scale of EMA Acceleration (curvature) is calculated automatically
//@version=4 | |
study("EMA21 Speed & Accel", overlay=false) | |
// Variable definition | |
NP = input(1, minval=1, title="Number of Periods to use in finite difference derivatives") | |
// CURVSC = input(0.1, minval=0, title="Accel Plot Scale") // Not used in this release | |
// | |
len1 = input(21, minval=1, title="EMA Length") | |
out1 = ema(close, len1) | |
// background color when speed & acceleration are >=0 | |
verdeclaro=#98FB98 | |
blanco=#FFFFFF | |
// | |
// SLOW MA Derivative (Speed in %/Period) Calculation (over NP periods) | |
// | |
SMAS = (1.50*ema(close, len1)-2*ema(close[NP], len1)+0.5*ema(close[2*NP], len1))/(NP*ema(close, len1)) // derivada con tres puntos | |
// Se plotea SMASMA para suavizar un poco | |
SMASMA = sma(SMAS, 5) | |
// | |
plot(max(SMASMA*100,-5), title="%-per-day", color=color.blue, linewidth=3) | |
// | |
// SMAS Derivative (Curvature = acceleration in %/period/period ) = Speed derivative = Acceleration | |
// | |
CURV = (ema(close, len1)-2*ema(close[NP], len1)+ema(close[2*NP], len1))/(NP*NP) // derivada SEGUNDA con tres puntos | |
// | |
CURVMA = sma(CURV,5) | |
// Scale Curvature | |
maxslope=highest(SMASMA,200)*100 | |
maxcurvature=highest(CURVMA,200) | |
scale=1*maxslope/maxcurvature | |
// | |
plot(iff(CURVMA>0, min(CURVMA*scale,5), max(CURVMA*scale,-5)), title="CURV", color=color.fuchsia, linewidth=2) | |
// | |
// Colorear verde claro u oscuro en función de CURV >=0 and/or SMASMA >=0 | |
// | |
bgcolor((CURVMA>=0 and SMASMA>=0) ? verdeclaro : blanco, | |
transp=40) | |
// Se plotea el eje de abscisas | |
plot(0, title="0", color=color.black) |