Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Lag between the indicator and the price bars.

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

    #16
    Hi,

    I'm experiencing the same (or similar) problem. The situation is the following:

    - NT 8 v 8.0.26.1 64-bit
    - Two dataseries in a strategy. The secondary dataserie was added using AddDataSeries() as shown in the languaje reference
    - First dataseries: CL 12-22 ; Secondary dataseries: GC 12-22
    - In the chart there are both instruments added: CL in panel 1 and GC in panel 2
    - Manually I added an SMA(30) to both instruments
    - In the strategy I added the sames SMAs(30) to both sataseries. The SMA for the first dataseries (CL 12-22) plots just over the SMA manually added to the chart, but there are not coincidence between the SMAs for the secondary dataseries (GC 12-22). In the beginnig of the chart (leftmost candles), the SMAs for the secondary dataseries are plotted exactly one over the other, but as long as you move to the right (later candles) the SMA added by script starts to stretch to the right. Both SMAs (added manually to the chart and added by script) has the same period of 30 candles.

    This is the coded where I added the SMAs:

    if (State == State.SetDefaults)
    {
    if (State == State.DataLoaded)
    {
    SMA_DS_1 = SMA(BarsArray[0], 30);
    AddChartIndicator(SMA_DS_1);
    ChartIndicators[0].Panel = 0;

    SMA_DS_2 = SMA(BarsArray[1], 30);
    AddChartIndicator(SMA_DS_2);
    ChartIndicators[1].Panel = 1;

    }
    ...

    See the attached screens. The first one shows the beginning of the chart (leftmost candles) and the second one shows where the added SMA by script is out of sync.

    Any suggestions?

    Thanks in advance,
    Javier
    Attached Files

    Comment


      #17
      Hello Javier,

      AddChartIndicator() does not work with added series.

      From the help guide.
      "Notes
      An indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same AddDataSeries() call included as well)
      o If a secondary or null Bars series is specified by the calling strategy (not the indicator itself), the strategy's primary series will be substituted instead.​"


      This means if you want an indicator to plot based a secondary series, you need to add the secondary series to the indicator directly, as well as the strategy, and then set the plot values on each primary bar to the value calculated from the secondary series.

      Below is a link to an example.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Yes, you are right. I dind't remembered it.

        So the question is:

        If I do not add the indicator to the chart, but I use it in the code, will the indicator values be synched to the secondary instrument added manually to the chart? (I could verify it visually, also adding the indicator manually to the chart and verifying the logic of the entries).

        Thanks ChelseaB.

        Comment


          #19
          Hello Javier,

          The indicator does not use any secondary chart bars manually applied to a chart directly. Only the primary is used by the indicator.

          The AddDataSeries() calls will pull the same historical cached data and will update with the same instrument thread, similar to if two charts are open to the same instrument and bar type.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hi ChelseaB,

            Yes, I understand this. I think I couldn't express correctly my question.

            The indicator doesn't use the secondary chart bars manually applied to a chart, but the code adds the secondary dataseries, and also instantiates an indicator that uses that secondary dataseries.

            The question is: the instantiated indicator (that uses the secondary dataseries) will work OK, so the entries will be correct (according to the logic of the strategy) even though the indicator is not added to the chart by code? (this could be verified adding the same indicator to the chart and verifying visually that the entries are correct)

            Is that correct?

            Thanks,
            Javier

            Comment


              #21
              Hello Javier,

              Yes, the expectation is that any indicator that calls AddDataSeries() will load the data series and the data will be available in OnBarUpdate().
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Excellent ChelseaB. Thanks a lot.

                Javier

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by JonesJoker, 04-22-2024, 12:23 PM
                6 responses
                32 views
                0 likes
                Last Post JonesJoker  
                Started by GussJ, 03-04-2020, 03:11 PM
                12 responses
                3,239 views
                0 likes
                Last Post Leafcutter  
                Started by AveryFlynn, Today, 04:57 AM
                0 responses
                5 views
                0 likes
                Last Post AveryFlynn  
                Started by RubenCazorla, 08-30-2022, 06:36 AM
                3 responses
                79 views
                0 likes
                Last Post PaulMohn  
                Started by f.saeidi, Yesterday, 12:14 PM
                9 responses
                25 views
                0 likes
                Last Post f.saeidi  
                Working...
                X