Announcement

Collapse
No announcement yet.

envelope Auto Percentage

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • envelope Auto Percentage

    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;

    }

  • #2
    Re: envelope Auto Percentage

    bark
    In the formula in which you compute the envelope use the efsExternal() function to call the efs that computes the Standard Deviation and then use the value returned by that call in your calculations of the envelope.
    For the description and syntax of the efsExternal() function see this article in the EFS KnowledgeBase. You can find additional detailed examples in this thread on the efsInternal() and efsExternal() functions and in this thread that provides more examples on how to create studies on studies using these functions
    Alex


    Originally posted by bark
    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;

    }

    Comment

    Working...
    X