Announcement

Collapse
No announcement yet.

Comparing 2 Mom periods

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

  • Comparing 2 Mom periods

    Nothing plots. I think the problem is how I'm creating the series.


    PHP Code:
    // comapring two Mom periods

    var xFastMom null;
    var 
    xSlowMom null;
    var 
    xMACD null;
    var 
    xSig null;
    var 
    xHist null;
    var 
    bInit false;


    function 
    preMain() {
        
    setPlotTypePLOTTYPE_LINE); 
        
    setPlotTypePLOTTYPE_LINE); 
        
    setPlotTypePLOTTYPE_HISTOGRAM); 
        
    setDefaultBarFgColorColor.blue);
        
    setDefaultBarFgColorColor.red);
        
    setDefaultBarFgColorColor.grey);
        }

    function 
    main() {
    if (!
    bInit) {
            
    xFastMom ema(6mom(12) );
            
    xSlowMom ema(6mom(26) );
            
    xMACD efsInternal("fGetMACD"xFastMomxSlowMom);
            
    xSig ema(9getSeries(xMACD) );
            
    xHist getSeries(xMACD) - getSeries(xSig);
            
    bInit true;
        }
        
        return new Array( 
    getSeries(xMACD), getSeries(xSig), getSeries(xHist) );
    }

    function 
    fGetMACD(xFxS){
        
    nF xF.getValue(0);
        
    nS xS.getValue(0);
        return(
    nF-nS);


  • #2
    pj909
    In the following line of code the getSeries() function is not required to call the xMACD series as this is being passed within the initialization routine [and the efsInternal() call is returning a single series anyhow]



    You can pass the xMACD series directly to the ema() function as shown below



    The following line of code



    should be located outside of the initialization routine else it will be executed only once.
    Furthermore you should retrieve the values from each series rather than calling the series eg



    In the following line of code



    you are incorrectly calling xHist as if it were a series which it is not. When you use one or more series within an expression the result is not a series but a value
    Additionally as I believe I have already explained to you in the past [you may want to search through your own posts] unless you are basing your study on external intervals and/or symbols [whereby you want the efs engine to maintain the synchronization of the plots] you do not need to plot the series [and for that matter even call it] but should plot its values that you retrieve using the getValue() method of the series object
    That line of code should be as follows



    Once you implement the suggested changes the formula will work
    I would also suggest that you search the forums as there are many examples of studies on studies available since the subject has been covered at length before [including in some of your own threads and if I remember correctly on this very same topic]
    Alex



    Originally posted by pj909 View Post
    Nothing plots. I think the problem is how I'm creating the series.


    PHP Code:
    // comapring two Mom periods

    var xFastMom null;
    var 
    xSlowMom null;
    var 
    xMACD null;
    var 
    xSig null;
    var 
    xHist null;
    var 
    bInit false;


    function 
    preMain() {
        
    setPlotTypePLOTTYPE_LINE); 
        
    setPlotTypePLOTTYPE_LINE); 
        
    setPlotTypePLOTTYPE_HISTOGRAM); 
        
    setDefaultBarFgColorColor.blue);
        
    setDefaultBarFgColorColor.red);
        
    setDefaultBarFgColorColor.grey);
        }

    function 
    main() {
    if (!
    bInit) {
            
    xFastMom ema(6mom(12) );
            
    xSlowMom ema(6mom(26) );
            
    xMACD efsInternal("fGetMACD"xFastMomxSlowMom);
            
    xSig ema(9getSeries(xMACD) );
            
    xHist getSeries(xMACD) - getSeries(xSig);
            
    bInit true;
        }
        
        return new Array( 
    getSeries(xMACD), getSeries(xSig), getSeries(xHist) );
    }

    function 
    fGetMACD(xFxS){
        
    nF xF.getValue(0);
        
    nS xS.getValue(0);
        return(
    nF-nS);

    Comment


    • #3
      Thank you Alex.

      Comment


      • #4
        pj909
        You are welcome
        Alex


        Originally posted by pj909 View Post
        Thank you Alex.

        Comment

        Working...
        X