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

Accessing a variable from strategy

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

    Accessing a variable from strategy

    After reading the relevant articles, I wish to make sure the following are correct:

    - If I need a collection of values that always has the same length as bars on chart, I better use one of the Series type collections.

    - When using any of the built-in Series collections, OnBarUpdate is executed automatically when accessing the Series variable from a strategy.

    - If I need a collection that does not hold the same amount of values as bars on chart, I can freely do so with generic lists (for example).

    - If I need to access a collection variable (which is not a Series type variable) from a strategy, I can do so but I will have to add Update() to the variable get property in order to explicitly execute OnBarUpdate() because it won't be called automatically.

    #2
    For what you say here, It really depends on if you use CalculationOnBarClose = true or false.

    With true, OnBarUpdate() is called on each close of a bar even for historical data so a list would have the same number of elements as bars on a chart.

    OnBarUpdate() isn't called automatically when accessing series, it only depends on the bars and COBC setting.

    Update() just forces an OnBarUpdate() call, so it would depend on if you need to do this or not. I.e. it would ensure you are getting the most recent calculations as output.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Damn. I thought I got it.

      Bottom line, I have an indicator which calculates values and saves them to a List<double>. The amount of values in the collection is not correlated to the number of bars on the chart so I guess using IDateSeries collection is not the solution here. Correct?

      Second, I want to access that List<double> from a strategy. OBU needs to be executed for the List<double> to be created and hold values. What should I do?

      Comment


        #4
        savekad,

        Whenever you call an indicator like EMA(0).Value[0] it will automatically be calling the OnBarUpdate() method under the hood so to speak. There is generally no need to use the "Update()" method unless you want to ensure that you have the most recent calculation for something, such as if it calculates tick-by-tick.

        Using a dataseries would be the easiest way to access the data you need. You can still use a list internally, but expose the values using a dataseries, such as in the following reference sample.

        Adam P.NinjaTrader Customer Service

        Comment


          #5
          I've managed to get it to work only by including a call to Update().
          I think the OBU invoked only when accessing a IDataSeries variable.
          In my case, I tried to access a List<double> variable.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,227 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          7 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          440 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          12 views
          0 likes
          Last Post FAQtrader  
          Working...
          X