Announcement

Collapse
No announcement yet.

getFirstBarIndexOfDay d

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

  • getFirstBarIndexOfDay d

    Hi~

    I am trying to implement getFirstBarIndexOfDay as in the example below, but it does not seem to return the high of the first bar of the current day. Does anyone know what is wrong with this?

    Thanks,
    anarco

    function main() {
    var nState = getBarState();
    var nIndex = getCurrentBarIndex();
    var nBarIndex;
    var nTime;
    var nPrice;
    var aHigh;

    //if (nState == BARSTATE_CURRENTBAR){
    if (nState == BARSTATE_NEWBAR){
    var t1 = volume(0);
    var t1_o = open(0);
    nTime = getValue("rawtime", nIndex);
    debugPrintln(nTime);
    nBarIndex = getFirstBarIndexOfDay( nTime );
    debugPrintln(nBarIndex);
    aHigh =high(nBarIndex);
    debugPrintln(aHigh);



    }

  • #2
    Re: getFirstBarIndexOfDay d

    anarco
    The reason it is not working is because it is missing a } curly bracket to close the conditional statement if (nState == BARSTATE_NEWBAR){
    Once you add the bracket the script will return the appropriate value
    Alex


    Originally posted by anarco
    Hi~

    I am trying to implement getFirstBarIndexOfDay as in the example below, but it does not seem to return the high of the first bar of the current day. Does anyone know what is wrong with this?

    Thanks,
    anarco

    function main() {
    var nState = getBarState();
    var nIndex = getCurrentBarIndex();
    var nBarIndex;
    var nTime;
    var nPrice;
    var aHigh;

    //if (nState == BARSTATE_CURRENTBAR){
    if (nState == BARSTATE_NEWBAR){
    var t1 = volume(0);
    var t1_o = open(0);
    nTime = getValue("rawtime", nIndex);
    debugPrintln(nTime);
    nBarIndex = getFirstBarIndexOfDay( nTime );
    debugPrintln(nBarIndex);
    aHigh =high(nBarIndex);
    debugPrintln(aHigh);



    }

    Comment


    • #3
      Hi~

      I just pasted the section that was relevant. I am not getting any errors, I am simply not getting the correct value. This is the full code.

      Thanks in advance!
      anarco

      function preMain() {
      setPriceStudy(true);
      setStudyTitle("High 15min");
      setShowCursorLabel(true);
      debugClear();
      setComputeOnClose();

      }


      function main() {
      var nState = getBarState();
      var nIndex = getCurrentBarIndex();
      var nBarIndex;
      var nTime;
      var nPrice;
      var aHigh;

      if (nState == BARSTATE_NEWBAR){
      var t1 = volume(0);
      var t1_o = open(0);
      nTime = getValue("rawtime", nIndex);
      debugPrintln(nTime);
      nBarIndex = getFirstBarIndexOfDay( nTime );
      debugPrintln(nBarIndex);
      aHigh =high(nBarIndex);
      debugPrintln(aHigh);



      }


      }

      Comment


      • #4
        anarco
        The reason you are getting an unexpected value is because you are using setComputeOnClose(). When this statement is used the formula engine is actually processing bar index -1 and not bar index 0 so all the bar index references are being displaced by 1 bar. Comment out or delete the setComputeOnClose() statement and you should get the value corresponding to the first bar of the day
        Alex


        Originally posted by anarco
        Hi~

        I just pasted the section that was relevant. I am not getting any errors, I am simply not getting the correct value. This is the full code.

        Thanks in advance!
        anarco

        function preMain() {
        setPriceStudy(true);
        setStudyTitle("High 15min");
        setShowCursorLabel(true);
        debugClear();
        setComputeOnClose();

        }


        function main() {
        var nState = getBarState();
        var nIndex = getCurrentBarIndex();
        var nBarIndex;
        var nTime;
        var nPrice;
        var aHigh;

        if (nState == BARSTATE_NEWBAR){
        var t1 = volume(0);
        var t1_o = open(0);
        nTime = getValue("rawtime", nIndex);
        debugPrintln(nTime);
        nBarIndex = getFirstBarIndexOfDay( nTime );
        debugPrintln(nBarIndex);
        aHigh =high(nBarIndex);
        debugPrintln(aHigh);



        }


        }

        Comment

        Working...
        X