Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Handling & Parameters

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

    Order Handling & Parameters

    Hi again.

    This is probably something simple, but I need to ask for a little help because I'm confused with the help files and the description of the EXIT functions.

    I'm trying to use the following orders to setup a STOP and TARGET exit for a project.

    PHP Code:
    stopOrder ExitLongStop(0trueDefaultQuantity, (StopPriceBase ATR(ATRLength)[1]), "JSStop""Long Hammer Stop");
    targetOrder ExitLongStopLimit(0trueDefaultQuantity, (ExecutionPriceBase ATR(ATRLength)[1]), (ExecutionPriceBase ATR(ATRLength)[1]), "JSTarget"); 

    When I try to compile, I get a message stating "No Overload for Method ??; takes 5 arguments" or "6 arguments".

    Yet, in the online help, the ExitLongStop function shows a total of 6 parameters/arguments...

    ExitLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal)

    So, until I get a little help on how to setup the parameters for these functions, I guess I'm stuck. Which is it.. 5 or 6 arguments?

    Can someone show me a proper syntax for these two functions? I'm trying to develop some complex order handling functions and I'm getting stuck with the documentation and variances in the descriptions. It appears the sample descriptions are VERY SIMPLE and as soon as I try to pass the parameters shown in the help files, I get more errors than I expect.

    Thanks in advance.

    #2
    Bmatheny, correct for the advanced overload for the ExitLongStopLimit you would have 6 parameters, it looks like you're missing one signal name tag here in this call to make it compile.

    ExitLongStopLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, double stopPrice, string signalName, string fromEntrySignal)
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I tried that, it threw the error about needing 5 arguments.

      When I got rid of the extra string parameter, it would not compile.

      Let me try to get you some sample code to review.

      B

      Comment


        #4
        Bmatheny, I would then suggest reviewing the call you do via Intellisense parameter by parameter, this would tell you exactly what the compiler would expect for each overload offered.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          First off, thank you for all the help you have provided over the past few days. Using the examples I've found and plugging thru my code, I'm almost there.

          But...

          I still have a problem that I'm trying to address.

          I'm using the iOrder structure to control my 4 orders. I have two entry orders (one on either side of the trigger price) and one target and one stop order.

          private IOrder entryOrder1 = null;
          private IOrder entryOrder2 = null;
          private IOrder stopOrder = null;
          private IOrder targetOrder = null;

          I've developed the code to handle the entries and the exits using the iOrder structures and conditions.

          When the trade completes (either a stop or target), I'm trying to reset the iOrder structures by setting them to null.. like this.

          entryOrder1 = null;

          But it appears I get an error with this statement (even though it clearly shows in the help files this is how you reset the iOrder values). This is the error I get. Can you please assist me with regards to this error??

          **NT** Error on calling 'OnOrderUpdate' method for strategy 'EmeryV2/ffab658e97ad4bc3a31415d5294c48a4': Object reference not set to an instance of an object.

          Here is a snippet of my code to handle the stop and target exits.

          PHP Code:
          // Stop Order Filled
          if ((stopOrder != null) && (stopOrder == order))
          {
          Print(
          " Stop Order Filled :: "+order.ToString());
          if (
          order.OrderState == OrderState.Filled)
          {
          CancelOrder(targetOrder);
          entryOrder1 null;
          entryOrder2 null;
          stopOrder null;
          targetOrder null;
          entryDirection 0
          StopPriceBase 0
          ExecutionPriceBase 0

          }
          }

          // Target Order Filled
          if ((targetOrder != null) && (targetOrder == order))
          {
          Print(
          " Target Order Filled :: "+order.ToString());
          if (
          order.OrderState == OrderState.Filled)
          {
          CancelOrder(stopOrder);
          entryOrder1 null;
          entryOrder2 null;
          stopOrder null;
          targetOrder null;
          entryDirection 0
          StopPriceBase 0
          ExecutionPriceBase 0

          }


          Comment


            #6
            to further assist you in helping me, I wanted to add the following.

            _ I am declaring the IOrder structures only once.
            _ I have commented out the "= null" statements for the stop and target orders thinking they could reset or destroy the IOrder structures, but that has not changed anything
            _ It appears the error is related to an order structure that has been destroyed or is invalid.
            _ I am cancelling the orders using the CancelOrder function, so I assume the IOrder structure is still in place.
            _ I have four functions in the OnOrderUpdate function to handle the four types of orders I'm managing. Could there be a problem in how I've structured the OnOrderUpdate function?

            BTW, this error appears to happen at the END of the trade process (where the stop or target order is filled). I'm attaching the OUTPUT of the project to try to better assist you in helping me.

            PHP Code:
            **NT** Enabling NinjaScript strategy 'EmeryV2/afcce801108d4e31a979abf0dc4af33e' On starting a real-time strategy StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=20 StopTargetHandling=PerEntryExecution ErrorHandling=TakeNoAction ExitOnClose=Truetriggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes
            Bullish Hammer Found
            Order
            ='NT-00000/Sim101' Name='Long Hammer Stop' State=PendingSubmit Instrument='NQ 12-12' Action=Buy Limit price=0 Stop price=2646.75 Quantity=1 Strategy='EmeryV2' Type=Stop Tif=Day Oco='' Filled=0 Fill price=0 Token='19572c74dcb94390855e6035f9bbe6bd' Gtd='12/1/2099 12:00:00 AM'
            Order='NT-00000/Sim101' Name='Long Hammer Stop' State=Accepted Instrument='NQ 12-12' Action=Buy Limit price=0 Stop price=2646.75 Quantity=1 Strategy='EmeryV2' Type=Stop Tif=Day Oco='' Filled=0 Fill price=0 Token='19572c74dcb94390855e6035f9bbe6bd' Gtd='12/1/2099 12:00:00 AM'
            Order='NT-00000/Sim101' Name='Long Hammer Stop' State=Working Instrument='NQ 12-12' Action=Buy Limit price=0 Stop price=2646.75 Quantity=1 Strategy='EmeryV2' Type=Stop Tif=Day Oco='' Filled=0 Fill price=0 Token='19572c74dcb94390855e6035f9bbe6bd' Gtd='12/1/2099 12:00:00 AM'
            Order='NT-00001/Sim101' Name='Long Hammer Low Limit' State=PendingSubmit Instrument='NQ 12-12' Action=Buy Limit price=2643.5 Stop price=0 Quantity=1 Strategy='EmeryV2' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='b5701647953a4db58f2e76909325aa8b' Gtd='12/1/2099 12:00:00 AM'
            Order='NT-00001/Sim101' Name='Long Hammer Low Limit' State=Accepted Instrument='NQ 12-12' Action=Buy Limit price=2643.5 Stop price=0 Quantity=1 Strategy='EmeryV2' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='b5701647953a4db58f2e76909325aa8b' Gtd='12/1/2099 12:00:00 AM'
            Order='NT-00001/Sim101' Name='Long Hammer Low Limit' State=Working Instrument='NQ 12-12' Action=Buy Limit price=2643.5 Stop price=0 Quantity=1 Strategy='EmeryV2' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='b5701647953a4db58f2e76909325aa8b' Gtd='12/1/2099 12:00:00 AM'
            Order='NT-00001/Sim101' Name='Long Hammer Low Limit' State=Filled Instrument='NQ 12-12' Action=Buy Limit price=2643.5 Stop price=0 Quantity=1 Strategy='EmeryV2' Type=Limit Tif=Day Oco='' Filled=1 Fill price=2643.5 Token='b5701647953a4db58f2e76909325aa8b' Gtd='12/1/2099 12:00:00 AM'
            Order='NT-00000/Sim101' Name='Long Hammer Stop' State=PendingCancel Instrument='NQ 12-12' Action=Buy Limit price=0 Stop price=2646.75 Quantity=1 Strategy='EmeryV2' Type=Stop Tif=Day Oco='' Filled=0 Fill price=0 Token='19572c74dcb94390855e6035f9bbe6bd' Gtd='12/1/2099 12:00:00 AM'
            Order='NT-00000/Sim101' Name='Long Hammer Stop' State=Cancelled Instrument='NQ 12-12' Action=Buy Limit price=0 Stop price=2646.75 Quantity=1 Strategy='EmeryV2' Type=Stop Tif=Day Oco='' Filled=0 Fill price=0 Token='19572c74dcb94390855e6035f9bbe6bd' Gtd='12/1/2099 12:00:00 AM'
             
            Target Order Filled :: Order='NT-00002/Sim101' Name='JSTarget' State=PendingSubmit Instrument='NQ 12-12' Action=Sell Limit price=2644.55670911982 Stop price=0 Quantity=1 Strategy='EmeryV2' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='08bb56b2d0774dc2a1b9f4445cc07b29' Gtd='12/1/2099 12:00:00 AM'
             
            Target Order Filled :: Order='NT-00002/Sim101' Name='JSTarget' State=Accepted Instrument='NQ 12-12' Action=Sell Limit price=2644.55670911982 Stop price=0 Quantity=1 Strategy='EmeryV2' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='08bb56b2d0774dc2a1b9f4445cc07b29' Gtd='12/1/2099 12:00:00 AM'
             
            Target Order Filled :: Order='NT-00002/Sim101' Name='JSTarget' State=Working Instrument='NQ 12-12' Action=Sell Limit price=2644.55670911982 Stop price=0 Quantity=1 Strategy='EmeryV2' Type=Limit Tif=Day Oco='' Filled=0 Fill price=0 Token='08bb56b2d0774dc2a1b9f4445cc07b29' Gtd='12/1/2099 12:00:00 AM'
             
            Target Order Filled :: Order='NT-00002/Sim101' Name='JSTarget' State=Filled Instrument='NQ 12-12' Action=Sell Limit price=2644.55670911982 Stop price=0 Quantity=1 Strategy='EmeryV2' Type=Limit Tif=Day Oco='' Filled=1 Fill price=2644.55670911982 Token='08bb56b2d0774dc2a1b9f4445cc07b29' Gtd='12/1/2099 12:00:00 AM'
            **NT** Error on calling 'OnOrderUpdate' method for strategy 'EmeryV2/afcce801108d4e31a979abf0dc4af33e'Object reference not set to an instance of an object

            Comment


              #7
              Additionally, why would it show TARGET ORER FILLED 4 times? Does this mean that the system is reporting the target order filled and completed with 4 separate instances?

              Comment


                #8
                Bmatheny, you see prints for each update your order here going from PendingSubmit to eventually filled. The OnOrderUpdate() is called for each change in the order state, so an expected outcome.

                For driving strategy logic on fills, it would be recommend to work in the OnExecution() method - a reference sample showing the approach at work would be found here - http://www.ninjatrader.com/support/f...ead.php?t=7499

                The object reference error means that there's still an IOrder property in your OnOrderUpdate() you're trying access when it's null / empty.

                One effective way to get more granular feedback where this would be happening in your code is using standard C# Try / Catch blocks - http://www.ninjatrader.com/support/f...ead.php?t=9825
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Thankyou for your quick reply. I found the error early this AM. It appears my strategy is throwing errors because I'm executing tight stop and target orders. The error is generated because I'm executing a stop or target order WITHIN a bar range and NT is rejecting the order. Even though the order would be valid at the time of entry, in real time.

                  Is there any way to address this? The system I've built is designed to scalp only 2~5 ticks, but I'm waiting for the entry order to be filled, then firing the stop and target orders. In the case of a big bar, or a tight 2 tick target, I often get a bar that triggers/fills the entry, but has already passed my target (in historical mode).

                  Any suggestions??

                  Comment


                    #10
                    When backtesting, the events will be triggered at the end of the bar.

                    If you would like to backtest with intrabar granularity, you would need to add a finer data series, such as a tick series to submit the orders to intrabar.

                    Please see our Reference Sample on this topic for more information:

                    You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Good Morning,

                      Been working with my project now for a bit and noticed some interesting price data when I turned my strategy on. I'm using IB as a data feed to NT and without my strategy enabled, the price bars appear to update perfectly. When I turn my strategy on, it get all kinds of funky bars on the chart.

                      The oddest part of all of this is I'm only running ONE CHART. So I can't imaging that NT is processing my script so slow that it messes up the chart data?

                      But, in any event, I did some digging and found another condition to test for filled orders and have recently converted my strategy to this new function. Below, I have summarized what I'm trying to do and posted some code examples. Please provide me some direction as to why my script (all of about 300 lines of code) would cause NT to start screwing up the price data and such.

                      Initially, I was using ..

                      PHP Code:
                      protected override void OnOrderUpdate(IOrder order)
                        {
                      //   Print("Pre Entry1 Test "+entryOrder1);
                         
                      if ((PendingEntry == true) && (entryOrder1 != null) &&(entryOrder1 == order))
                         {
                          if (
                      order.OrderState == OrderState.Filled)
                          {
                           Print(
                      order.ToString());
                           
                      ExecutionPriceBase order.AvgFillPrice
                           
                      CancelOrder(entryOrder2);
                           if (
                      PendingentryDirection 0
                           {
                            
                      entryDirection PendingentryDirection;
                            
                      PendingentryDirection 0;
                            
                      stopOrder ExitLongStop(0trueMath.Abs(entryDirection), (ExecutionPriceBase ATRBase), "JSStop""");
                            
                      targetOrder ExitLongLimit(0trueMath.Abs(entryDirection), (ExecutionPriceBase ATRBase), "JSTarget""");
                      //      targetOrder = ExitLongStopLimit(0, true, DefaultQuantity, (ExecutionPriceBase + ATR(ATRLength)[1]), (ExecutionPriceBase + ATR(ATRLength)[1]), "JSTarget", "");
                           
                      }
                           if (
                      PendingentryDirection 0
                           {
                            
                      entryDirection PendingentryDirection;
                            
                      PendingentryDirection 0;
                            
                      stopOrder ExitShortStop(0trueMath.Abs(entryDirection), (ExecutionPriceBase ATRBase), "JSStop""");
                            
                      targetOrder ExitShortLimit(0trueMath.Abs(entryDirection), (ExecutionPriceBase ATRBase), "JSTarget""");
                      //      targetOrder = ExitShortStopLimit(0, true, DefaultQuantity, (ExecutionPriceBase + ATR(ATRLength)[1]), (ExecutionPriceBase + ATR(ATRLength)[1]), "JSTarget", "");
                           
                      }
                           
                      PendingEntry false;
                          }
                         }
                       
                      ...  
                      Order #2

                      For all my order handling. I'm guessing this is the problem (checking the orders each tick). I also had to create a "once per bar" feature with NT because my triggers are checked at the beginning of each new bar. So I developed the following to handle it (no biggie).

                      PHP Code:
                        if (CurrentBar != lastCurrentBar) {
                         
                      lastCurrentBar CurrentBar;
                         ..  
                      Check for new order triggers
                       
                        

                      What I'm trying now to handle the orders is as follows..

                      PHP Code:
                       
                      protected override void OnExecution(IExecution execution)
                      {
                      if (
                      entryOrder1 != null && entryOrder1 == execution.Order)
                      {
                      // Print(execution.ToString());

                      Print(execution.ToString());
                      ExecutionPriceBase entryOrder1.AvgFillPrice
                      CancelOrder(entryOrder2);
                      // entryOrder1 = null;
                      if (PendingentryDirection 0
                      {
                      entryDirection PendingentryDirection;
                      PendingentryDirection 0;
                      stopOrder ExitLongStop(0trueMath.Abs(entryDirection), (ExecutionPriceBase ATRBase), "JSStop""");
                      targetOrder ExitLongLimit(0trueMath.Abs(entryDirection), (ExecutionPriceBase ATRBase), "JSTarget""");
                      // targetOrder = ExitLongStopLimit(0, true, DefaultQuantity, (ExecutionPriceBase + ATR(ATRLength)[1]), (ExecutionPriceBase + ATR(ATRLength)[1]), "JSTarget", "");
                      }
                      if (
                      PendingentryDirection 0
                      {
                      entryDirection PendingentryDirection;
                      PendingentryDirection 0;
                      stopOrder ExitShortStop(0trueMath.Abs(entryDirection), (ExecutionPriceBase ATRBase), "JSStop""");
                      targetOrder ExitShortLimit(0trueMath.Abs(entryDirection), (ExecutionPriceBase ATRBase), "JSTarget""");
                      // targetOrder = ExitShortStopLimit(0, true, DefaultQuantity, (ExecutionPriceBase + ATR(ATRLength)[1]), (ExecutionPriceBase + ATR(ATRLength)[1]), "JSTarget", "");
                      }
                      PendingEntry false
                      }

                      My intention is to develop more complex strategies and deploy them for my clients. But I have to be honest, if NT has specific tricks to developing simple strategies like this, then it sure would be nice to know all of them up front???

                      Any help woudl be appreciated..

                      Nope. No luck. Here are some screen shots showing the problems. I need to know why this is acting this way. I really can't believe my strategy is causing this problem??
                      Attached Files

                      Comment


                        #12
                        Hi Bmatheny, have not see a case yet where a custom strategy affected the price data in such a way - is this seen with NT7 R11 and TWS 927.7 here? Would you see the same behavior if the SampleMACrossOver for example is added to the same chart? If you reload historical data, would the data then normalize?
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Yes, if I remove or reload my strategy, then the data is refreshed from IB (it appears).

                          Let me check my IB version.

                          Build 922.6 Jan 2012

                          The odd thing is without my strategy, everything works fine. When I add my strategy, then it starts messing up. I'm trying to create a sample strategy that you can evaluate on your end.

                          The other thing I should mention is I'm using a compound IF statement for my entries. Like this.

                          PHP Code:
                          if ( ((Condition1 == true) && (Condition2 == true)) &&
                            ( ((
                          cond3) && (cond4) && (cond5)) ||
                              ((
                          cond6) && (cond7) && (cond8)) ||
                              ((
                          cond9) && (cond10) && (cond11))
                            )  
                          ) {
                            if (!
                          Historical) {
                              ... 
                          Trade Actions
                            
                          }
                          }
                           
                          Do 
                          you think this could cause a problem?  I've never had any issues with other languages running compound conditions like this. 

                          Comment


                            #14
                            Thanks Bmatheny - no from my experience I would not think this syntax used is contributing.

                            For the TWS, please ensure to run the 927.7 we recommend using in our connection guide here -



                            Once this is installed, please retry with your code and see if you would get the same behavior - if you do I would appreciate an example sent to support that we could run here to further investigate.
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Sorry it took so long for me to get back to you. I have lots of projects going on at this time.

                              Same issue. I have no idea why this is happening. I have attached the chart for you to see an am going to work on a sample script with the same structure so you can see how I've got everything setup.

                              I can't imagine I'm doing much wrong here. This is a simple script and I tried to follow many of the examples in the code help. I will post the sample strategy as soon as I create it.

                              Oddly, it appears to happen as soon as it enters the ENTRY TRADE. After it enters the entry trade, I setup a check function to see if it filled and then set two orders to handle the stop and target, then start check those orders as well. I'm wondering if it has anything to do with how the IOrder feature works. I thought resetting those values to null would reset them for future use and clear the stored values, but now I'm thinking I may have to re-declare them.

                              Weee. fun with NinjaTrader.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Belfortbucks, Today, 09:29 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Belfortbucks  
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              151 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Working...
                              X