Announcement

Collapse
No announcement yet.

Series & getValue

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

  • Series & getValue

    Greetings,

    I'd like build one function that recieves one parameter like "SourcePrice" (i.e hl2, hlc3, ...), and returns one array with the complete serie, for educational purposes.
    The code that I have developed doesn't work. Only returns one value.

    Could you help me, please ? Thanks very much.

    PHP Code:
    /************************************************************************
    * Ejemplos para elegir el tipo de precio                                 
    * Los precios posibles son: close open high low hl2 hlc3 ohlc4           
    *************************************************************************/
    function preMain() {

        
    setPriceStudy(false);
        
    setStudyTitle("PriceSource");
        
        var 
    Param1 = new FunctionParameter("sSource",
                              
    FunctionParameter.STRING);
        
    Param1.setDefault("hl2");
    }

    function 
    main(sSource){
        
        if ( 
    sSource == null sSource "hl2";
        
    //I like get one array with ten previous values
        
    var = eval( sSource+"().getValue(0,-10)");
        if ( 
    == null ) return null;

        return new Array( 
    a[0], a[1]); // <<< DON'T WORK !!!


        //var b = getSeries(a); //  <<< That doesn´t work neither


  • #2
    Hello Cls,

    With EFS2 Series Objects, the .getValue() method does not take a number of bars parameter as it is not necessary. Since the EFS2 Series is already an array that contains all the data you just use the .getValue() method to retrieve the specific element of this series (or array) by bar index reference. Try the modified code below. The key is to create a global variable to store the series (see xSeries).

    PHP Code:
    function preMain() {

        
    setPriceStudy(false);
        
    setStudyTitle("PriceSource");
        
        var 
    Param1 = new FunctionParameter("sSource"FunctionParameter.STRING);
        
    Param1.setDefault("hl2");
    }

    var 
    xSeries null;  //add

    function main(sSource) {
        
        if ( 
    sSource == null sSource "hl2";

        if (
    xSeries == nullxSeries = eval( sSource+"()");
        
        var 
    a0 xSeries.getValue(0);
        var 
    a1 xSeries.getValue(-1);
        if ( 
    a1 == null ) return;

        return new Array( 
    a0a1);

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      JasonK, thanks very much. Your answer have been very useful.
      I were confused with "getValue function" and "getValue method".

      Greetings

      Comment


      • #4
        You're most welcome.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment

        Working...
        X