Announcement

Collapse
No announcement yet.

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.

        http://www.ninjatrader.com/support/f...ead.php?t=4991
        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 Currandeny, Today, 05:32 AM
          0 responses
          1 view
          0 likes
          Last Post Currandeny  
          Started by pjsmith, Today, 01:00 AM
          1 response
          10 views
          0 likes
          Last Post NT-Roland  
          Started by alejandro888, Yesterday, 08:41 PM
          0 responses
          9 views
          0 likes
          Last Post alejandro888  
          Started by UltraNIX, Today, 02:14 AM
          0 responses
          5 views
          0 likes
          Last Post UltraNIX  
          Started by augustfay, Yesterday, 12:06 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_Jason  
          Working...
          X