Announcement

Collapse
No announcement yet.

EMA results not correct

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

  • EMA results not correct

    I have a working indicator that produces stochastic momentum. I am trying to add an EMA(3, vSMI) of the SMI, however the results are not correct. The results range around 300, when the SMI ranges between -50 and +50. Below is a copy of the code I am using. I have also attached the .efs.

    PHP Code:

    function main() {
        
        var 
    vSMqN   efsInternal("myCalcN");
        var 
    vEMAsN  ema(25vSMqN);
        var 
    vEMArN  ema(1vEMAsN);

        var 
    vSMqD   efsInternal("myCalcD");
        var 
    vEMAsD  ema(25vSMqD);
        var 
    vEMArD  = (ema(1vEMAsD) * .5);
        var 
    vSMI    = ((vEMArN/vEMArD)*100);
        var 
    vSMIs   ema(3vSMI);
        
        if (
            
    vSMI 50
            
    onAction1()

        else if (
            
    vSMI < -50
            
    onAction2();
        
        return new Array(
            
    vSMI,
            
    vSMIs
        
    ); 
    Any thoughts are greatly appreciated!

    Regards,
    zMendel
    Attached Files

  • #2
    Re: EMA results not correct

    Originally posted by zmendel
    I have a working indicator that produces stochastic momentum. I am trying to add an EMA(3, vSMI) of the SMI, however the results are not correct. The results range around 300, when the SMI ranges between -50 and +50. Below is a copy of the code I am using. I have also attached the .efs.

    PHP Code:

    function main() {
        
        var 
    vSMqN   efsInternal("myCalcN");
        var 
    vEMAsN  ema(25vSMqN);
        var 
    vEMArN  ema(1vEMAsN);

        var 
    vSMqD   efsInternal("myCalcD");
        var 
    vEMAsD  ema(25vSMqD);
        var 
    vEMArD  = (ema(1vEMAsD) * .5);
        var 
    vSMI    = ((vEMArN/vEMArD)*100);
        var 
    vSMIs   ema(3vSMI);
        
        if (
            
    vSMI 50
            
    onAction1()

        else if (
            
    vSMI < -50
            
    onAction2();
        
        return new Array(
            
    vSMI,
            
    vSMIs
        
    ); 
    Any thoughts are greatly appreciated!

    Regards,
    zMendel
    zMendel,

    In case you are not aware I think Alex has a library with all those Blau double smoothed egotic indicators you may want to check out.


    If you want to get this version to work might be helpful to find the bug if you post the rest of the EFS, I think the first few line on the origional contained the ifunctions referenced via the EFSnternal calls.

    Glen
    Glen Demarco
    [email protected]

    Comment


    • #3
      EMA results not correct

      Glen:

      How would I get the Blau indicators from Alex? Where is the library you mentioned? Can I search for it in the forums or somewhere else. I searched the forums for Blau, but only found 1 indicator (TSI).

      I had attached the .efs to the original post. Are you able to grab that to look at the code? Regardless, here is the rest of the code:

      PHP Code:

      function preMain() {
          
      setPriceStudy(false);
          
      setStudyTitle("Stochastic Momentum Index (SMI) Ergotic Oscillator v3.1.3");
          
      setCursorLabelName("SMI"0);
          
      setCursorLabelName("SMIs"1);
          
      setDefaultBarStyle(PS_SOLID0);
          
      setDefaultBarStyle(PS_SOLID1);
          
      setDefaultBarFgColor(Color.navy0);
          
      setDefaultBarFgColor(Color.red1);    
          
      setDefaultBarThickness(10);
          
      setDefaultBarThickness(21);
          
      setPlotType(PLOTTYPE_HISTOGRAM0);
          
      setPlotType(PLOTTYPE_LINE1);    
      }

      function 
      myCalcN(){
              return (
      getValue("Close") - (.5 * ((hhv(13high())) + (llv(13low())))));
              
              }
              
      function 
      myCalcD(){
              return (
      hhv(13high())) - (llv(13low()));
              
              }

      function 
      main() {
          
          var 
      vSMqN   efsInternal("myCalcN");
          var 
      vEMAsN  ema(25vSMqN);
          var 
      vEMArN  ema(1vEMAsN);

          var 
      vSMqD   efsInternal("myCalcD");
          var 
      vEMAsD  ema(25vSMqD);
          var 
      vEMArD  = (ema(1vEMAsD) * .5);
          var 
      vSMI    = ((vEMArN/vEMArD)*100);
          var 
      vSMIs   ema(3vSMI);

          if (
              
      vSMI 50
              
      onAction1()

          else if (
              
      vSMI < -50
              
      onAction2();
          
             return new Array(
              
      vSMI,
              
      vSMIs
          
      );
         
          }
        
          
        function 
      postMain() {

      }


          function 
      onAction1() {
              
      setBarThickness(3);
              
      setBarFgColor(Color.RGB(255,0,0));
              }
              
          function 
      onAction2() {
              
      setBarThickness(3);
              
      setBarFgColor(Color.RGB(0,255,0));
              
              }[ 
      Thanks for all your help.

      Regards,
      zMendel

      Comment


      • #4
        Hello zMendel,

        The problem your are having is the same problem that was previously explained by Alexis in this thread. Your vSMI variable that you are passing to the ema() function is not a Series, but a number. When you pass a number as the second parameter of the ema(), the function treats it as a bar index reference, which is not the intended result you are looking for. Implement the same process for vSMI using the instructions Alexis gave you for vSMq in your previous thread. Hope this helps.
        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
          EMA results not correct

          Dear Jason:

          Thanks for your help. I thought that was the issue. However, when I adjust the code to place the results in an efsInternal(), I only get <none> in my vSMI results, and thus, <none> in vSMIs (ema of vSMI). See my adjusted function Main code below and the full .efs attached.

          PHP Code:

          function main(TradeTradeB1TradeB2) {
              
              if (
          getBarState() == BARSTATE_NEWBAR && getCurrentBarIndex() == 0bRealTime true;
              
              var 
          vSMqN   efsInternal("myCalcN");
              var 
          vEMAsN  ema(36vSMqN);
              var 
          vEMArN  ema(5vEMAsN);

              var 
          vSMqD   efsInternal("myCalcD");
              var 
          vEMAsD  ema(36vSMqD);
              var 
          vEMArD  ema(5vEMAsD);
              function 
          myCalcSMI() {
                  return ((
          vEMArN/(vEMArD .5))*100);
                  }
              
          //var vEMArD= (ema(5, vEMAsD) * .5);
              //var vSMI  = ((vEMArN/vEMArD)*100);
              
          var vSMI    efsInternal("myCalcSMI");
              var 
          vSMIs   ema(3vSMI);
              
              if (
                  
          vSMI 50
                  
          onAction1(TradeTradeB1TradeB2)
              else if (
                  
          vSMI < -50
                  
          onAction2(TradeTradeB1TradeB2)
              else if (
                  
          vSMI <= 50 || vSMI >= -50
                  
          onAction3();
              
              return new Array(
                  
          vSMI,
                  
          vSMIs
              
          );
             

          Attached Files

          Comment


          • #6
            Hello zmendel,

            Your new function, myCalcSMI(), needs to be placed outside of main() like myCalcD() and myCalcN(). Also, since myCalcSMI() uses data from your custom Series, you will also need to pass those Series to the myCalcSMI() function as parameters. For a detailed code example and explanation of this type study-on-study process, please visit this thread. Also make note of the initialization routine used to initialize the various data Series with the use of the bInit flag. This is a routine you should start using as well, which will be a more efficient coding practice and should help you better understand which variables in your code are storing Series Objects versus numbers.
            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


            • #7
              EMA results not correct

              Dear Jason:

              That was excellent advice. I adjusted the code as you suggested (also looking at the previous threads you advised which were also very helpful, thanks Alex) and it now works very well.

              Thanks you very much for the help.

              Regards,
              zMendel

              Comment


              • #8
                You're most welcome.
                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

                Working...
                X