ZackeryE21
New member
I have an indicator that calculates what percentage a given moving average is of a stock price.
if
Stock Price = $100
and
Moving Average = $110
then
Divergence = 110% (Moving Average is 10% above Stock Price)
So, my question is, how do I access the Divergence amount over a given period, and get a mean from that? I know how to calculate mean and everything of course; I just don't know how to store the data as I'm plotting the Divergence.
Here's the code for the Divergence Index indicator itself:
Thanks so much!
if
Stock Price = $100
and
Moving Average = $110
then
Divergence = 110% (Moving Average is 10% above Stock Price)
So, my question is, how do I access the Divergence amount over a given period, and get a mean from that? I know how to calculate mean and everything of course; I just don't know how to store the data as I'm plotting the Divergence.
Here's the code for the Divergence Index indicator itself:
Code:
declare once_per_bar;
declare lower;
input price = close;
input aggregationPeriod = AggregationPeriod.DAY;
input length = 200;
def EMA = ExpAverage(price, length);
def divergence_value = (EMA / close) * 100;
plot Divergence = divergence_value;
Thanks so much!