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

update main series indicator from secondary tick series?

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

    update main series indicator from secondary tick series?

    I would like to create a strategy with intra bar granularity in backtests+optimizations which updates indicators as if it was running OnEachTick

    I have a secondary single-tick data series running, and have tried feeding the Closes[0] and also the Closes[1] to the indicators, but they are plotting quite differently depending on which series I feed them.

    I'm attaching an example script. You can see, for example, when using a 1000 tick bar for the main series, the plots show up quite differently.

    One idea I've had to achieve the OnEachTick behavior would be to use a local Series<double> which updates the most recent index from the tick series, but keeps the previous index set when the main bar closes.

    I'm unsure how to manage when indices get added to the local Series variable. In the approach I'm thinking of here, they would only be added once per bar of the main series.


    What is the recommended way of getting indicator calculations in a multi series strategy running OnBarClose to match those of a single series strategy running OnEachTick?

    Thank you.

    Attached Files

    #2
    Hello _bxdf_, thanks for your post.

    From the help guide page on AddChartIndicator() there is a note on multi series strategies:

    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)
    This means that the TRIX indicator needs to be modified to add the 1 tick series and calculate itself based on the 1 tick series rather than the primary series. Since you are using the TRIX indicator for Closes[0] already, you must make a copy of TRIX and use both versions in the strategy.

    Our colleague Kate made an example of doing this here:
    https://ninjatrader.com/support/foru...a-series-chart

    Please let me know if i can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello Chris, thanks for your quick reply. I studied the thread you linked.

      I think that I have a different issue than that thread is addressing. Whereas Kate worked through how to plot a different timeframe than the main series, I would like to calculate the same as the main series, but to have it update per-tick (as it behaves in Calculate.OnEachTick) so that backtests have intra-bar granularity and so the indicator values update continuously throughout the main bar using Calculate.OnBarClose.

      I don't mind if the indies are hidden from rendering, for what it's worth.

      I modified a TRIX as is demonstrated in Kate's other thread, and it's plotting the same curves that the panel 3 TRIX (which has Closes[1] as the series argument) does.
      What I'm looking for are the curves of the first TRIX...


      After that, I partially worked out how to run the indicator on a custom local Series<double>, And the TRIX plots the right curves (please see the panel 4 TRIX in the attached example). However, I am currently getting out-of-bounds exceptions when I access the series.

      Would you please have a look at my example code, and check the commented out print statements as well as the BarsInProgress == 1 update of the mainToTickCloses[0] = Close[0] there? Is this an inappropriate approach to getting the intra-bar granularity?

      Thanks again for your help.
      Attached Files
      Last edited by _bxdf_; 02-01-2021, 01:39 PM.

      Comment


        #4
        I misspoke in my previous post regarding the panel numbers, excuse me.

        The modified TRIX plots in panel 5.

        The TRIX on the custom series plots in panel 4.

        Comment


          #5
          Hello _bxdf_, thanks for your reply.

          We have an example here demonstrating how to sync a DataSeries object to a secondary series:
          https://ninjatrader.com/support/help...series_obj.htm

          Another solution would be to run the strategy and indicator OnEachTick, then you can filter out the OnBarClose logic from the OnEachTick logic by using the IsFirstTickOfBar property. We also have a pre made example demonstrating here:

          https://ninjatrader.com/support/help...either_cal.htm

          Please let me know if I can assist any further.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Hi again Chris,

            I took a look at the link on synchronizing the data series and secondary bars.
            I am able to print the series values and see that they sync between the primary and secondary series (there are tick or so differences at times, but I assume that this is because of the order of operations between series and that filtering with IsFirstTickOfBar can smooth this out).

            I can plot an indicator on the custom series, however it is not changing per tick update, only on the primary series close.

            Additionally, if I attempt to access the indicator values running on the custom series, it errors out, and the plots disappear. Looks like a NAN result.
            This is puzzling to me since the values are clearly plotted at the correct levels without accessing them in script.

            I also started looking into the Update() method in indicator properties, but the TRIXUpdate indicator I've modified is causing an error when the modified indicator is instanced.



            I'm attaching the test scripts I have so far. Is there a caveat with using a custom Series<double> as the input to an indicator?

            Thanks
            Attached Files

            Comment


              #7
              Hello _bxdf_, thanks for your reply.

              I apologize but I will not be able to review or debug any custom script. I attached a simple example that is updating the indicator on each tick. Can you run this on your system and test? Notice any differences between what your script is doing and the attached test script.

              I look forward to assisting.
              Attached Files
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Thanks for the example.

                I've incorporated the structure from it, and can access the indicator data per tick.

                However, I'm still having an issue that I mentioned in my first post in the thread here.

                I have a secondary single-tick data series running, and have tried feeding the Closes[0] and also the Closes[1] to the indicators, but they are plotting quite differently depending on which series I feed them
                Note, at this point I have added an internal secondary series to the indicator, and am running the indicator calculations in BarsInProgess == 1, both from the host strategy, and internally within the indicator.

                Please see my attached screenshot to see how the plots are different.

                Click image for larger version

Name:	singleTickDifferences.PNG
Views:	292
Size:	127.7 KB
ID:	1139578
                Attached Files

                Comment


                  #9
                  Hello _bxdf_, thanks for your reply.

                  If you feed in the primary series to the indicator then it will only update the indicator with the OHLC of each bar of the primary series, so I would expect these to be different. Print out the value of the indicator on each OnBarUpdate call and you will see different time stamps for each data point, and you will also see the single tick indicator updating more often.

                  Please let me know if I can assist any further.
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    Maybe I can more clearly explain what I want to do.

                    If you run an indicator or strategy OnEachTick on realtime data, the current indicator values constantly adjust to the current close.

                    I have a strategy that is dependent on certain thresholds of the current readings. This strategy does not reproduce its live results in Backtests and Optimizations because there is a lack of intrabar granularity. I am trying to get the optimizer to take account of the OnEachTick fluctuations.

                    I agree that using different input series would be expected to produce different results. However! If you load an indicator twice, and set one to run OnBarClose, the other OnEachTick, you'll see that they *DO* produce the same curves, but that the OnEachTick is constantly updating.

                    Please see the attached screenshot.
                    How do I get this real-time OnEachTick behavior with the little wiggle at the right side of the chart to happen with the Optimizer??Click image for larger version

Name:	barVsTickCurrentValueDifference.PNG
Views:	243
Size:	119.6 KB
ID:	1139721

                    Comment


                      #11
                      Hello _bxdf_, thanks for your reply.

                      Have you tried turning on Tick Replay? Go to Tools>Options>Market Data and enable Show Tick Replay, then enable it in the Data Series window and reload the historical data. Do you get different results?

                      https://ninjatrader.com/support/help...ick_replay.htm

                      I look forward to assisting.
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Yes, I've run back tests with Tick Replay enabled. Is it really supposed to be a realistic simulation for OnEachTick?

                        The very diagonal equity curves in the attached screenshots are from Tick Replay back tests, whereas live performance looks more like the screenshot of the arched/jagged equity curve
                        Attached Files

                        Comment


                          #13
                          Hello _bxdf_, thanks for your reply.

                          The order fill procedure is still being performed on the primary series. Tick Replay will have no effect on order fills. You must fill your orders upon the 1 tick series like in this example on backtesting intrabar strategies:

                          https://ninjatrader.com/support/help...ipt_strate.htm

                          Please let me know if this does not resolve your inquiry.
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Chris, thanks for continuing the discussion.

                            I am still getting discrepancies in the back tests.

                            I ran the strategy real-time overnight after I modified the entries in the strategy to be the following:

                            currentLimitOrderShort = EnterShortLimit(1, true, 1, limitPrice, "Maranello Short Entry " + entryCount);

                            currentLimitOrderLong = EnterLongLimit(1, true, 1, limitPrice, "Maranello Long Entry " + entryCount);

                            And then I ran a backtest over the same hours.


                            When using Tick Replay, is it necessary to access indicator outputs in the tick series? The example script does everything from the primary series.

                            *Edit* I just realized that the real-time was run on NQ, and I did the back test on MNQ. Re-running right now..
                            Last edited by _bxdf_; 02-04-2021, 05:28 PM.

                            Comment


                              #15
                              Here are the back test and real time performance,

                              note, In the backtest equity curve, trade 41 is the start of the real time curve.

                              Back test:

                              Click image for larger version

Name:	MaranelloSettings1CurveBACKTEST.PNG
Views:	234
Size:	169.1 KB
ID:	1140103


                              Real time:

                              Click image for larger version

Name:	MaranelloSettings1Curve.PNG
Views:	225
Size:	104.2 KB
ID:	1140104

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by fx.practic, 10-15-2013, 12:53 AM
                              5 responses
                              5,403 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by Shai Samuel, 07-02-2022, 02:46 PM
                              4 responses
                              94 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by DJ888, Yesterday, 10:57 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by MacDad, 02-25-2024, 11:48 PM
                              7 responses
                              158 views
                              0 likes
                              Last Post loganjarosz123  
                              Started by Belfortbucks, Yesterday, 09:29 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post Belfortbucks  
                              Working...
                              X