Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MT Programmer new to NT, tips please?

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

    #16
    Originally posted by DerkWehler View Post
    Ok, I understand that, and have this setting:

    base.set_CalculateOnBarClose(true);

    So, calculating from the left, and it is on the 5th bar from the left at the moment, base.Close[0] refers to the close price of the current (5th from left) bar then?

    And base.Typical[1] refers to the previous (4th bar from left) bar's typical price, (high + low + close) / 3 ? Or does it refer to the 6th bar from the left?
    You may be overthinking this, and Bertrand certainly did not help (what he says is right, but that is because he adopted your thinking mode in answering the question).

    CurrentBar will always be the left-most bar, because the bars are indexed backwards. So an index of 0 is always the right-most bar and an index of CurrentBar (monotonically increasing as the chart streams) will always be the left-most bar. To put it more simply, for the question that you asked: no, Close[0] is the Close of the last bar or penultimate bar, depending on the COBC setting. The close of the 5th bar from the right is always Close[5]. Just use the index to refer to the correct bar.

    If you are using a calculation that uses the historical stream, then at each bar, the index will be increased. so each bar in turn in the stream will be represented by 0, until the stream is complete.

    Comment


      #17
      Originally posted by koganam View Post
      You may be overthinking this, and Bertrand certainly did not help (what he says is right, but that is because he adopted your thinking mode in answering the question).

      CurrentBar will always be the left-most bar, because the bars are indexed backwards. So an index of 0 is always the right-most bar and an index of CurrentBar (monotonically increasing as the chart streams) will always be the left-most bar. To put it more simply, for the question that you asked: no, Close[0] is the Close of the last bar or penultimate bar, depending on the COBC setting. The close of the 5th bar from the right is always Close[5]. Just use the index to refer to the correct bar.

      If you are using a calculation that uses the historical stream, then at each bar, the index will be increased. so each bar in turn in the stream will be represented by 0, until the stream is complete.
      Koganam:

      Thank you for the post, but now I need to make sure I have it correct, so let me state my understanding with an example:

      For this we will still assume CalculateOnBarClose = true.

      For the ind to draw on the chart, OnBarUpdate() gets called once for each bar, from left to right. So lets assume for the moment that it is working on the 2nd bar (the one just to the right of the left-most bar). Then base.Close[0] is the close price of that bar, and base.Close[1] is the close price of the left-most bar. When it moves one more to the right, base.Close[0] is the close price of THAT bar, and base.Close[2] is the close price of the left-most bar.

      Good so far?

      While on the second bar, CurrentBar == 1, right? And on the next one, CurrentBar == 2, so Current bar tells you how many bars you are away from the left-most bar.

      That all correct? :-)

      Thank you,
      -Derk

      Comment


        #18
        Originally posted by DerkWehler View Post
        Koganam:

        Thank you for the post, but now I need to make sure I have it correct, so let me state my understanding with an example:

        For this we will still assume CalculateOnBarClose = true.

        For the ind to draw on the chart, OnBarUpdate() gets called once for each bar, from left to right. So lets assume for the moment that it is working on the 2nd bar (the one just to the right of the left-most bar). Then base.Close[0] is the close price of that bar, and base.Close[1] is the close price of the left-most bar. When it moves one more to the right, base.Close[0] is the close price of THAT bar, and base.Close[2] is the close price of the left-most bar.

        Good so far?

        While on the second bar, CurrentBar == 1, right? And on the next one, CurrentBar == 2, so Current bar tells you how many bars you are away from the left-most bar.

        That all correct? :-)

        Thank you,
        -Derk
        Absolutement! If I may wax French for a bit.
        Last edited by koganam; 08-09-2012, 05:37 AM.

        Comment


          #19
          YAQ (yet another questions)

          Given that my class is call MyFirstInd, and this code in my OnBarUpdate() :

          protected override void OnBarUpdate()
          {
          double item;
          double num;
          double num1;
          MyFirstInd myFirstInd = this;
          if (base.CurrentBar == 0)
          {
          item = base.Close[0];
          }
          else
          {
          item = base.Close[0] * 0.2 + 0.8 * base.Close[1];
          }
          myFirstInd.gEMA = item;

          if (base.CurrentBar != 0)
          {
          double num2 = 0;
          for (int i = Math.Min(base.CurrentBar, this.CCILength - 1); i >= 0; i--)
          {
          num2 = num2 + Math.Abs(base.Typical[i] - base.SMA(base.Typical, this.CCILength)[0]);
          }
          MyFirstInd myFirstInd2 = this;
          double item1 = base.Typical[0] - base.SMA(base.Typical, this.CCILength)[0];
          if (num2 == 0)
          {
          num = 1;
          }
          else
          {
          num = 0.015 * num2 / (double)Math.Min(this.CCILength, base.CurrentBar + 1);
          }
          myFirstInd2.gCCI = item1 / num;
          }
          ...
          }

          I do nor understand why the new instances were created (myFirstInd, & myFirstInd2).

          They are never reference after that code. Doesn't it seem that it would have been better (equivalent) to do it this way:


          protected override void OnBarUpdate()
          {
          double item;
          double num;
          double num1;
          //MyFirstInd myFirstInd = this; // removed
          if (base.CurrentBar == 0)
          {
          item = base.Close[0];
          }
          else
          {
          item = base.Close[0] * 0.2 + 0.8 * base.Close[1];
          }
          this.gEMA = item; // changed

          if (base.CurrentBar != 0)
          {
          double num2 = 0;
          for (int i = Math.Min(base.CurrentBar, this.CCILength - 1); i >= 0; i--)
          {
          num2 = num2 + Math.Abs(base.Typical[i] - base.SMA(base.Typical, this.CCILength)[0]);
          }
          //MyFirstInd myFirstInd2 = this; // removed
          double item1 = base.Typical[0] - base.SMA(base.Typical, this.CCILength)[0];
          if (num2 == 0)
          {
          num = 1;
          }
          else
          {
          num = 0.015 * num2 / (double)Math.Min(this.CCILength, base.CurrentBar + 1);
          }
          this.gCCI = item1 / num; // changed
          }
          ...
          }


          Any ideas why the original author declared new MyFirstIn, only to set = this, and then set one member variable, rather than do it the latter way?

          -Derk

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          579 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X