Announcement

Collapse
No announcement yet.

MA of Any EFS. It Works!

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

  • MA of Any EFS. It Works!

    Make sure you point to a default efs file, in lines 11 & 12. In this program I pointed to "MyMA.efs". You can replace it with any file of your choice.


    function preMain() {

    setPriceStudy(false);
    setStudyTitle("My EFS MA");
    setCursorLabelName("My EFS MA", 0);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarFgColor(Color.red, 0);


    // DEFINE WHICH DEFAULT EFS FILE YOU WANT TO USE
    var fp0 = new FunctionParameter("MyEFS", FunctionParameter.STRING);
    fp0.setDefault("MyMA.efs");


    var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp1.setName("Length");
    fp1.setLowerLimit(1);
    fp1.setDefault(5);
    }

    var aValue = null;

    function main(MyEFS, Length) {

    //insert the code for the custom study here

    addBand(0, PS_SOLID, 1, Color.blue, 90000);

    var vPlot = call(MyEFS);//replace close(0) with the return of the custom study

    if (aValue == null) {
    aValue = new Array(Length);
    }
    if (getBarState() == BARSTATE_NEWBAR) {
    aValue.pop();
    aValue.unshift(vPlot);
    } else {
    aValue[0] = vPlot;
    }

    var i=0;
    var nSum = 0;
    for (i = 0; i < Length; ++i) {
    nSum += aValue[i];
    }
    var vSMA = nSum/Length;


    return vSMA;
    }
Working...
X