Announcement

Collapse
No announcement yet.

Number of bars to calculate study

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

  • Number of bars to calculate study

    I thought I understood how this works, but apparently I do not. I am running a study in Playback mode that has two indicator values that are used. One is Stoch(10,3,3), and the other is CCI(34). I obtain the values of these indicators using:

    var study2 = new CCIStudy(34, "HLC/3");
    var study3 = new stochK(10, 3, 3);

    then

    study2.getValue(CCIStudy.CCI, 0);
    study3.getValue(0);


    Both of these return null values for several more bars than I was expecting. The Stoch study returns null until the beginning of the 20th bar, and the CCI study returns null until the beginning of the 100th bar. I thought I was expecting 10 and 34 bars respectively.

    The values returned are correct, just the lookback period is strange.

    Any suggestions?

  • #2
    Hello hmmerritt,

    There will be a certain number of bars required before the first valid return can be calculated. This number of bars depends on the algorithm of the particular study. It is not always going to be a number of bars that directly corresponds to one of the study inputs.

    In formula development, it may be required, depending on the specific formula logic that all the indicators used have been primed before processing trade logic or calculating other values based on the indicators. In this case, you should perform a null check on the current value of the indicators as in the example below.

    PHP Code:
    function preMain() {
        
    //setPriceStudy(true);
        
    setStudyTitle("example");
        
    setCursorLabelName("stochK"0);
        
    setCursorLabelName("cci"1);
    }

    var 
    x1 null;
    var 
    x2 null;

    function 
    main() {
        if (
    x1 == nullx1 stochK103); 
        if (
    x2 == nullx2 cci34hlc3() ); 
        
        var 
    n1 x1.getValue(0);
        var 
    n2 x2.getValue(0);
        if (
    n1 == null || n2 == null) return;  // null check
        
        
    return new Array(n1n2);

    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