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

how to load historical data in strategy?

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

    #16
    Please note that I am making lot of code changes in the generated code and then saving them later.
    Next time when I try to open the code from editor, it is locked. Please check my screencast and let me know if i am doing anything incorrectly.

    https://www.screencast.com/t/OFq5YjzrOJBA

    Comment


      #17
      Hello toughgetsgoing,

      This video does not demonstrate that the script was unlocked and then re-opened.

      I cannot verify if you are performing the correct steps because the full steps were not included in the video.

      It almost looks like you are opening the script before unlocking it in a text editor, unlocking the code, copying the code from a text editor with the pre-unlocked changes back which reverts the code the previous state.

      No, this would not be the proper process to unlock a script.

      As a curiosity, why are you copying the pre-unlocked code back into the script?
      This would undue the unlock as the information for the wizard is at the bottom of the script which you are manually copying back in.
      Last edited by NinjaTrader_ChelseaB; 06-18-2017, 04:39 PM.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        I was only trying to copy my local changes which i was doing in my original script. I didn't want to copy the whole file. (I did that because first time my code was lost).

        But now when I follow your steps, I am not able to reproduce the issue.

        I think it's ok to consider my steps were incorrect and there is no issue. But if I face any issue again, I will take a screen cast and share it next time.

        Thanks for your time.

        Comment


          #19
          Hi @NinjaTrader_ChelseaB
          I have a feeling on why i lost my code when i launched ninja trader 2nd time. I think this happened because in my first launch I had opened the ninjatrader solution in Visual studio (For debugging purpose) and i had compiled my changes from visual studio instead of from nina script editor. This must have made my strategy to get locked for some reason.
          Later one it was getting locked because i kept copying an external script (as i showed in video earlier) from the fear of losing my changes.

          Comment


            #20
            Hi @NinjaTrader_ChelseaB,

            thanks for your help so far. I am able to development properly now. I have couple of follow up questions regarding my original post here.

            Question 1. I am able to load historical daily data in my daily live simulation. This is working fine. I use BarsRequest API to get this data. Unfortunately this doesn't work in my backtest. (using Strategy Analyzer).

            My code to get historical data is as follows:

            BarsRequest barsRequest = new BarsRequest(this.Instrument, DateTime.Now.AddDays(-90), DateTime.Now);
            barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Day, Value = 1 };

            If you notice, I am loading past 90 days of daily data from today's date. I want to change this to use simulation date instead. How can i get date of the simulation?

            Also if I change the date of simulation, will I be load historical 90 days daily data in backtest (on each day?

            Question 2
            I want to refer to an external library in my code. from online documentation i see that the only way to achieve this is using AddOn framework. I checked the sample provided on the website at http://ninjatrader.com/support/helpG...t_overview.htm

            from the example I see that one is trying to develop and AddOn GUI. as given below

            public class AddOnFramework : AddOnBase
            public class AddOnFrameworkWindowFactory : INTTabFactory
            public class AddOnFrameworkWindow : NTWindow, IWorkspacePersistence


            What I want to do is to refer to some mathematical functionality in a library. Nothing more. Just some static calculation functions. How can I achieve this in best possible way? is AddOn dev the right way to go? I still don't understand how to use AddOn just as a library.

            Comment


              #21
              Hello toughgetsgoing,

              I can confirm that using BarsRequest will work historically in a backtest if the data is available.

              Attached is an example. Try running this in the Strategy Analyzer.

              The from and to time of the strategy analyzer is not a property that can be accessed. But you can get the DateTime of the first bar and DateTime of the last bar.

              Bars.GetTime(1)
              Bars.GetTime(Count - 2)



              The data that loads will depend on what dates or number of bars you give it and when the method is run. My example processes on the second bar and only processes once.


              It is not required to use the Addon class. Add your dll, add a reference to the dll, then call the call the Namespace and class written into the file.
              Attached Files
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Hi @NinjaTrader_ChelseaB

                I am facing another issue with my backtest now. As you mentioned, I am able to load the historical data in Strategy Analyzer. The issue is that I don't see continues futures data over the whole period. Here is the input to my strategy

                start date: 1/1/2012
                end date: 6/21/2017
                instrument: ES 06-17


                I request the 5 minute bar data asynchronously as mentioned your example.

                Now I was expecting Bars.GetTime(1) to be start of my backtest period i.e. somewhere near 1/1/2012 but instead this is 5/26/2017.

                Since i have specified Global merge policy = "Merge back adjusted" then Why is my start date pointing to 5/26/2017 and not close to 1/1/2012 ?

                I also tried ES ##-## as instrument name instead of above as mentioned in the link here link but this did not help as well


                So my final question is : How can I backtest a strategy on ES future starting from 2012 till now? For some reason when i run the strategy, the data is loaded from 26th May 2017 instead from Jan 2012.


                please see attached pictures for details:



                Last edited by toughgetsgoing; 06-26-2017, 08:16 AM. Reason: additional info

                Comment


                  #23
                  Hello toughgetsgoing,

                  I've tested this but I am not able to reproduce.

                  Below is a link to a video of the test.
                  Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


                  What is the date and time of the first bar (on the left) of the Chart in the Strategy Analyzer?
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Hi Chesea,

                    Thanks for that quick video. It helps a lot. Apologies for these small questions, i am still getting used to the platform. I just started exploring NinjaTrader recently.

                    I think I understand the issue now. I guess this is happening because I don't have access to the data at all.

                    So I get to work on this dev work on weekends mostly. I wasn't ready with testing from 2012 until recently. When I first specified the historical dates (few days ago) I think i had already lost the 2 weeks Continuum demo data access. (To be fair I didn't know that demo was available for only 2 weeks. I don't remember reading this anywhere).
                    I haven't subscribed to any other data as of now. Since my cache doesn't have any data (In historical data window, I see data from 26th May 2017 onwards only), strategy analyzer is not able to load or fetch any new data.

                    Could you confirm if my understanding is correct?

                    In such case I need to subscribe to tickdata? effectively pay for this? I was wondering if there is a way to extend the Continuum demo account for another 2 weeks.

                    Also here are my strategy properties, if it might help

                    Calculate = Calculate.OnEachTick;
                    EntriesPerDirection = 1;
                    EntryHandling = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy = true;
                    ExitOnSessionCloseSeconds = 30;
                    IsFillLimitOnTouch = false;
                    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution = OrderFillResolution.Standard;
                    Slippage = 0;
                    StartBehavior = StartBehavior.WaitUntilFlat;
                    TimeInForce = TimeInForce.Day;
                    TraceOrders = false;
                    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade = 20;


                    If my understanding is not correct and if should still be able to backtest using strategy analyzer, then let me know and i will create another screencast of the steps i am taking. pretty much same as what you have done in your video.

                    Comment


                      #25
                      Hello toughgetsgoing,

                      Yes, you must be connected to a connection (showing in green) that provides historical data to get historical data for the backtest.



                      The data that appears on the chart of the Strategy Analyzer will be the data that was tested over.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        Hi Chelsea,

                        I am connected to data provider on the platform (Kinetick) and the connection is green but i haven't paid for any kinetick subscription yet.

                        Continuum connection doesn't work anymore as i have lost the access.

                        When i started using ninjatrader, everywhere it was mentioned that data was free and simulations is all free. I didn't realize that i will need to pay for data.

                        Is there any tickdata (possibly intraday data) that is provided by NinjaTrader and which is free (maybe after i get the NT license) or I need to pay at least one data provider (Kinetic or Continueem for my case) to load historical intraday data?

                        regards,
                        toughgetsgoing
                        Last edited by toughgetsgoing; 06-27-2017, 06:20 PM.

                        Comment


                          #27
                          Hello toughgetsgoing,

                          The NinjaTrader Platform is free to use. You can use the Simulated Data Feed right now for as long as you would like with no expiration.

                          That I know of, there are no sources of unlimited free tick data from the market.

                          For NinjaTrader, if you would access to the NinjaTrader Continuum system after your demo, you would need to fund a brokerage account and subscribe to the exchanges you would like data for with your funded brokerage account.

                          For Kinetick, see the subscription page to start a subscription.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #28
                            understood about the data feeds now.

                            Back to loading the data in the strategy I still seems to have some issue.

                            Today i was testing using Simulated feed as you mentioned. This is the first time I am connecting to simulated feed. After running the strategy in Analyzer window the date of the first bar is still 26/05/2017. (Same date on the leftmost bar in the chart of strategy analyzer window).

                            I have created a screencast for this demo. Could you please tell me if I am doing something incorrectly. Is there a way to refresh the data cache so that NT will pull the data again? It feels like the strategy is not looking at the continues futures data but instead looking at ES 09-17 data only.

                            https://www.screencast.com/t/8yEs9cZ9

                            Comment


                              #29
                              Hello toughgetsgoing,

                              Who are you connecting to for historical data?

                              Below is a link to the NinjaTrader 8 help guide on Data by provider which shows the supported connection technologies and the types of data these connections support.


                              Also here is a publicly available link to a list of the supported brokers with the NinjaTrader Platform.
                              NinjaTrader provides online access to the futures, forex and equities markets through online brokers including NinjaTrader Brokerage.


                              Last, here is a link to our Connections Guide which will have instructions to setup the provider in NinjaTrader (scroll to the bottom).



                              I'm not understanding what you are asking about with the Simulated Data Feed. This connection provides fake self-generated real-time data and does not provide historical data. Are you testing this script in real-time on a chart? The BarsRequest is not going to work with the Simulated Data Feed as this connection does not provide historical data.

                              In my previous post, I am trying to have you understand the NinjaTrader Platform and your data provider connection are not the same thing.
                              You can use the platform for free with no expiration. You would pay for a license when you are ready to trade live.
                              However, for a connection for data, this will need to be obtained from a provider.
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #30
                                ah ok. I thought simulation feed will also provide (simulated) historical data. I need to read more about these feeds. Right now I don't have any historical data stored in cache. I will find out more information and get back to you once the data feed is finalized. Thank you.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by PaulMohn, Today, 03:49 AM
                                0 responses
                                3 views
                                0 likes
                                Last Post PaulMohn  
                                Started by inanazsocial, Today, 01:15 AM
                                1 response
                                7 views
                                0 likes
                                Last Post NinjaTrader_Jason  
                                Started by rocketman7, Today, 02:12 AM
                                0 responses
                                10 views
                                0 likes
                                Last Post rocketman7  
                                Started by dustydbayer, Today, 01:59 AM
                                0 responses
                                2 views
                                0 likes
                                Last Post dustydbayer  
                                Started by trilliantrader, 04-18-2024, 08:16 AM
                                5 responses
                                23 views
                                0 likes
                                Last Post trilliantrader  
                                Working...
                                X