Announcement

Collapse
No announcement yet.

Moving average with negative offset

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

  • Moving average with negative offset

    I am using a moving average of

    vMA5x = new MAStudy(5, -3, "Close", MAStudy.EXPONENTAL);
    vMA5 = vMA5x.getValue(MAStudy.MA);

    The IF condition is something like this.

    if (vMA5 > vMA8) && (vMA5 > vMA12)

    I do a function etc. What I wanted to do was to see what the value is in vMA5 for purpose of validating my results. So I place a

    debugPrintln("vMA5-3 : " +vMA5); just after doing my alert and placing a flag on the chart. the value that was return was

    vMA5-3 : null

    Not sure how that this can be a "null" value used in this IF condition and still be true result for the IF statment.

  • #2
    cantwait
    Without seeing the code it is not possible to determine what is happening within the efs.
    Post the script or a working sample of it that illustrates the problem and someone may be able to help
    Alex

    Comment


    • #3
      Thank you for taking some time to read my question. Let me ask the question in a different way.

      In JavaScript if something has a value of "null" in it which I understand to mean that null = nothing. So if you have a conditional statement where you compare "null" to say 1.7760, what should be the result of the condition. Is it a "true" or a "false" condition returned. My understanding is that null will alway return a false condition.

      Comment


      • #4
        cantwait
        It should return false. Having said that the value of the average with negative offset will not be null on historical bars.
        Alex

        Comment


        • #5
          Alex, Thank you for your quick reply, it is very much appreciated. My next question is, how does one go about getting the value from a negative MA offset at the close of the current bar. In reading up on the EFS it appears that I could use the REF() command to request a previous bar of -1, -2, -3 etc. Also, why have a negative offset for a MA in EFS if you can not get a valid return value. Thanks for you input on this.

          cantwait

          P.S. It does return a null for a MA5/-3 at the close of the current bar. I ran a test to verify it and a value for previous bars.

          Comment


          • #6
            cantwait
            Using your own example from a prior message you would use
            vMA5x.getValue(MAStudy.MA,-3)
            in your conditions which will return the value of the average 3 bars back.
            As to your question I am not sure I understand what you are asking.
            Alex

            Comment

            Working...
            X