Announcement

Collapse
No announcement yet.

Confused... series objects and efsInternal??

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

  • Confused... series objects and efsInternal??

    For the life of me I cannot understand why the two different results are occuring in the following routine when trying to calculate
    sma(close(0)"minus"close(-len)) or sma(close(0)"divide"close(-len)). Minus works but divide does not.
    Yet without the sma() part, xDiv.getValue(0) returns a value when subtraction or division is applied in closeDiv().
    I understand that sma() requires a series object to work on which is what it gets, so there must be a difference between 'subtract' and 'divide'...

    So the question is, what is it I don't understand??

    Regards
    Nigel

    PHP Code:
    var len 20;
    var 
    xDiv null;
    function 
    main(){

    if(
    xDiv == nullxDiv efsInternal("closeDiv"lenclose());
    var 
    efsClose sma(10getSeries(xDiv), 0);

    return (
    efsClose);
    }
    function 
    closeDivlensource ) {
     
       var 
    ret source.getValue(0) - source.getValue(-len);    //subtract WORKS
     //var ret = source.getValue(0) / source.getValue(-len);    //divide DOES NOT WORK??
     
    return( ret );

    Last edited by red49er; 12-20-2012, 05:18 AM.

  • #2
    Hey Nigel,

    Just check the denominator against 0 and null and you'll be fine

    G.


    Originally posted by red49er View Post
    For the life of me I cannot understand why the two different results are occuring in the following routine when trying to calculate
    sma(close(0)"minus"close(-len)) or sma(close(0)"divide"close(-len)). Minus works but divide does not.
    Yet without the sma() part, xDiv.getValue(0) returns a value when subtraction or division is applied in closeDiv().
    I understand that sma() requires a series object to work on which is what it gets, so there must be a difference between 'subtract' and 'divide'...

    So the question is, what is it I don't understand??

    Regards
    Nigel

    PHP Code:
    var len 20;
    var 
    xDiv null;
    function 
    main(){

    if(
    xDiv == nullxDiv efsInternal("closeDiv"lenclose());
    var 
    efsClose sma(10getSeries(xDiv), 0);

    return (
    efsClose);
    }
    function 
    closeDivlensource ) {
     
       var 
    ret source.getValue(0) - source.getValue(-len);    //subtract WORKS
     //var ret = source.getValue(0) / source.getValue(-len);    //divide DOES NOT WORK??
     
    return( ret );

    Comment


    • #3
      Hey thanks G...
      Now why didn't that occur to me??

      Comment


      • #4
        Originally posted by red49er View Post
        Hey thanks G...
        Now why didn't that occur to me??
        It happens to me all the time...

        Comment

        Working...
        X