Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 funk10101, Yesterday, 09:43 PM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by TheWhiteDragon, 01-21-2019, 12:44 PM
      5 responses
      551 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by rtwave, 04-12-2024, 09:30 AM
      5 responses
      37 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by funk10101, Today, 12:02 AM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by GLFX005, Today, 03:23 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Erick  
      Working...
      X