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

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 itrader46, Today, 09:04 AM
        0 responses
        3 views
        0 likes
        Last Post itrader46  
        Started by timmbbo, Today, 08:59 AM
        0 responses
        1 view
        0 likes
        Last Post timmbbo
        by timmbbo
         
        Started by bmartz, 03-12-2024, 06:12 AM
        5 responses
        33 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by Aviram Y, Today, 05:29 AM
        4 responses
        14 views
        0 likes
        Last Post Aviram Y  
        Started by algospoke, 04-17-2024, 06:40 PM
        3 responses
        28 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X