• 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

Retaining a value defined on a previous bar

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

  • arbuthnot
    started a topic Retaining a value defined on a previous bar

    Retaining a value defined on a previous bar

    Hi everyone

    With a bool, you can keep a logical value that remains valid from one bar to the next.

    What I’d like to do, if possible, is to do roughly the same for a value.

    Let’s say I define certain conditions (probably for order entry but not necessarily) and I define a value by

    Code:
    double a = Close[0];
    How can I keep the value of ‘a’ through the next n bars (until I wish it to be discarded) without it being redefined from bar to bar? In this way, I would have access to the value ‘a’ on the current bar even though it was defined, say, 5 bars ago.

    Much obliged in advance with any help with this.
    Last edited by arbuthnot; 04-26-2014, 03:44 PM. Reason: incorrrect spelling

  • NinjaTrader_CalH
    replied
    Hello Arbuthnot,

    Thank you for your post and for Sledge on answering

    Sledge's example should work for your purposes.

    Let us know if we can be of further assistance

    Leave a comment:


  • sledge
    replied
    Originally posted by arbuthnot View Post
    Hi everyone

    With a bool, you can keep a logical value that remains valid from one bar to the next.

    What I’d like to do, if possible, is to do roughly the same for a value.

    Let’s say I define certain conditions (probably for order entry but not necessarily) and I define a value by

    Code:
    double a = Close[0];
    How can I keep the value of ‘a’ through the next n bars (until I wish it to be discarded) without it being redefined from bar to bar? In this way, I would have access to the value ‘a’ on the current bar even though it was defined, say, 5 bars ago.

    Much obliged in advance with any help with this.
    Assuming 0.0 isn't valid (or you could use a negative #)...

    if a=0.0
    then
    //it's been cleared and needs reset
    a = close[0];

    end if;

    if a!= 0.0
    then
    //a has a valid value

    end if;

    or you could make another variable boolean that has whether or not A has been set (true) or needs to be set because it is new or has been cleared out of value.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by ushjkaybbaa, Today, 10:48 AM
0 responses
3 views
0 likes
Last Post ushjkaybbaa  
Started by chartish, Today, 10:33 AM
0 responses
7 views
0 likes
Last Post chartish  
Started by cpabiz20k, Today, 10:00 AM
2 responses
9 views
0 likes
Last Post cpabiz20k  
Started by rickyblah12, Today, 09:34 AM
1 response
4 views
0 likes
Last Post NinjaTrader_PatrickG  
Started by CaptainAmericaXX, Today, 09:05 AM
3 responses
13 views
0 likes
Last Post CaptainAmericaXX  
Working...
X