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

DateTime in NT8 Two

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

    DateTime in NT8 Two

    Hello,

    In NT7, I use a DateTime structure to reset a trade signal on a daily basis using the Time() syntax as follows:

    protected override void OnBarUpdate()
    {
    if (Time[0].DayOfWeek != Time[1].DayOfWeek && Bars.IsFirstBarOfSession)
    {
    SignalMadeToday = false;
    }
    .....

    Now I'm trying to use the exact same strategy in NT8, but have found an issue with this syntax. When I use this, NT8 throws out "Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range". To double check this, I used the SampleTimeFilter strategy for NT8, and the same thing happens if I change this;

    if (Time[0].DayOfWeek != DayOfWeek.Monday && Time[1].DayOfWeek != DayOfWeek.Friday)

    to this
    if (Time[0].DayOfWeek != Time[1].DayOfWeek)

    So what am I doing wrong? Its almost like NT is using Time() as a barSeries object instead of a barsAgo? It worked fine in NT7, but I can't get NT8 to work with this.

    Thanks,

    Lee

    #2
    Hello,
    The Time[] is a bar series. You will need to make sure that there are enough bars in the series for you to be accessing. Do you have a CurrentBar Check so that there are enough bars on the chart for you to get a Time[1] value?
    For more information on this check please see the following link: http://ninjatrader.com/support/forum...ead.php?t=3170
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Hi Cody,

      Thank you for the response. The script I'm using is straight from NT7 and works fine in NT7. I do not see that the bars are the issue as the following works and does not produce an error;

      protected override void OnBarUpdate()
      {
      if (Time[0].DayOfWeek != DayOfWeek.Monday && Time[1].DayOfWeek != DayOfWeek.Friday)
      ...
      }

      But, if I change to this, it does not work.

      protected override void OnBarUpdate()
      {
      if (Time[0].DayOfWeek != Time[1].DayOfWeek)
      ...
      }

      So how come this works in NT7 and does not work in NT8?

      Thanks,

      Lee

      Comment


        #4
        Hello,
        In NinjaTrader 7 you should need a current bar check as well to make sure there is a Time[1] to call.
        Would you be able to export the code for the NinjaTrader 7 and NinjaTrader 8 indicator you are using so I may investigate further?
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          Hi Cody,

          Here is the strategy in both NT7 & NT8. The one for NT7 works fine, the one for NT8 does not work.

          Regards,

          Lee
          Attached Files

          Comment


            #6
            Hi Cody,

            Has there been any resolution on this yet?

            Thanks,

            Lee

            Comment


              #7
              Hello,
              I am still debugging these to strategies as to why they are not working in NinjaTrader 8. Thank you for your patience.
              Cody B.NinjaTrader Customer Service

              Comment


                #8
                Hi Cody,

                No problem, just wanted to verify that there was something wrong with the strategy in NT8.

                Thanks again,

                Lee

                Comment


                  #9
                  Hi Cody,

                  Any updates on the status of this issue in NT8?

                  Thanks,

                  Lee

                  Comment


                    #10
                    Hello lee612801,

                    My name is Jess and I will be taking over this ticket.

                    Generally speaking there are a lot of things that may have worked in NinjaScript with NinjaTrader 7 that do not work in NinjaTrader 8. We try to document every known code breaking change on this page.



                    The above page can not catch every possible exception but generally it should not be expected that NT7 code works the same way in NT8 without testing. There is a guide for converting NT7 code to NT8 code here,



                    Some changes which may have affected your code were made to BarsRequiredToTrade / BarsRequiredToPlot, documented here,





                    With respect to your code, your NT7 code was not working to the Data Series specification, and this behavior was fixed for your Time series between NT7 and NT8. Data series in NT7 and NT8 are designed to index between 0 and CurrentBar - 1, for the most and least recent bars, respectively.

                    To avoid this in NT8, and to code to spec in NT7 should we decide to enforce your Time series working to specification in NT7, you will want to use a block such as this at the beginning of your OnBarUpdate method :

                    Code:
                    protected override void OnBarUpdate()
                    {
                        int threshold = 10; // this should be your greatest BarsAgo index
                        foreach(Integer CurrentBarI in CurrentBars)
                        {
                            if (CurrentBar <= threshold)
                            {
                                return;
                            }
                        }
                    Please let us know if there are any other ways we can help.
                    Last edited by NinjaTrader_JessicaP; 10-21-2016, 08:06 AM.
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Jessica,

                      Thank you for the response. I used your suggestion and was able to get the strategy in NT8 to run, but I did notice a difference between the strategies as far as results. I'm still investigating the differences, but If I remove the stop loss, the strategies produce the same results. With the stop loss, I get different results. Does the stop loss work different in NT8 than NT7?

                      Thanks,

                      Lee

                      Comment


                        #12
                        SetStopLoss and SetProfitTarget should have the same interface and specified operation between NT7 and NT8, which is why they do not appear on the code breaking changes page, but the way they interact with other elements may have changed between versions.

                        Could you put together a minimal, complete code sample for us which causes the behavior we are interested in and attach it to a reply here? If you would prefer not sharing your code with the public you can send code samples to platformsupport[at]ninjatrader[dot]com referencing attn:ninjatrader_jessicap and 1558634 in the body of your e-mail.
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          Here is a checklist with some additional information that will help us determine why we are getting unexpected backtest results.

                          • Do you see results when running the same test on the SampleMaCrossOver strategy in NinjaTrader with the same settings as your strategy?

                          • Who are you connected to? This is displayed in green on lower left corner of the Control Center window.

                          • Are you connected to your data feed provider when running this test?

                          • What instrument(s) (and expiry if applicable) have you selected?

                          • What Data Series Type have you selected? Example: Tick, Minute, Day

                          • What From and To date is selected?

                          • Is your strategy a multi instrument or multi time frame strategy?

                          • Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?


                          Jessica P.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Jessica,

                            Thanks for the info. Let me see what I can put together for you.

                            Thanks again,

                            Lee

                            Comment


                              #15
                              Thank you for providing these strategies, lee612801. I was able to compare the two side-by-side with the Market Replay (aka NT8 Playback) connection, and I noticed several differences starting both these strategies at midnight UTC on November Second with SetStopLoss commented out.

                              I am attaching two basic strategies in NT7 and NT8 which perform similarly under these circumstances. If these place trades differently on your end, please let us know so we may assist further.
                              Attached Files
                              Jessica P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by TraderBCL, Today, 04:38 AM
                              2 responses
                              12 views
                              0 likes
                              Last Post TraderBCL  
                              Started by martin70, 03-24-2023, 04:58 AM
                              14 responses
                              105 views
                              0 likes
                              Last Post martin70  
                              Started by Radano, 06-10-2021, 01:40 AM
                              19 responses
                              607 views
                              0 likes
                              Last Post Radano
                              by Radano
                               
                              Started by KenneGaray, Today, 03:48 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post KenneGaray  
                              Started by thanajo, 05-04-2021, 02:11 AM
                              4 responses
                              471 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Working...
                              X