• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need to code - Ninjatrader

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

    Need to code - Ninjatrader

    Hi,
    I have a couple of strategies which i wish to automate.

    I am a novice in this field, but generally good with algorithms

    I would prefer to code in C#/C++, and then integrate it with ninjatrader.

    Things i would need to get started

    1.) Level 1 tick data.
    2.) Getting all the data into variables - mainly bid offer , last price, volume traded and time stamp.

    Initially i dont need the strategy to go live, just want to test it on historical data/ paper trade on live data. so latency need not be an issue.

    I have a rthmic data connection, and can get past historical data from ninjatrader.

    What is the best way to get started, and how can i go about this.

    Any help would be appreciated,
    Thanks

    #2
    Hello nemesis45,

    NinjaScript is C# based language so it will be very similar.

    The best place to start coding an automated strategy would be to use the Strategy Wizard, which will have a point and click interface to create a basic strategy that you can view the source code of the strategy to see how it is being written. To access the Strategy Wizard you may go to the Tools -> New NinjaScript -> Strategy option.

    http://www.ninjatrader.com/support/h...egy_wizard.htm

    The Strategy Wizard can only do basic strategies so if your algorithms cannot be placed inside of the Strategy Wizard then you may unlock the strategy for some custom coding.

    We have documented all of the supports methods and objects of NinjaScript inside of our Help Guide that you may view for reference at the following link.

    http://www.ninjatrader.com/support/h..._reference.htm


    This should help you get started on an Automated Strategy, let us know if any questions come up.
    JCNinjaTrader Customer Service

    Comment


      #3
      thanks a lot,
      i will go through the help guide.

      this should get me started

      Comment


        #4
        hi

        Never mind.
        Is there any advanced help or extra resources which i can refer to?

        Basically all i want to do is put data like - Last price, volume at every print, along with Bid/offer sorted into variables.
        there seems to be no way to do this.

        Time bars are useless for this, looking into tick bars, but still doing such a simple thing seems complicated.

        Any way to do this?
        Last edited by nemesis45; 02-28-2014, 02:13 PM.

        Comment


          #5
          Hello nemesis45,

          You may add additional Series of Information like this but it would be very advanced for of NinjaScript where you may not want to start learning NinjaScript.

          Here is the link that goes over the Multi-Series approach in NinjaScript that you may view.
          http://www.ninjatrader.com/support/h...nstruments.htm

          Note that you can get Bid, BidVolume, and Close (Last Price) inside of the Strategy Wizard under "Price Data".

          Here is our Help Guide on our Strategy Wizard that you may view the different things that you can do inside of the Condition Builder.
          http://www.ninjatrader.com/support/h...on_builder.htm
          JCNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_JC View Post
            Hello nemesis45,

            You may add additional Series of Information like this but it would be very advanced for of NinjaScript where you may not want to start learning NinjaScript.

            Here is the link that goes over the Multi-Series approach in NinjaScript that you may view.
            http://www.ninjatrader.com/support/h...nstruments.htm

            Note that you can get Bid, BidVolume, and Close (Last Price) inside of the Strategy Wizard under "Price Data".

            Here is our Help Guide on our Strategy Wizard that you may view the different things that you can do inside of the Condition Builder.
            http://www.ninjatrader.com/support/h...on_builder.htm
            Close will give me the close for the last bar, how do i get the last traded price?
            ( by setting the period type to tick?)
            and how to see the last volume traded? ( VOL()[0} and set period type to tick?)

            I will go through all of NS tutorials, but please do inform if i can do this simply via C#/C++ without using NS

            Comment


              #7
              Hello nemesis45,

              Using a Period Type of 1 Tick the Close will be the last traded price. If you set the "CalculateOnBarClose" to false this will have the strategy process on each incoming tick of data so Close[0] will be the last traded price as you strategy is getting real-time data.

              If you would like to access data outside of NinjaTrader thus being outside of NinjaScript you may use the DLL interface that NinjaTrader has exposed so 3rd Party Applications can access NinjaTrader.

              This is not something that we can support but you here is the list of functions and a description of what they return that you may use in C# to get data from NinjaTrader.

              http://www.ninjatrader.com/support/h.../functions.htm
              JCNinjaTrader Customer Service

              Comment


                #8
                hi

                Originally posted by NinjaTrader_JC View Post
                Hello nemesis45,

                Using a Period Type of 1 Tick the Close will be the last traded price. If you set the "CalculateOnBarClose" to false this will have the strategy process on each incoming tick of data so Close[0] will be the last traded price as you strategy is getting real-time data.

                If you would like to access data outside of NinjaTrader thus being outside of NinjaScript you may use the DLL interface that NinjaTrader has exposed so 3rd Party Applications can access NinjaTrader.

                This is not something that we can support but you here is the list of functions and a description of what they return that you may use in C# to get data from NinjaTrader.

                http://www.ninjatrader.com/support/h.../functions.htm
                Yes the DLL looks exactly like what i need

                double MarketData(string instrument, int type)
                Gets the most recent price for the specified instrument and data type. 0 = last, 1 = bid, 2 = ask. You must first call the SubscribeMarketData() function prior to calling this function.

                Now how do i get the volume traded at last print?, got the last price using MarketData , but no function listed for volume

                I am missing getting the volume in DLL,
                Since in ninjascript if i set the period type to 1 tick, it will give cumulative volume since market has moved a tick, vol()[0] = volume since last tick move
                ok well it will do the job alright i guess

                Ok can use NS now. but i'd like to know how to use the DLL to get volume data also.
                Just in case

                Are there other functions which are not listed

                Also,
                int Ask(string instrument, double price, int size)
                Sets the ask price and size for the specified instrument

                Can you please explain this a little. what do you mean by set the ask price ( place an offer of size x? if so no order type.. so what does this do eg?)

                Thanks a lot
                Last edited by nemesis45; 02-28-2014, 04:36 PM.

                Comment


                  #9
                  Also, is there something like a "print has changed " value in incoming data , which i can access through DLL,
                  Additionally is there a volume ticker which i can access through DLL
                  Lastly, how to access level 2 data through DLL

                  Thank You

                  Comment


                    #10
                    Sample Program to get Data

                    I wrote a sample program to get this data
                    protected override void Initialize()
                    {
                    CalculateOnBarClose = false;
                    Add("CL 04-14",PeriodType.Tick,1);
                    Print("Hello World");
                    }
                    protected override void OnBarUpdate()
                    {
                    if(CurrentBar <= 100)
                    {
                    Print(CurrentBar);
                    Print("Current Bid Price="+GetCurrentBid());
                    Print("Current Bid Volume="+GetCurrentBidVolume());
                    Print("Current Ask Price="+GetCurrentAsk());
                    Print("Current Ask Volume="+GetCurrentAskVolume());
                    Print("Last Traded Price= " +Close[0]);
                    Print("Last Traded Volume="+VOL()[0]);
                    Print("Time Stamp="+Time[0]);


                    }
                    else
                    {
                    return;
                    }
                    }

                    This is the sample output i received.
                    on output window
                    Current Bid Price=101.98
                    Current Bid Volume=11
                    Current Ask Price=101.98
                    Current Ask Volume=11
                    Last Traded Price= 101.98
                    Last Traded Volume=11
                    ,, when DataSeries= second
                    Why are the current bid price and current ask price always the same
                    and all volume is equal , this is in all the cases of CurrentBar
                    If i backtest using Dataseries= Tick,1 , it says
                    Current Bid Price=102.02
                    Current Bid Volume=2
                    Current Ask Price=102.02
                    Current Ask Volume=2
                    Last Traded Price= 102.02
                    Last Traded Volume=2
                    Time Stamp=2/26/2014 4:38:01 AM

                    I have downloaded past data for CL 04-14 both Bid, Ask and Last, tick data

                    Please also tell me , how to get the TimeStamp down to the last millisecond ( or the finest resolution)

                    I think i would rather do this with the DLL,

                    Just please give me a complete list of functions for the DLL,
                    or tell me if there is a way to add functions to the DLL,

                    I just want to get the mentioned data from my Rthmic Data connection or Historical data into variables.

                    Thanks a lot

                    Comment


                      #11
                      Hello nemesis45,

                      The only functions inside of the DLL Interface are the one that you see listed on our Help Guide so there would not be a way to access volume or level 2 data.

                      When using "GetCurrentAskVolume()" or "GetCurrentBidVolume()" Historically meaning in a backtest as well you must note that the volume of the evaluated bar is substituted.

                      If you wanted the actual bid and ask Historical since you have downloaded the Bid and Ask tick data you may want to add the Bid and Ask Tick series as well. For example:

                      Code:
                      // Example uses the ES 03-14 Instrument but you would want to change this to your Instrument.
                      Add("ES 03-14", PeriodType.Tick,1 MarketDataType.Ask);
                      A second is the finest granularity that you can get inside of NinjaTrader 7.
                      JCNinjaTrader Customer Service

                      Comment


                        #12
                        Thanks a lot JC
                        I have added bid/ask bars
                        just to be clear the volume i am getting after adding Bid/Ask bars , is the volume at bid or volume at offer and not the volume traded?

                        I understand that i can get better resolution of time stamp on live data .
                        I know that for historical data, best resolution i would get is 1 second.
                        It's fine for historical data, but i would need better time resolution for live data.

                        It would be great if you could add some functions to the dll file, so that this data would be readily available.
                        Still i have more than enough to get started

                        Comment


                          #13
                          Hello nemesis45,

                          after adding Bid/Ask bars , is the volume at bid or volume at offer and not the volume traded?
                          Yes, that is correct.

                          I understand that i can get better resolution of time stamp on live data .
                          I know that for historical data, best resolution i would get is 1 second.
                          It's fine for historical data, but i would need better time resolution for live data.
                          Correct, in other methods like OnMarketData() and OnMarketDepth() it is possible to get a higher granularity of time but NinjaTrader 7 will only reports its executions and charts based on a second granularity.

                          It would be great if you could add some functions to the dll file, so that this data would be readily available.
                          I will forward this suggestion to our development team for future consideration on our next major release of NinjaTrader.

                          Let us know if you have any further questions.
                          JCNinjaTrader Customer Service

                          Comment


                            #14
                            Hi,
                            I am running a strategy named "Get buy and sell prints"

                            Its working fine, using OnMarketData()

                            The problem i am having is that when loading the strategy on the output window
                            there is a message saying

                            Date Time Structure D1 is 3/3/2014 7:30:00 PM

                            **NT** Disabling NinjaScript strategy 'GetBuyandSellPrints/51772dd51151470084e4061bfd3a4e26'
                            **NT** Enabling NinjaScript strategy 'GetBuyandSellPrints/81e02c606d704f01b3a96d58776d7468' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes

                            Why is it showing Date Time Structure D1 is so and so ,
                            i havent used a print command to print a date.

                            This command is what i have used in another strategy in the initialise function.
                            Why is that command coming into play in my current strategy.
                            The previous strategy hasnt been added to any chart, also Ninjatrader has been restarted since the strategy was last used.

                            Comment


                              #15
                              Just noticed
                              It's printing Date Time structure D1 = so and so
                              when i remove the strategy from chart.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by uiwislth, Yesterday, 11:25 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post uiwislth  
                              Started by Steve L, Yesterday, 10:04 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post Steve L
                              by Steve L
                               
                              Started by marianfed, Yesterday, 09:47 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post marianfed  
                              Started by hir04068, Yesterday, 09:29 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post hir04068  
                              Started by iq200, 03-11-2018, 07:49 PM
                              24 responses
                              1,018 views
                              0 likes
                              Last Post mrlucky1x  
                              Working...
                              X