Announcement

Collapse
No announcement yet.

ATR function

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

  • ATR function

    Hello,

    Below is a simple program where I am trying to use ATR9 and ATR26. When I used the print statement, it prints NULL.

    What am I doing wrong? I want to use the current value throughout the code. Sometimes, I will reference the atr9 at previous bars too so I need an array.

    function main() {
    var nNumberBars;
    var nIndex = getCurrentBarIndex();

    nNumberBars = getNumBars();


    if ( (bInit==false) && (nNumberBars != 0) )
    {
    if (atr9 == null) atr9 = atr(9);
    if (atr26 == null) atr26 = atr(26);

    debugPrintln("atr9=",atr9.getValue(0));


    if ((nIndex==0) && (nNumberBars != 0) )
    {
    // my function
    }


    return(currentstrategy+overextension);

    }

  • #2
    This is the pattern you're looking for. Since you need atr26's values too, no need to check atr9 for null returns:

    Code:
    var bInit = false;
    
    var atr9;
    var atr26;
    
    
    function main()
    {
      if (bInit == false)
      {
        atr9 = atr(9);
        atr26 = atr(26);
        bInit = true;
      }
    
      if (atr26 == null) return;
    
      if (isLastBarOnChart())
      {
         // all historical data has been loaded
      }
    }

    Comment

    Working...
    X