Announcement

Collapse
No announcement yet.

Help with simple EFS

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

  • Help with simple EFS

    I don't know what I'm doing wrong here. It's just a simple MA of another indicator, but all it returns is -0. Please Help!

    Thanks for looking!


    function preMain(){
    setStudyTitle("MoVoMA");
    setCursorLabelName("MoVoMA", 0);
    setPlotType(PLOTTYPE_LINE);
    }
    var vSum = 0;
    var vSum1 =0;
    var vSum2 =0;
    var vTrend = 0;


    function main(nInputLength){
    if(nInputLength == null)
    nInputLength = 18;

    var nLength = nInputLength;
    var i,j;
    var vClose;
    var vOpen;
    var vVol;
    var SumTrend ;

    vClose = getValue("Close", 0, -3);
    vOpen = getValue("Open", 0, -3);
    vVol= getValue("Volume",0, -3);

    vSum = (vClose[0]-vOpen[0])*vVol[0];
    vSum1 = (vClose[1]-vOpen[1])*vVol[1];
    vSum2 =(vClose[2]-vOpen[2])*vVol[2];

    vTrend = (vSum+vSum1+vSum2)/30;

    if(vTrend == null) {
    return;
    }
    for(j = 0; j< nLength; j++) {

    SumTrend += vTrend[j];
    }


    return SumTrend/nLength;

    }

  • #2
    Hello weffy,

    In your for loop you are referencing vTrend[j] as an array. vTrend is not an array in your formula so it is returning "undefined." Did you intend to sum the previous nLength bars' vTrend values?
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Yes. Sum 18 bars, divide by 18

      Comment


      • #4
        Here's the modifications you need. Notice the array aTrend.

        PHP Code:
        function preMain(){
            
        setStudyTitle("MoVoMA");
            
        setCursorLabelName("MoVoMA"0);
            
        setPlotType(PLOTTYPE_LINE);
        }

        var 
        vSum 0;
        var 
        vSum1 =0;
        var 
        vSum2 =0;
        var 
        vTrend 0;
        var 
        aTrend null;

        function 
        main(nInputLength){
            if(
        nInputLength == null)
                
        nInputLength 18;

            var 
        nLength nInputLength;
            var 
        i,j;
            var 
        vClose
            var 
        vOpen;
            var 
        vVol;
            var 
        SumTrend 0;
            var 
        nState getBarState();

            if (
        aTrend == nullaTrend = new Array(nLength);

            if (
        nState == BARSTATE_NEWBAR) {
                
        aTrend.pop();
                
        aTrend.unshift(vTrend);
            }
            
            
        vClose getValue("Close"0, -3);
            
        vOpen getValue("Open"0, -3);
            
        vVolgetValue("Volume",0, -3);

            
        vSum = (vClose[0]-vOpen[0])*vVol[0];
            
        vSum1 = (vClose[1]-vOpen[1])*vVol[1];
            
        vSum2 =(vClose[2]-vOpen[2])*vVol[2];

            
        vTrend = (vSum+vSum1+vSum2)/30;
            
        aTrend[0] = vTrend;

            if(
        vTrend == null) return;
            
            for(
        0jnLengthj++) {
                
        SumTrend += aTrend[j]; 
            }

            return 
        SumTrend/nLength;

        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          Thanks Jason, Maybe it wasn't so simple, for me anyway. I don't understand it, but I'll give it a try.

          Thanks again, Jeff

          Comment

          Working...
          X