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

Multi Time Frame Strateg

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

    Multi Time Frame Strateg

    I've built a strategy using 3 different time frames (lets say 1,2, and 3 min.). When certain conditions are met, I want to issue my order "immediately". To do this, I've used the following code:

    EnterLong(0,DefaultQuantity,"LE");

    I assumed sending my order on the first Bar Series would fill the order on the next bar. However, I have an order issued at 13:08, that does not fill until 13:10 when my conditions are no longer met. I've verified via TraceOrders that the order is being sent at 13:08, and it is a market order. So why would it not fill at the open of the 13:09 bar?

    #2
    toptrader,

    Will need more information on the full sequence of events to occur. Please add prints that outline exactly which BarsInProgress is being processed along with the TraceOrders. Adding prints to OnOrderUpdate() will also help better track down the exact details as to what the order is doing.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh,
      Below are my print logs with TraceOrders=true as well as some output of my own. My output format is:

      Time[0], Order.Action, BarsInProgress

      1/7/2010 1:08:00 PM Entered internal PlaceOrder() method at 1/7/2010 1:08:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LE' FromEntrySignal=''
      1/7/2010 1:08:00 PM, BuyToCover, 0
      1/7/2010 1:08:00 PM, BuyToCover, 0
      1/7/2010 1:08:00 PM, BuyToCover, 0
      1/7/2010 1:08:00 PM, Buy, 0
      1/7/2010 1:08:00 PM, Buy, 0
      1/7/2010 1:08:00 PM, Buy, 0
      1/7/2010 1:09:00 PM, BuyToCover, 0
      1/7/2010 1:09:00 PM, Buy, 0

      Comment


        #4
        Which BIP was the order submitted from? Please add some OnOrderUpdate() prints to see the OrderState of that market order.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,
          Below is more info. I've also attached a screen shot so you can see what is happening.

          Time[0], order.Action, BarsInProgress, order.OrderState

          1/7/2010 1:08:00 PM Entered internal PlaceOrder() method at 1/7/2010 1:08:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LE' FromEntrySignal=''
          1/7/2010 1:08:00 PM, 2 // BarsInProgress was 2 when the order was sent
          1/7/2010 1:08:00 PM, BuyToCover, 0, PendingSubmit
          1/7/2010 1:08:00 PM, BuyToCover, 0, Accepted
          1/7/2010 1:08:00 PM, BuyToCover, 0, Working
          1/7/2010 1:08:00 PM, Buy, 0, PendingSubmit
          1/7/2010 1:08:00 PM, Buy, 0, Accepted
          1/7/2010 1:08:00 PM, Buy, 0, Working
          1/7/2010 1:09:00 PM, BuyToCover, 0, Filled
          1/7/2010 1:09:00 PM, Buy, 0, Filled
          Attached Files
          Last edited by toptrader; 01-19-2010, 01:20 PM.

          Comment


            #6
            toptrader,

            So it says 1:09 is the filled time which is accurate. I am not sure what exactly is the issue then?
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I agree a fill time of 1:09 is accurate, but look at the chart, It fills at 1:10. I've updated the logs in my previous post to show more information. Is there any other information that would be helpful?
              Last edited by toptrader; 01-19-2010, 01:20 PM.

              Comment


                #8
                Please bring up the Data Box and hover over the execution. What time does it say on the execution in the Data Box? If it says 1:09, please attach a simple as possible reference sample that demonstrates this so we can test with it on our end. Thank you.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  The execution time says 1:10. Below is a modified version of the strategy. It is pretty simple. I am looking for three time frames to meet 1 buy/sell criteria simultaneously to generate an entry.

                  Code:
                  double fastma1 = SMA(Closes[0],20)[0];
                  double fastma2 = SMA(Closes[0],25)[0];
                  double fastma3 = SMA(Closes[0],30)[0];
                  
                  double medma1 = SMA(Closes[1],20)[0];
                  double medma2 = SMA(Closes[1],25)[0];
                  double medma3 = SMA(Closes[1],30)[0];
                  
                  double slowma1 = SMA(Closes[2],20)[0];
                  double slowma2 = SMA(Closes[2],25)[0];
                  double slowma3 = SMA(Closes[2],30)[0];
                  
                  bool trade1long = fastma1>fastma2 && fastma2>fastma3;
                  bool trade2long = medma1>medma2 && medma2>medma3;
                  bool trade3long = slowma1>slowma2 && slowma2>slowma3;
                  
                  if (trade1long && trade2long && trade3long)
                  EnterLong(0,DefaultQuantity,"LE");
                  The code is exactly opposite for shorts.

                  Comment


                    #10
                    toptrader,

                    Which BarsInProgress context is this placed in? It may be easier if you just attached your file so to eliminate all confusion and discrepancies when we test it. Thank you.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      I don't have it under any BarsInProgress context. I tried several variations using BarsInProgress, but this simplified version was the closest I've gotten to what I'm trying to accomplish.

                      Comment


                        #12
                        TopTrader, I "filled in the blanks" of your strategy and ran it and the execution was plotted at the correct time on the chart. Is there something your strategy does different? Please see the attached files for reference.
                        Attached Files
                        AustinNinjaTrader Customer Service

                        Comment


                          #13
                          The only difference between your code and mine is the indicators used. My Output Window says the order is placed on the 1 min. chart at 13:08, but it waits 2 bars to plot the fill. The output window says the following.

                          1/7/2010 1:08:00 PM Entered internal PlaceOrder() method at 1/7/2010 1:08:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LE' FromEntrySignal=''
                          1/7/2010 1:09:00 PM Entered internal PlaceOrder() method at 1/7/2010 1:09:00 PM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='LE' FromEntrySignal=''
                          1/7/2010 1:09:00 PM Ignore order amendment: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName=LE' FromEntrySignal='' Reason='Order already has this stop price/limit price/quantity'
                          1/7/2010 1:09:00 PMExecution='NT-00017' Instrument='SPY' Account='Sim101' Name='Close position' Exchange=Default Price=113.79 Quantity=1 Market position=Long Commission=0 Order='NT-00020' Time='1/7/2010 1:10:00 PM'
                          1/7/2010 1:09:00 PMExecution='NT-00018' Instrument='SPY' Account='Sim101' Name='LE' Exchange=Default Price=113.79 Quantity=1 Market position=Long Commission=0 Order='NT-00021' Time='1/7/2010 1:10:00 PM'

                          So it appears I place the order at 13:08, it fills at 13:09, then plots at 13:10. I don't understand.

                          Comment


                            #14
                            toptrader,

                            Please just provide a NinjaScript Export of exactly the strategy you are using. We can only evaluate what we have and as Austin has shown, what we have worked so we need what you have to try and see what you are seeing. Thank you.
                            Josh P.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by JonesJoker, 04-22-2024, 12:23 PM
                            6 responses
                            32 views
                            0 likes
                            Last Post JonesJoker  
                            Started by GussJ, 03-04-2020, 03:11 PM
                            12 responses
                            3,239 views
                            0 likes
                            Last Post Leafcutter  
                            Started by AveryFlynn, Today, 04:57 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post AveryFlynn  
                            Started by RubenCazorla, 08-30-2022, 06:36 AM
                            3 responses
                            79 views
                            0 likes
                            Last Post PaulMohn  
                            Started by f.saeidi, Yesterday, 12:14 PM
                            9 responses
                            25 views
                            0 likes
                            Last Post f.saeidi  
                            Working...
                            X