• 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 uiwislth, Yesterday, 11:25 PM
      0 responses
      4 views
      0 likes
      Last Post uiwislth  
      Started by Steve L, Yesterday, 10:04 PM
      0 responses
      3 views
      0 likes
      Last Post Steve L
      by Steve L
       
      Started by marianfed, Yesterday, 09:47 PM
      0 responses
      4 views
      0 likes
      Last Post marianfed  
      Started by hir04068, Yesterday, 09:29 PM
      0 responses
      2 views
      0 likes
      Last Post hir04068  
      Started by iq200, 03-11-2018, 07:49 PM
      24 responses
      1,018 views
      0 likes
      Last Post mrlucky1x  
      Working...
      X