• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NBarsUp Modification

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

    NBarsUp Modification

    Can you tell me why this code is not correctly counting the # of up bars? I'm trying to follow the logic before modifying it. Thanks in advance!

    protected override void OnBarUpdate()
    {
    int BarsupCnt;

    BarsupCnt = 0;
    //Barup = false;

    if (CurrentBar < BarCount)
    {
    Value[0] = 0;
    }
    else
    {
    bool gotBars = false;

    Print(Time[3].ToString() + " 3 close " + Close[3]);
    Print(Time[3].ToString() + " 3 open " + Open[3]);
    Print(Time[2].ToString() + " 2 close " + Close[2]);
    Print(Time[2].ToString() + " 2 open " + Open[2]);
    Print(Time[1].ToString() + " 1 close " + Close[1]);
    Print(Time[2].ToString() + " 1 open " + Open[1]);
    Print(Time[0].ToString() + " 0 close " + Close[0]);
    Print(Time[0].ToString() + " 0 open " + Open[0]);

    for (int i = 0; i < BarCount + 1; i++)
    {
    if (i == BarCount)
    {
    gotBars = true;
    break;
    }

    if ((Close[i] > Open[i]))
    {
    BarsupCnt = BarsupCnt + 1;
    }

    Print("BarsupCnt: " + BarsupCnt);

    }

    Value[0] = gotBars ? 1 : 0;
    }
    }

    #2
    NBarsUp Modification

    Hello GibbsB613,

    Thanks for writing in to our Support team.

    You are setting your BarsupCnt = 0 each time OnBarUpdate() is called. You will want to define this variable outside of the OnBarUpdate() method so it is only changing with respect to your logic defined in your else condition.

    Please let me know if I may be of any further assistance.
    Alan S.NinjaTrader Customer Service

    Comment


      #3
      Just so I understand this clearly:

      1. Once that last bar closes, isn't onbarupdate only being called once?
      2. Were you able to test your recommendation?

      Thanks!!

      Comment


        #4
        Hello GibbsB613,

        Thanks for your reply.

        1. OnBarUpdate is called for every bar in the collection. Your code sets the variable to 0 on every bar. You then attempt to increment the value if the Close is greater than the Open. So your only possible values are 1 or 0 at any time. This code will never increment to a full count of the up bars as is.

        2. The logic you are using is flawed at the basic level of assigning values. Testing our suggestion would be to test basic programming concepts.

        Please let me know if you have any questions.
        Alan S.NinjaTrader Customer Service

        Comment


          #5
          Ok, I'll give it a try. My expectation was that once the bar closed it would run once and only reset the variable to zero once.

          Thanks!!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Dert66, Today, 12:11 PM
          0 responses
          5 views
          0 likes
          Last Post Dert66
          by Dert66
           
          Started by jjanguda, Today, 10:04 AM
          0 responses
          177 views
          0 likes
          Last Post jjanguda  
          Started by sambo81, Today, 09:20 AM
          1 response
          12 views
          0 likes
          Last Post sambo81
          by sambo81
           
          Started by TopGunNote, 05-14-2019, 01:12 PM
          3 responses
          78 views
          0 likes
          Last Post dpaulw
          by dpaulw
           
          Started by Grano, Today, 06:07 AM
          0 responses
          6 views
          0 likes
          Last Post Grano
          by Grano
           
          Working...
          X