• 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 dmking, Today, 08:09 AM
      0 responses
      2 views
      0 likes
      Last Post dmking
      by dmking
       
      Started by reedstickets, Today, 08:00 AM
      0 responses
      2 views
      0 likes
      Last Post reedstickets  
      Started by siroya, Today, 07:16 AM
      2 responses
      4 views
      0 likes
      Last Post siroya
      by siroya
       
      Started by Boonfly8, Today, 07:17 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by liltr3d, Yesterday, 10:52 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Working...
      X