Announcement

Collapse
No announcement yet.

TypeError: variable has no properties

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

  • TypeError: variable has no properties

    Hi,

    The following is a snippet of my code, I'm getting error: "TypeError: LMA0 has no properties".

    Please help. Thank you.

    W

    PHP Code:
    var xSMA efsExternal("MA.efs""close"fastMAlength);
        var 
    xLMA efsExternal("MA.efs""close"slowMAlength);
        
        
    SMA0 xSMA.getValue(0);
        
    SMA1 xSMA.getValue(-1);
        
    SMA2 xSMA.getValue(-2);
        
    LMA0 xLMA.getValue(0);
        
    LMA1 xLMA.getValue(-1);
        
    LMA2 xLMA.getValue(-2);

    debugPrintln(LMA0); 

  • #2
    Correction.

    PHP Code:
    var xSMA efsExternal("MA.efs""close"fastMAlength);

        var 
    xLMA efsExternal("MA.efs""close"slowMAlength);

        
    SMA0 xSMA.getValue(0);
        
    SMA1 xSMA.getValue(-1);
        
    SMA2 xSMA.getValue(-2);
        
    LMA0 xLMA.getValue(0);
        
    LMA1 xLMA.getValue(-1);
        
    LMA2 xLMA.getValue(-2);

    debugPrintln(LMA0.toFixed(2)); 

    Comment


    • #3
      William
      You need to perform a null check on the variable being used prior to applying the .toFixed() method eg
      if(LMA0 == null) return;
      Alex

      Comment


      • #4
        This will happen at the very start of calculating your moving average study. The study will return null until it has enough samples to compute the first moving average. So you are assigning null to LMA0 and then trying to print it, which efs doesn't like.

        A simple fix would be
        if(xLMA.getValue(-2) != null)
        assign values and print inside if statement


        Steve

        Comment


        • #5
          I see. Thanks, guys. Much appreciated.

          William

          Comment

          Working...
          X