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 cmoran13, 04-16-2026, 01:02 PM
        0 responses
        43 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        25 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        162 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        98 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        158 views
        2 likes
        Last Post CaptainJack  
        Working...
        X