Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple timeframes orders problem

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

    Multiple timeframes orders problem

    Hi,

    I'm working on a strategy that uses two time frames: 1 minute bar to enter orders and 1 tick bar to exit orders (trailing stops, etc..)

    As a start, I've modified the SampleMACrossOver strategy to include another timeframe, but I'm getting wrong orders and the strategy gets disabled.

    This is the modified code:
    Code:
    		/// <summary>
    		/// This method is used to configure the strategy and is called once before any strategy method is called.
    		/// </summary>
    		protected override void Initialize()
    		{
    			SMA(Fast).Plots[0].Pen.Color = Color.Orange;
    			SMA(Slow).Plots[0].Pen.Color = Color.Green;
    
                Add(SMA(Fast));
                Add(SMA(Slow));
    			
    			Add(PeriodType.Tick, 1);   //New time frame to handle exits.
    			CalculateOnBarClose	= true;
    		}
    
    		/// <summary>
    		/// Called on each bar update event (incoming tick).
    		/// </summary>
    		protected override void OnBarUpdate()
    		{
    			// Check which Bars object is calling the OnBarUpdate() method 
        		if (BarsInProgress == 0) 
        		{ 
             		// Do something within the context of the 1 minute Bars here 
    			if (CrossAbove(SMA(Fast), SMA(Slow), 1))
    			    EnterLong();
    			else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
    			    EnterShort();
    			Print("BarsInProgress: "+BarsInProgress+"   "+Time[0]+" Close[0]:"+Close[0]);
        		} 
        		else if (BarsInProgress == 1) 
        		{ 
             		// Do something within the context of the 1 tick Bars 
    				Print("BarsInProgress: "+BarsInProgress+"   "+Time[0]+" Close[0]:"+Close[0]);
        		} 			
    		}
    What I'm doing wrong?

    Thanks!

    #2
    Hello dpicon,
    Unfortunately there is no exit codes in your sample code.

    Please refer to this sample code which demonstrates entering in one timeframe and exiting on another timeframe.


    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Well my example is the one included on the NT installation. I believe it exits by entering an opposite order. If I remove the
      Code:
       Add(PeriodType.Tick, 1);
      from the code I posted before then everything works Ok, but with the modifications (just adding a new 1 tick bars), it just generates the following errors:

      **NT** An over fill was detected on order 'Order='74fe8a7c1df14d53b8543537a6389bbf/Sim101' Name='Buy' State=Filled Instrument='FDAX 06-12' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='aaaTickTest' Type=Market Tif=Gtc Oco='' Filled=1 Fill price=6470,5 Token='74fe8a7c1df14d53b8543537a6389bbf' Gtd='01/12/2099 0:00:00'' generated by strategy 'aaaTickTest/d32abf6de6964da1a0efbb4522564608' : This strategy will be disabled and NinjaTrader will attempt to cancel/close any strategy generated orders and positions. Please check your account orders and positions and take any appropriate action.
      **NT** Disabling NinjaScript strategy 'aaaTickTest/d32abf6de6964da1a0efbb4522564608'
      This happens only on a 1 minute chart. If I run the strategy in a 1 tick chart (and "Reload All Historical Data") then the errors go away. Why?

      Basically what I want to achieve is to add an intrabar exit to an already working strategy changing the less amount of code.

      My strategy works on a 1 minute chart, and I thought that adding a secondary tick chart would allow me to do that, providing that in OnBarUpdate I discriminate between BarsInProgress==0 for the current working code and indicators using the 1 min bars and BarsInProgress == 1 for the new exit code using the tick bars.

      Regarding your example it adds two 5 and 15 minute bars objects, would it be possible to remove the first
      Code:
      Add(PeriodType.Minute, 5);
      and use the first bar series (BarsInProgress == 0) if the strategy is already working on a 5 min chart?
      Last edited by dpicon; 05-10-2012, 05:25 AM.

      Comment


        #4
        Hello dpicon,
        You are witnessing and overfill.

        An overfill is categorized as when an order returns a "Filled" or "PartFilled" state after the order was already marked for cancellation. The cancel request could have been induced by an explicit CancelOrder() call, from more implicit cancellations like those that occur when another order sharing the same OCO ID is filled, or from things like order expirations.


        Can you send a sample code replicating it. Also please let me know the exact steps to reproduce it. You can email the sample strategy to support[AT]ninjatrader[DOT]com

        Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.


        Yes, you can remove the Add(PeriodType.Minute, 5); code. Please not you have to make necessary adjustments in the other parts of the code too for everything to work smoothly.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Update:
          1) I have opened a 1 tick chart and reloaded all historical data.
          2) Now I open my 1 minute chart and run the strategy
          3) Now it works.

          Could it be that when running the strategy trough the historical bars because the historical tick data were not downloaded the strategy got it wrong sending overfills etc??

          Is there a way to make sure that data is there?
          Would I have the same problems when backtesting?

          Too many questions... I'm sorry

          Comment


            #6
            Hello dpicon,
            Glad to know everything is working fine at your end.

            Unfortunately I cannot say for sure, the exact cause unless I can reproduce it at my end.

            If you are connected to your connectivity provider and your connectivity provider supports the data type (appends tick and minute data) then NinjaTrader will pull the missing data.

            Also please make sure Get data from server is checked in the Options menu.
            • In Control Center menu bar goto Tools>Options...
            • In the Options dialog click on the Data tab
            • In the Data tab make sure "Get data from server (if available)" is checked.


            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Joydeep View Post
              Also please make sure Get data from server is checked in the Options menu.
              • In Control Center menu bar goto Tools>Options...
              • In the Options dialog click on the Data tab
              • In the Data tab make sure "Get data from server (if available)" is checked.
              That was the main problem, the strategy were not downloading the needed tick data at first until I did Reload All Historical Data on a tick chart.

              May I suggest that if a strategy does not find the needed historical data at least Prints an output message?

              Thanks for your help!

              Comment


                #8
                Hello dpicon,
                Were you connected to your connectivity provider while backtesting?

                I will forward your feature request to development.

                Please let me know if I can assist you any further.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Yes I was connected to Kinetick but the option to
                  Get data from server (if available)
                  was not checked.
                  Oh! And I wasn't backtesting, I was just running the strategy the missing historical data was the one needed to cover the previous bars on the chart.

                  All is fixed now thanks for your support!

                  Comment


                    #10
                    Hello dpicon,
                    Glad to know everything is working fine at your end.

                    Please let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      Hello dpicon,
                      Development has assigned tracker id no #125 for your feature request.

                      Please let me know if I can assist you any further.
                      JoydeepNinjaTrader Customer Service

                      Comment


                        #12
                        Multiple Time Frame Data Series Problem

                        Hello, sorry to post as a reply but I don't see a new thread option.
                        I am trying to bring up a chart with both 3 minute and 15 minute time frame of ES futures. But the chart will not populate with any date.
                        Could it be that I just started here and am using the simulated?
                        Appreciate the help.
                        Tom

                        Comment


                          #13
                          TomTrades, Welcome to the NT forums!

                          You will need a subscription to a data service or an account with one of our supported brokers in order to view intraday data like 3 or 15 minute. You can view free daily data with the Kinetick (end of day free) connection. Kinetick is the recommended service for streaming / real time data as well. More information on Kinetick available here:


                          See this link for all our data providers and the level of data supported:
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks Ryan
                            I have a data service. CQG through AMP Clearing

                            Comment


                              #15
                              At the bottom it says I may post new threads so were is the illusive "New Thread" button?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by AaronKoRn, Today, 09:49 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Today, 08:42 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Today, 07:51 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,980 views
                              3 likes
                              Last Post jhudas88  
                              Started by rbeckmann05, Today, 06:48 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post rbeckmann05  
                              Working...
                              X