Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

intra-bar/inter-tick variable persistance ?

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

    intra-bar/inter-tick variable persistance ?

    Another amibroker-ish question.

    AFL has no intra-bar 'memory'. Ie, it recalculates every bar from the begining of the series every tick. This isn't an issue with daily or bar-close indicators, but it sure is an issue in R/T as new intra-bar ticks can move your indicator all over the place

    How is this handled in NinjaScript. ?
    For example,
    ie
    1) if x = true then do something
    2) x = close> sma(9)

    Tick1
    - x is false the 1st tick into the bar and statement 1 does not branch out.
    - Statement 2 is executed and sets it to be true.
    Tick 2
    - Will x remain set for the next tick/pass ?

    #2
    imported post

    Hmm not sure I follow. Since NinjaScript basically is C#, the livetime concepts of C# for variables do apply.

    a) Any class variable you defined in your strategy (see "Variables" region) is persisted as long as the strategy is running.

    b) If you define a varoiable within the scope of the OnBarUpdate method then it's not persisted as you processed the current tick and returned from the OnBarUpdate method.

    Comment


      #3
      imported post

      Here are examples to illustrate what Dierk was stating.With example 1, x is preserved from tick to tick. Example 2 likely behaves like AFL where x is not preserved from tick to tick.



      Example 1:
      private bool x = false;

      OnBarUpdate()
      {
      if (x)
      // Do something

      x = close > SMA(9)[0]
      }


      Example 2:
      OnBarUpdate()
      {
      bool x = false;

      if (x)
      // Do something

      x = close > SMA(9)[0]
      }
      RayNinjaTrader Customer Service

      Comment


        #4
        imported post

        Thanks Dierk and Ray!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        579 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X