Announcement

Collapse
No announcement yet.

Need Help with Diff between two MAs - NOT MACD

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

  • Need Help with Diff between two MAs - NOT MACD

    I would like to plot the difference between two EMAs - one is based on bar open and the other is based on bar close (which is why I can't use the MACD). I would actually like to calculate two differences - one based on a pair of 8 Bar EMA (one Open, one Close) and the other based on a pair of 13 bar EMA (one Open, one Close).

    I am not using variables in the efs (just to keep it simple). The number of bars is being hardwired in for both pairs.

    I would like to plot horizontal lines at 3 cents difference and 6 cents difference on both sides of the zero line. I'm multiplying by 100 to work with whole numbers rather than hundredths.

    I've pieced something together based on looking at a dozen or so efs files. I'm unfamiliar with the syntax and am probably making some obvious errors.

    I have managed to plot the four reference lines. I don't really understand the relationship between a Study and a Variable. Iialso don't understand how to make the efs show the values.

    I could probably work on this for days and still might not figure it out.

    The code I came up with is attached in a Word document. i couldn't figure out how to copy and paste the code into the post. Other people have done it - there's a way to do this that I'm unaware of.

    Ii would certainly appreciate your help.

    Ira
    [email protected]
    Attached Files

  • #2
    Re: Need Help with Diff between two MAs - NOT MACD

    Ira
    Enclosed below is a corrected version of your script (with some brief comments on the changes made) .
    If you are new to programming in efs and are interested in learning more about it you may want to review the JavaScript for EFS video series and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS.
    If at any time you have specific programming questions post them in this forum and someone will try to assist you
    Alex


    PHP Code:
    addBand(6PS_SOLID1Color.black"upper6")
    addBand(3PS_SOLID1Color.black"upper3")
    addBand(-6PS_SOLID1Color.black,"lower6")
    addBand(-3PS_SOLID1Color.black"lower3")

    function 
    preMain()
    {
        
    setStudyTitle("MA Diff");
        
    setCursorLabelName("Diff 8"0);
        
    setCursorLabelName("Diff 13"1);
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarFgColor(Color.red1);
        
    setDefaultBarThickness(20);
        
    setDefaultBarThickness(21);
        
        
    setStudyMax(15);
        
    setStudyMin(-15);
    }

    var 
    Cema8 null;
    var 
    Oema8 null;
    var 
    Cema13 null;
    var 
    Oema13 null;
    //var diff8 = null;//removed as not required
    //var diff13 = null;//removed as not required
    var bInit=false;

    function 
    main ()
    {
        var 
    myCema8;
        var 
    myOema8
        
    var myCema13;
        var 
    myOema13;
        var 
    mydiff8;
        var 
    mydiff13;

        if ( 
    bInit == false ) {//replaced {} brackets with () parenthesis
            
    Cema8 ema(8close());//removed 0 from close(0) close() is now a series as required by the ema() function
            
    Oema8 ema(8open());//removed 0 from open(0) as per above comment
            
    Cema13 ema(13close());//removed 0 from close(0) as per above comment also changed length of ema
            
    Oema13 ema(13open());//removed 0 from open(0) as per above comment 
            //diff8 = (Cema8 - Oema8)*100;//this needs to be calculated outside of bInit routine
            //diff13 = (Cema13 - Oema13)*100;//as above
            
    bInit true;
        }
        
    //{//removed { bracket
            
        
    myCema8 Cema8.getValue(0);
        
    myOema8 Oema8.getValue(0);
        
    myCema13 Cema13.getValue(0);
        
    myOema13 Oema13.getValue(0);
        
        if(
    myCema8==null || myOema8==null || myCema13==null || myOema13==null) return;//added null check on the values
            
        
    mydiff8 = (myCema8 myOema8)*100;//removed the .getValue(0) methods 
        
    mydiff13 = (myCema13 myOema13)*100;//as above
        
        //mydiff8 = diff8.getValue(0);//removed as not required also diff8 is not a series so cannot use getValue() method
        //mydiff13 = diff13.getValue(0);//as above

        
    return new Array ( mydiff8mydiff13 );


    Originally posted by iberenhaus
    I would like to plot the difference between two EMAs - one is based on bar open and the other is based on bar close (which is why I can't use the MACD). I would actually like to calculate two differences - one based on a pair of 8 Bar EMA (one Open, one Close) and the other based on a pair of 13 bar EMA (one Open, one Close).

    I am not using variables in the efs (just to keep it simple). The number of bars is being hardwired in for both pairs.

    I would like to plot horizontal lines at 3 cents difference and 6 cents difference on both sides of the zero line. I'm multiplying by 100 to work with whole numbers rather than hundredths.

    I've pieced something together based on looking at a dozen or so efs files. I'm unfamiliar with the syntax and am probably making some obvious errors.

    I have managed to plot the four reference lines. I don't really understand the relationship between a Study and a Variable. Iialso don't understand how to make the efs show the values.

    I could probably work on this for days and still might not figure it out.

    The code I came up with is attached in a Word document. i couldn't figure out how to copy and paste the code into the post. Other people have done it - there's a way to do this that I'm unaware of.

    Ii would certainly appreciate your help.

    Ira
    [email protected]

    Comment


    • #3
      Alex,

      I just received the email that you responded. Thank you so much. I really appreciate your help.

      Thanks,

      Ira

      Comment


      • #4
        Thank you

        Alex:

        It worked like a charm.

        I'm thrilled. As you can see I was only able to get part of the way there, but you figured out exactly what I wanted to do.

        Thanks again,

        Ira

        Comment


        • #5
          Ira
          You are most welcome
          I am glad to hear that it worked and that I was able to be of help.
          Alex


          Originally posted by iberenhaus
          Alex:

          It worked like a charm.

          I'm thrilled. As you can see I was only able to get part of the way there, but you figured out exactly what I wanted to do.

          Thanks again,

          Ira

          Comment

          Working...
          X