No announcement yet.

Query re Series object in highest()/lowest functions

  • Filter
  • Time
  • Show
Clear All
new posts

  • Query re Series object in highest()/lowest functions


    I have the following series object defined in my script

             xFT_P2 = efsExternal(Fisher_Trend.efs, RangePeriods * P2_Factor, PriceSmoothing_P2, IndexSmoothing_P2, Point_P2);
      binit = true
    Later in the code, I try to create a series of the last 20 values of this indicator.
    (I am only interested in the lowest of the 20 values in the series.)

       var lowest_FT_20 = lowest(20, xFT_P2);  // ERROR: This returns NaN - Why?
       // These lines return the first four values of the series as expected
        nFT_P2 = xFT_P2.getValue(0);  
        nFT_P2_1 = xFT_P2.getValue(-1);
        nFT_P2_2 = xFT_P2.getValue(-2);
        nFT_P2_3 = xFT_P2.getValue(-3);
    From the KB

    lowest( nLength [, Series | sym() | inv() ][, nBarIndex ] )

    //create a Series Object of the lowest value from sma(20).
    var xSeries = lowest(10, sma(20));

    Return Value(s)
    Returns a Series Object when nBarIndex is not specified.
    Returns a single value when nBarIndex is specified.

    I have used this function as well as the highest() function in my code to retrieve the OHLC for various bar counts.
    I have found that in those cases, the variable xSeries equals one value and not a series.

        var Lowest_Low_Last_5 = lowest(5, low());  // returns single value representing the lowest low for the current bar and the next 4 bars.
    // If a series is returned, then obtain the values using the getValue method.
        var lowest_low_0 = Lowest_Low_Last_5.getValue(0); // returns same value as var Lowest_Low_Last_5
        var lowest_low_1 = Lowest_Low_Last_5.getValue(-1); 
        var lowest_low_2 = Lowest_Low_Last_5.getValue(-2);
        var lowest_low_3 = Lowest_Low_Last_5.getValue(-3);
        var lowest_low_4 = Lowest_Low_Last_5.getValue(-4);
    Below are the values returned for the above code;
    Since these functions (highest and lowest) are supposed to return a series, I thought the 5 values are returned from lowest to highest, but apart from lowest_low_0 which equals Lowest_Low_Last_5, subsequent values returned seem to continue on past the nth bar.

    My theory is that the subsequent values are assigned a different value as long as the related bar makes a new low. This would explain why lowest_low_4 = lowest_low_3.

    Lowest_Low_Last_5: 0.80644
    Lowest_Low_Last_10: 0.80493
    Lowest_Low_Last_15: 0.80493

    lowest_low_0: 0.80644 // Lowest_Low_Last_5
    lowest_low_1: 0.80569 // = low(-5) from list below
    lowest_low_2: 0.80537 // = low(-6) from list below
    lowest_low_3: 0.80493 // = low(-7) from list below
    lowest_low_4: 0.80493 // = low(-7) from list below

    low(0): 0.80863
    low(-1): 0.80862
    low(-2): 0.80855
    low(-3): 0.80841
    low(-4): 0.80644 // lowest low of last 5 bars = lowest_low_0
    low(-5): 0.80569 // lowest_low_1
    low(-6): 0.80537 // lowest_low_2
    low(-7): 0.80493 // lowest_low_3
    low(-8): 0.80521
    low(-9): 0.80549
    low(-10): 0.8072

    Just to Summarise - my queries are

    1. Is it possible to use the series xFT_P2 within the highest() or lowest() functions?
    2. Do the highest() and lowest() functions return a series or single value when used as above?

    Thank you