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 poplagelu, Today, 05:00 AM
          0 responses
          3 views
          0 likes
          Last Post poplagelu  
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,407 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by Shai Samuel, 07-02-2022, 02:46 PM
          4 responses
          98 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          8 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          160 views
          0 likes
          Last Post loganjarosz123  
          Working...
          X