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

EnterLongStop problems

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

    EnterLongStop problems

    I'm trying a simple breakout strategy using EnterLongStop. When I give a signal name, sometimes the order does not get transmitted and when I remove the signal, all of the orders go through:

    Sometimes fails:
    EnterLongStop(size, top, "bb " + orderCount);

    Always works:
    EnterLongStop(size, top);


    The frustrating thing is that the first one doesn't always fail, it just fails on some occasions but it consistently fails on these occasions. If I comment out one line and uncomment the other, then I can just toggle these trades on or off.

    What's going on, is this a bug?

    Edit: I'm using version 6.5.1000.1

    #2
    Please enable TraceOrders and see the Output window to see why calls to this method sometimes fails.

    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      Please enable TraceOrders and see the Output window to see why calls to this method sometimes fails.

      http://www.ninjatrader-support.com/H...aceOrders.html
      It is saying that my order was ignored:

      Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'

      I placed one EnterLongStop at 10:10 am, and expecting this to be cancelled at the end of the bar, I placed a second EnterLongStop. Both are received:

      4/1/2008 10:10:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:10:00 AM: Action=Buy OrderType=Stop Quantity=1,082 LimitPrice=0 StopPrice=36.96 SignalName='Long 1' FromEntrySignal=''
      4/1/2008 10:15:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:15:00 AM: Action=Buy OrderType=Stop Quantity=1,082 LimitPrice=0 StopPrice=36.96 SignalName='Long 2' FromEntrySignal=''


      Just to be sure that the orders were being cancelled automatically, I used the fill EnterLongStop:

      EnterLongStop(0, false, size, top, "Long " + orderCount);


      So, here's the problem: the first order is being cancelled, but it's apparently cancelled after I call EnterLongStop the second time. The very next bar, price moves through my stop price and the second EnterLongStop should catch it, but it has been ignored and the first EnterLongStop is cancelled.

      What are we supposed to do?

      Comment


        #4
        FWIW, here is the full log in order. Notice the time that the 'Ignore' is exactly the same as the Cancel, only the Cancel comes after. This doesn't give strategy writers the opportunity to keep a buy stop order in place.

        4/1/2008 10:10:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:10:00 AM: Action=Buy OrderType=Stop Quantity=1,082 LimitPrice=0 StopPrice=36.96 SignalName='Long 1' FromEntrySignal=''
        4/1/2008 10:15:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:15:00 AM: Action=Buy OrderType=Stop Quantity=1,082 LimitPrice=0 StopPrice=36.96 SignalName='Long 2' FromEntrySignal=''
        4/1/2008 10:15:00 AM Ignored PlaceOrder() method at 4/1/2008 10:15:00 AM: Action=Buy OrderType=Stop Quantity=1,082 LimitPrice=0 StopPrice=36.96 SignalName='Long 2' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
        4/1/2008 10:15:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00000/Back101' Name='Long 1' State=Working Instrument='FMCN' Action=Buy Limit price=0 Stop price=36.96 Quantity=1,082 Strategy='SimpleBreakStrategy' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='efb2317d527344e6b0320ea28c956a73' Gtd='12/1/2099 12:00:00 AM'

        Comment


          #5
          Interesting adrian.
          Do you mind posting a simple as possible strategy demonstrating what you are experience? I would like to run some experiments on them. Thanks.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Josh,

            You could try this:
            Code:
            #region Using declarations
            using System;
            using System.ComponentModel;
            using System.Diagnostics;
            using System.Drawing;
            using System.Drawing.Drawing2D;
            using System.Xml.Serialization;
            using NinjaTrader.Cbi;
            using NinjaTrader.Data;
            using NinjaTrader.Indicator;
            using NinjaTrader.Gui.Chart;
            using NinjaTrader.Strategy;
            #endregion
            
            // This namespace holds all strategies and is required. Do not change it.
            namespace NinjaTrader.Strategy
            {
                /// <summary>
                /// Enter the description of your strategy here
                /// </summary>
                [Description("Enter the description of your strategy here")]
                public class LongStopDemoStrategy : Strategy
                {
                    #region Variables
                    // Wizard generated variables
                    private int myInput0 = 1; // Default setting for MyInput0
                    // User defined variables (add any user defined variables below)
                    private int orderCount = 0;
                    #endregion
            
                    /// <summary>
                    /// This method is used to configure the strategy and is called once before any strategy method is called.
                    /// </summary>
                    protected override void Initialize()
                    {
                        CalculateOnBarClose = true;
                        TraceOrders = true;
                    }
            
                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                        int openBar = Bars.BarsSinceSession;
                        int highBar = HighestBar(High, openBar);
                        if( High[highBar] - High[0] < .10 ) {
                            double top = High[highBar];
                            DrawLine("break" + CurrentBar, 1, top, 0, top, Color.Blue);
                            int size = 100;
                            orderCount++;
                            EnterLongStop(100, top, "bb " + orderCount);
                        }
                    }
            
                    #region Properties
                    [Description("")]
                    [Category("Parameters")]
                    public int MyInput0
                    {
                        get { return myInput0; }
                        set { myInput0 = Math.Max(1, value); }
                    }
                    #endregion
                }
            }
            I'm running it against FMCN with data from 1 April 2008 and for clarity, I'm drawing a line where the EnterLongStop order is being placed. Around mid-day, price moves up and clearly breaks through the high of the day, but the order isn't filled. Here is the output, times in Pacific Time:

            Code:
            4/1/2008 8:15:00 AM Entered internal PlaceOrder() method at 4/1/2008 8:15:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=36.96 SignalName='bb 1' FromEntrySignal=''
            4/1/2008 8:20:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00000/Back101' Name='bb 1' State=Working Instrument='FMCN' Action=Buy Limit price=0 Stop price=36.96 Quantity=100 Strategy='LongStopDemoStrategy' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='71c152bf394441cca710707386699ca1' Gtd='12/1/2099 12:00:00 AM'
            4/1/2008 10:10:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:10:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=36.96 SignalName='bb 2' FromEntrySignal=''
            4/1/2008 10:15:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:15:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=36.96 SignalName='bb 3' FromEntrySignal=''
            4/1/2008 10:15:00 AM Ignored PlaceOrder() method at 4/1/2008 10:15:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=36.96 SignalName='bb 3' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
            4/1/2008 10:15:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00001/Back101' Name='bb 2' State=Working Instrument='FMCN' Action=Buy Limit price=0 Stop price=36.96 Quantity=100 Strategy='LongStopDemoStrategy' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='f6f04321651e49e9a6fb655f805d6a7c' Gtd='12/1/2099 12:00:00 AM'
            4/1/2008 10:20:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:20:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=37.36 SignalName='bb 4' FromEntrySignal=''
            4/1/2008 10:25:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00002/Back101' Name='bb 4' State=Working Instrument='FMCN' Action=Buy Limit price=0 Stop price=37.36 Quantity=100 Strategy='LongStopDemoStrategy' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='14df54ed2e07406eb8ffbe24004d378b' Gtd='12/1/2099 12:00:00 AM'
            4/1/2008 10:35:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:35:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=37.49 SignalName='bb 5' FromEntrySignal=''
            4/1/2008 10:40:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:40:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=37.49 SignalName='bb 6' FromEntrySignal=''
            4/1/2008 10:40:00 AM Ignored PlaceOrder() method at 4/1/2008 10:40:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=37.49 SignalName='bb 6' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
            4/1/2008 10:40:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00003/Back101' Name='bb 5' State=Working Instrument='FMCN' Action=Buy Limit price=0 Stop price=37.49 Quantity=100 Strategy='LongStopDemoStrategy' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='97fc88c0290f4b0e916b9edddf4f6da9' Gtd='12/1/2099 12:00:00 AM'
            The order should be placed at 10:15 and filled on the 10:20 bar. Instead, what we see is the PlaceOrder() logged, then this is ignored because it exceeds the number of entries, and then the 10:10 order is cancelled.


            Pardon the slight complexity in the strategy. When I run this just madly blasting out EnterLongStop(), some are filled and some aren't, but this case is replicatable and repeatable, at least with my data. Let me know if there's anything else you need.

            Comment


              #7
              Hi adrian,

              I believe the issue you are facing is attributed to the strategy not resubmitting your preexisting order to keep it alive. NinjaTrader will automatically cancel orders that are not resubmitted at every bar. To work around this you can set a "liveUntilCancelled" parameter to true. With this parameter the order will not require resubmissions at every bar.

              Please use this overload:
              EnterLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName)

              barsInProgressIndex should be 0 if you want to submit to your primary bar series.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by Josh View Post
                I believe the issue you are facing is attributed to the strategy not resubmitting your preexisting order to keep it alive. NinjaTrader will automatically cancel orders that are not resubmitted at every bar. To work around this you can set a "liveUntilCancelled" parameter to true. With this parameter the order will not require resubmissions at every bar.
                I don't think so. I want the order to be cancelled, but the cancel is taking place after the OnBarUpdate event is called (under some circumstances) so that when I try to place a new order, it gets rejected.

                Please use this overload:
                EnterLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName)

                barsInProgressIndex should be 0 if you want to submit to your primary bar series.
                I've tried that as well, and the same bug is present with this method as well. If you look at the trace, the order is placed, then Ninja ignores it, and then the first order is cancelled.

                It doesn't happen all the time, but on some occasions (I haven't figured out which) when you submit two EnterLongStop orders on two consecutive bars, it breaks.

                The work around I've been using is to store the IOrder and manually cancel it at the start of the OnBarUpdate.

                Comment


                  #9
                  Josh,

                  I'm now using 'EnterLongStop(0, false, 100, top, "bb " + orderCount);' to enter my position and the exact same problem is happening.

                  Check out the log: 'bb 2' is placed at 10:10am, then at 10:15am the next OnBarUpdate() is called and 'bb 3' is placed, which is ignored because there are too many entries.

                  What should happen and what does happen in most cases, is 'bb 2' is placed, then 'bb 2' is cancelled and then 'bb 3' is placed. The sequencing has gotten messed up for some reason:
                  Code:
                  4/1/2008 10:10:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:10:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=36.96 SignalName='bb 2' FromEntrySignal=''
                  4/1/2008 10:15:00 AM Entered internal PlaceOrder() method at 4/1/2008 10:15:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=36.96 SignalName='bb 3' FromEntrySignal=''
                  4/1/2008 10:15:00 AM Ignored PlaceOrder() method at 4/1/2008 10:15:00 AM: Action=Buy OrderType=Stop Quantity=100 LimitPrice=0 StopPrice=36.96 SignalName='bb 3' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
                  4/1/2008 10:15:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00001/Back101' Name='bb 2' State=Working Instrument='FMCN' Action=Buy Limit price=0 Stop price=36.96 Quantity=100 Strategy='LongStopDemoStrategy' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='72d2d157ae6e42e28968081bd89cd49f' Gtd='12/1/2099 12:00:00 AM'

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Jonafare, 12-06-2012, 03:48 PM
                  5 responses
                  3,984 views
                  0 likes
                  Last Post rene69851  
                  Started by Fitspressorest, Today, 01:38 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Fitspressorest  
                  Started by Jonker, Today, 01:19 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Jonker
                  by Jonker
                   
                  Started by futtrader, Today, 01:16 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post futtrader  
                  Started by Segwin, 05-07-2018, 02:15 PM
                  14 responses
                  1,791 views
                  0 likes
                  Last Post aligator  
                  Working...
                  X