How can I create an envelope (EMA Channel) that the Percentage will be calculated automatically as follow: (standard deviation of last 100 days) / (last price) *100
I already have the formula to calculate the Percentage, but I cen`t combine it to the envelop formula
thanks in advance for the help
the (standard deviation of last 100 days) / (last price) *100 formula:
/*********************************
var nStdev = callFunction("StandardDeviation.efs", "main", 10, "Close");
if (nStdev == null) return;
********************************/
function preMain() {
setStudyTitle("Envelop per");
setDefaultBarFgColor(Color.RGB(192,87,255));
setCursorLabelName("Env per");
}
function main(nLength, sPriceSource) {
if (nLength == null) nLength = 100;
if (sPriceSource == null) sPriceSource = "Close";
var aSource = getValue(sPriceSource, 0, -nLength);
if (aSource == null) return null;
var sumX = 0;
var sumX2 = 0;
for (i = 0; i < nLength; ++i) {
sumX += aSource[i];
sumX2 += (aSource[i] * aSource[i])
}
var meanX = (sumX/nLength);
varClose = getValue("Close")
var stdev = Math.sqrt((sumX2/nLength) - (meanX*meanX))/close(-1)*100 ;
return stdev;
}
I already have the formula to calculate the Percentage, but I cen`t combine it to the envelop formula
thanks in advance for the help
the (standard deviation of last 100 days) / (last price) *100 formula:
/*********************************
var nStdev = callFunction("StandardDeviation.efs", "main", 10, "Close");
if (nStdev == null) return;
********************************/
function preMain() {
setStudyTitle("Envelop per");
setDefaultBarFgColor(Color.RGB(192,87,255));
setCursorLabelName("Env per");
}
function main(nLength, sPriceSource) {
if (nLength == null) nLength = 100;
if (sPriceSource == null) sPriceSource = "Close";
var aSource = getValue(sPriceSource, 0, -nLength);
if (aSource == null) return null;
var sumX = 0;
var sumX2 = 0;
for (i = 0; i < nLength; ++i) {
sumX += aSource[i];
sumX2 += (aSource[i] * aSource[i])
}
var meanX = (sumX/nLength);
varClose = getValue("Close")
var stdev = Math.sqrt((sumX2/nLength) - (meanX*meanX))/close(-1)*100 ;
return stdev;
}
Comment