• 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

    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

    #2
    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.

    Comment


      #3
      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
      Cal H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by futures2018!, Yesterday, 05:01 PM
      3 responses
      12 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Splex, Today, 12:04 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Jim  
      Started by n8dogg59, Today, 06:55 AM
      0 responses
      3 views
      0 likes
      Last Post n8dogg59  
      Started by Tradarr, Yesterday, 07:13 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_PatrickG  
      Started by unlobotrader, Today, 02:46 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChristopherS  
      Working...
      X