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

    how to load historical data in strategy?

    hi everyone,

    this is my Day 1 of strategy development on Ninja Trader. Apologies if i am asking some obvious questions here. I thought the documentation was very limited.

    I want to load historical daily data (say last 6 months) in Init() function to calculate some historical statistics before I can use them in my indicator calculation (OnBarUpdate) function for real time calculation. I should be able to send orders from onBarUpdate if my criterion is satisfied.

    Could you direct me to an example which can perform these tasks?

    Some more simple questions:
    1. I wanted to be able to debug the code. I downloaded Visual Studio for the development but all the youtube videos shows NinjaScript editor for development.
    2. I want to access strategy positions and manage the risk. Any example for this scenario?
    3. On NinjaTrader web page I saw some reference to DLL building (for more advanced developers). I didn't see any example or more documentation on this. Where do I start on this case?
    4. Is there a way to continuesly roll contracts automaticall in backtest? any examples?


    Regards,
    toughgetsgoing

    #2
    I have started reading more on Automated Trading on Ninja Traders documentation. This seems to have decent information. I was confused with Strategy Builder which is slightly different from what I was looking for. I will read more on this today. Any examples will be appreciated.

    Comment


      #3
      I still couldn't find on how to load historical daily data in Initialization function. can someone please help with this info? I need daily OHLC data for past 3 months which will be used only once in Init function.

      Comment


        #4
        Hello toughgetsgoing,

        To request data out of sync, this can be done with a BarsRequest.


        Using Visual Studio instead of the included NinjaScript Editor is not officially supported by NinjaTrader Support. However, we are taking some steps to make the NinjaTrader project easier to open in Visual Studio. I've also created a video that demonstrates debugging (with 2015 and previous).
        Support for the development of custom automated trading strategies using NinjaScript.


        Are you wanting to find the position of a strategy from within that instance of a strategy?


        You can also find the position of an account.



        Are you wanting to find the position of a running instance of a strategy from another script such as an addon or indicator?
        If so, this would be undocumented and outside of the realm of what may be supported by NinjaTrader (but may be possible to do).

        Scripts can be exported from NinjaTrader as assemblies (dlls) and can optionally have Agile.NET encryption applied.
        Exporting as dll - http://ninjatrader.com/support/helpG...riptAsAssembly
        Agile.NET - http://ninjatrader.com/support/helpG...l_security.htm

        Regarding the merge policy (automatically rolling dates in backtest), please see a post where I have detailed this.


        Last, I am including a link to a informational post about getting started with NinjaScript.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          This is great information and very details. Thank you very much. I will start playing with these ideas right away.

          Comment


            #6
            strategy overwritten

            Hi Chelsey,

            So, last night I was playing with the strategy code. I made some changes (after unlocking the script). It was late so I saved the file in the ninjascript editor and i shut down the NinjaTrader.
            Next day when open the NinjaScript Editor and open my strategy code , I see that the strategy is locked again. My understanding was that once you unlock a code you cannot lock it again.

            What happened after that is I unlocked the code again but then unfortunately I lost all the code changes that i had done on previous night and now it was like a brand new strategy.

            Did I miss any step while saving a strategy ?

            Regards,

            Comment


              #7
              I am confused. I got the code back again. What is going on in the background?

              Comment


                #8
                Hello toughgetsgoing,

                Do you have two copies of script?

                If a script is unlocked and compiled it will not open with the strategy builder.
                (If you are able to reproduce this behavior we would need to investigate and submit a report)

                When a script is opened its read from file. (There isn't a second location where the open source code is kept)

                Do you have two copies of the script perhaps?

                Are you able to reproduce the behavior?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  This happens to me everytime I restart NinjaTrader. I have only one copy of script as shown in the snapshot. (My strategy name is GeninMission01.cs). I saved a copy in a completely different drive last night so that i don't lose any changes when i restart NinjaTrader.http://imgur.com/a/TTpjo

                  Not sure what is happening but whenever i restart my NinjaTrader, the code reverts to the original version when i build a new strategy. Maybe I am doing something incorrectly.

                  If you see the timestamp on the file, its from tonight when I started NinjaTrader.

                  Comment


                    #10
                    Now I am able to reproduce the issue. Behaviour is very strange and i might say a bit unpredictable as well. not sure if i will be able to explain properly but here are the steps.

                    - create new strat, unlock the code. make changes and save.
                    - close ninja script editor.
                    - Open ninja script editor from "New" menu.
                    - at this step, sometimes the strategy is locked again. (Here is additional snapshot of unlocked strategy even though it was locked, compiled and saved earlier. Sanpshot 2
                    - when i repopen ninja script editor, sometimes strategy is in unlocked state and sometimes it is not.
                    - if the strategy is locked, then obviously it means its a new strategy and the code is reverted to empty skeleton.
                    In one of the states... for some reason i was able to see my original code when the strategy was in unlocked state .

                    Looks like strategy locking/unlocking has some issue when i report ninja script editor.

                    Comment


                      #11
                      at least i have now understood how to get back my code

                      when i reopen ninja editor [call this Window 1] and double click on my strategy it opens strategy parameter window (i.e.strategy is locked). When I unlock the code (second time), it opens a new script editor with an empty strategy skeleton [call this Window 2]. Now if I ignore Window 2 and double click on my strategy name again on Window 1, magic happens and Window 1 shows my original code!

                      That was like a puzzle!

                      Comment


                        #12
                        Hello toughgetsgoing,

                        Are you compiling and saving your changes after unlocking?

                        (If not, it will open with the builder again as that was its last saved state)
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          I am definitely saving and compiling the strategy. that is how i am able to get back my original version in Window 1.
                          Another point you should know (which shows that i compile and save) is that i have set Debug mode to On and I am debugging through the code in my Visual Studio. So yes, definitely compiling and saving the code.

                          Comment


                            #14
                            Hello toughgetsgoing,

                            I am attempting to reproduce this behavior using the latest version (8.0.7.0) so that I may report the behavior to our development but I am unable to reproduce.

                            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.


                            May I confirm that I have taken the correct steps to reproduce the behavior?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              I will create a similar screencast later tonight and post it here. Thanks.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Javierw.ok  
                              Started by timmbbo, Today, 08:59 AM
                              2 responses
                              10 views
                              0 likes
                              Last Post bltdavid  
                              Started by alifarahani, Today, 09:40 AM
                              6 responses
                              41 views
                              0 likes
                              Last Post alifarahani  
                              Started by Waxavi, Today, 02:10 AM
                              1 response
                              21 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Working...
                              X