• 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 shs232, Today, 10:02 AM
          0 responses
          3 views
          0 likes
          Last Post shs232
          by shs232
           
          Started by cary1267, Today, 09:37 AM
          0 responses
          5 views
          0 likes
          Last Post cary1267  
          Started by kattiehowe, Today, 09:01 AM
          0 responses
          9 views
          0 likes
          Last Post kattiehowe  
          Started by Irukandji, Yesterday, 06:24 AM
          10 responses
          74 views
          0 likes
          Last Post neoikon
          by neoikon
           
          Started by malcolm, Today, 08:07 AM
          0 responses
          7 views
          0 likes
          Last Post malcolm
          by malcolm
           
          Working...
          X