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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        31 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        9 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        18 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        20 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X