Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

counting variables

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

    counting variables

    Hello,

    how can one count up the value of a variable, but only one time like

    if(Rising(SMA(BarsArray[2],20))) varrising++;
    if(Rising(SMA(BarsArray[3],20))) varrising++;

    so that in total the value of the varrising would be 2 in this case (and not counting up with every new bar)

    if(Falling(SMA(BarsArray[2],20))) varrising--;
    if(Falling(SMA(BarsArray[3],20))) varrising--;

    so that I would have varrising a value of 1 if one of both dataseries is falling.

    OR/AND

    another idea to resolve this is to give a fixed value like

    if(Rising(SMA(BarsArray[2],20))) var2=1;
    if(Rising(SMA(BarsArray[3],20))) var3=1;

    but in this case I dont know how to add up with every bar like

    valuevar = var2 + var3 + .....

    Or could I do this aproach simply with int valuevar = var2 + var3 in onbarupdate?

    So, because of being not a programmer I´m missing a brick with both ideas.


    Thank you
    Tony
    Last edited by tonynt; 07-20-2016, 06:16 AM. Reason: clearifying

    #2
    Hello tonyt, and thank you for your question.

    The most direct answer to your question that I may give, is that you will need to check on the current value of varrising . That is,

    Code:
    [FONT=Courier New]if(Rising(SMA(BarsArray[2],20)) && varrising == 0) varrising++;[/FONT]
    In situations like this however, I find it is better to keep a data structure. That looks like

    Code:
    [FONT=Courier New]private class TrackRising
    {
        public int riseCount = 0;
        public bool hasRisen()
        {
            return riseCount == 0;
        }
    }
    
    private TrackRising tracker = null;
    protected override void OnBarUpdate()
    {
        if (tracker == null)
        {
            tracker = new TrackRising();
        }
        [/FONT][FONT=Courier New]if(Rising(SMA(BarsArray[2],20))) tracker.riseCount++;[/FONT]
    Please let us know if there are any other ways we may help.
    Jessica P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    58 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    39 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    19 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    21 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    51 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X