I decided that I should re-think using standard deviation and have chosen to use variance in price as my metric for this study. I still have one minor issue that I have yet to figure out how to resolve. I cannot figure out to display the type of moving average on the the label. I would appreciate any insight you may give me in resolving that. I included a chart with the example. I will provide code for my other studies if there is any interest the are shown on the example I have attached.
Here is the code as it stands now:
#JM_2MAs
#timeframe is a multiplier that allows any average time frame that is not the same as the chart time frame
#if not intra-day, then intra-day is set to one to one for daily and longer charts
def na = Double.NaN;
def bn = BarNumber();
def data = close;
input avg_type = AverageType.SIMPLE;
input intraday = yes;
input timeframe = 2;
input avg1_len = 50;
input avg2_len = 100;
input Line_Weigth =1;
#Intraday or Not
def actLen = if intraday == yes then timeframe else 1;
def avg1 = MovingAverage(avg_type, data, round(avg1_len*actLen ));
def avg2 = MovingAverage(avg_type, data, round(avg2_len*actLen));
input show_avg1_line = yes;
input show_avg2_line = yes;
plot avg1_p = if show_avg1_line then avg1 else na;
avg1_p.SetDefaultColor(CreateColor(0, 255, 255 ));
avg1_p.SetLineWeight(Line_Weigth);
avg1_P.SetStyle(Curve.points);
avg1_p.HideBubble();
plot avg2_p = if show_avg2_line then avg2 else na;
avg2_p.SetDefaultColor(CreateColor(255, 102, 255 ));
avg2_p.SetLineWeight(Line_Weigth);
avg2_p.SetStyle(Curve.points);
avg2_p.HideBubble();
def dst1 = (close-avg1) / close;
def amt1 = round(close-avg1);
def dst2 = (close- avg2) / close;
def amt2 = round(close-avg2);
# I would like to dispay the MovingAverage.type instead of just "MA" text
AddLabel(show_avg1_line,avg1_len + "MA: " +round(avg1), CreateColor(0, 255, 255)) ;
AddLabel(show_avg1_line,"Dif : "+ amt1 + " " + (asPercent(round(close-avg1)/close)), CreateColor(0, 255, 255 ));
AddLabel(show_avg2_line,avg2_len + "MA: " +round(avg2), CreateColor(255, 102, 255)) ;
AddLabel(show_avg2_line,"Dif : "+ amt2 + " " + (asPercent(round(close-avg2)/close)), CreateColor(255, 102, 255 ));
#End