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 aligator, 01-06-2022, 12:14 PM
    4 responses
    233 views
    0 likes
    Last Post john_44573  
    Started by reynoldsn, Today, 05:56 PM
    0 responses
    4 views
    0 likes
    Last Post reynoldsn  
    Started by bortz, 11-06-2023, 08:04 AM
    51 responses
    1,989 views
    0 likes
    Last Post aligator  
    Started by dmking, 11-12-2019, 12:31 PM
    4 responses
    4,150 views
    0 likes
    Last Post jasonw
    by jasonw
     
    Started by roblogic, Today, 04:31 PM
    0 responses
    10 views
    0 likes
    Last Post roblogic  
    Working...
    X