Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

1 ATM order at a time, please

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

    #46
    No, you can still work with IOrder objects in the OnBarUpdate(), the event leasding to the method call is the key...OnBarUpdate() is called for each bar update (CalculateOnBarClose dependent), OnOrderUpdate() for each order state change (can be price, qty, overall fill state).

    Comment


      #47
      Uh-oh. My plan is to cancel the order should it not fill and then run 4 ticks away. Is that going to be an issue? Also, is there a formal code snippet I should be using for that?

      EDIT: Moved entry code to but still doesn't work. Please see attached.

      Thanks.
      Attached Files
      Last edited by dsraider; 02-03-2010, 04:20 PM.

      Comment


        #48
        Dave, unfortunately no snippet available for this - you just need to compare to your attempting limit order price and then cancel order them if your threshhold is breached.

        What is the TraceOrders output telling you on the latest change? Are orders placed, or not all? Any errors in the log?

        You may want to comment out most portions of the code and then slowly build from the ground up testing each step if the outcome is what you would expect...for example only work with one position first and don't scale in and use just static target and stop, once this works, you can safely move on to the next complexity level.

        Comment


          #49
          Orders aren't being entered at all so the Log and the Output window had nothing. Now that you fixed that "1a" bug for me (thanks again), I changed it back to a market order and everything works perfectly (including trails). That's what leads me to believe my limit order language may be wrong, but I just can't figure it out.

          UPDATE: for limit orders, when I leave the bool out, it places the order properly but cancels immediately citing cancellation due to end of bar. When I add the bool as true (and the other components) it doesn't trade at all:

          EnterLongLimit(0, true, 1, Open[-1], "Long 1a");

          or

          EnterLongLimit(0, true, DefaultQuantity), Open[-1], "Long 1a");
          Last edited by dsraider; 02-03-2010, 05:14 PM.

          Comment


            #50
            With liveUntilCancelled set to 'true' (the bool) - do you see any TraceOrders output mentioning of running into 'order ignored due to Internal Order Handling Rules'?

            Also the Open of 1 bar ago would be just Open[1], not Open[-1].

            Comment


              #51
              Got this:

              2/3/2010 6:23:04 PM Entered internal PlaceOrder() method at 2/3/2010 6:23:04 PM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1087.50 StopPrice=0 SignalName='Long 1a' FromEntrySignal=''
              2/3/2010 6:23:04 PM Ignored PlaceOrder() method at 2/3/2010 6:23:04 PM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1087.50 StopPrice=0 SignalName='Long 1a' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'

              Open[-1] is actually on purpose. I want to set my entry at the open of the next bar.

              Comment


                #52
                Bertrand!

                After a decent night's sleep and a LOT of coffee, I changed EntriesPerDirection to 2 and it now places my limit orders (stops, targets and trails work as well). I was under the impression that 'Entries' referred to sets, not to individual cars. Onto CancelOrder().

                Thanks,
                Dave

                Comment


                  #53
                  GM Dave, great thanks for reporting back - depends on which EntryHandling / EntriesPerDirection combo you use...with EntryHandling set to unique entries per direction at 1 should work for you.

                  Comment


                    #54
                    Morning Sir,

                    EntryHandling is set to UniqueEntries but it just wouldn't work until I changed EntriesPerDirection to 2. Maybe it has to do with the fact that I'm splitting my entries in half so that I can scale out?

                    Anyway, as you've probably expected from me, entering my CancelOrder() code is preventing orders again. Nothing in the output window but my log shows:

                    Error on calling 'OnBarUpdate' method for strategy 'RaiderTrendStrat': Index was out of range. Must be non-negative and less than the size of the collection.
                    Parameter name: index

                    when my cancel criteria is:

                    else if (entryOrder1 != null && GetCurrentBid() == Open[-1] + 2 * TickSize)
                    {
                    CancelOrder(entryOrder1);
                    CancelOrder(entryOrder2);
                    }

                    Changing Open[-1] to [0] allows it to load but no orders occur. Any hints?

                    Comment


                      #55
                      You would need a != null check for the second IOrder object, too Dave.

                      Also, you can't access an open value in the future, the most current accessible one is Open[0].

                      Comment


                        #56
                        Well, I thought I did it right but it just won't enter. It loads up fine in the Log but entries are missed and TraceOrders shows nothing. Going to start drinking early today...
                        Attached Files

                        Comment


                          #57
                          Dave, you want to reset the IOrders also if those are filled, meaning they are 'ready' for the next entry to be taken -

                          Code:
                           
                          protected override void OnOrderUpdate(IOrder order)
                          {
                          // Checks for all updates to entryOrder.
                          if (entryOrder1 != null && entryOrder1.Token == order.Token)
                          { 
                          // Check if entryOrder is cancelled.
                          if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled)
                          {
                          // Reset entryOrder back to null
                          entryOrder1 = null; 
                          } 
                           
                          } 
                          // Checks for all updates to entryOrder.
                          if (entryOrder2 != null && entryOrder2.Token == order.Token)
                          { 
                          // Check if entryOrder is cancelled.
                          if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled)
                          {
                          // Reset entryOrder back to null
                          entryOrder2 = null; 
                          } 
                           
                          }

                          Comment


                            #58
                            Thanks but I'm afraid that didn't do anything. In English, since my signal needs the bar to close and sets the entry at the open of the next bar. If that is 1000 long limit and it doesn't fill, the strat should self-cancel once it hits 1000.50. maybe it's my cancel logic?

                            Output window:

                            2/4/2010 3:14:50 PM Entered internal PlaceOrder() method at 2/4/2010 3:14:50 PM: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=1065.00 StopPrice=0 SignalName='Short 1a' FromEntrySignal=''
                            2/4/2010 3:14:50 PM Entered internal PlaceOrder() method at 2/4/2010 3:14:50 PM: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=1065.00 StopPrice=0 SignalName='Short 1b' FromEntrySignal=''
                            2/4/2010 3:14:51 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Long 1a' Mode=Ticks Value=8 Currency=0 Simulated=False
                            2/4/2010 3:14:51 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Long 1b' Mode=Ticks Value=8 Currency=0 Simulated=False
                            2/4/2010 3:14:51 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Short 1a' Mode=Ticks Value=8 Currency=0 Simulated=False
                            2/4/2010 3:14:51 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Short 1b' Mode=Ticks Value=8 Currency=0 Simulated=False
                            2/4/2010 3:16:10 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Short 1a' Mode=Price Value=1065 Currency=0 Simulated=False
                            2/4/2010 3:16:10 PM Amended stop order: Order='NT-00627/Sim101' Name='Stop loss' State=Working Instrument='ES 03-10' Action=BuyToCover Limit price=0 Stop price=1065 Quantity=1 Strategy='RaiderTrendStrat' Type=Stop Tif=Gtc Oco='NT-00415' Filled=0 Fill price=0 Token='f6d25067f4bb4e719a2e92365888b774' Gtd='12/1/2099 12:00:00 AM'
                            2/4/2010 3:16:10 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Short 1b' Mode=Price Value=1065 Currency=0 Simulated=False
                            2/4/2010 3:16:10 PM Amended stop order: Order='NT-00629/Sim101' Name='Stop loss' State=Working Instrument='ES 03-10' Action=BuyToCover Limit price=0 Stop price=1065 Quantity=1 Strategy='RaiderTrendStrat' Type=Stop Tif=Gtc Oco='NT-00416' Filled=0 Fill price=0 Token='fe2e9acf55c7496ab97a8120ef63f3dc' Gtd='12/1/2099 12:00:00 AM'
                            2/4/2010 3:16:10 PM previousPrice = 1065

                            2/4/2010 3:16:10 PM newPrice = 1065

                            2/4/2010 3:17:10 PM Cancelled pending exit order, since associated position is closed: Order='NT-00628/Sim101' Name='Profit target' State=Working Instrument='ES 03-10' Action=BuyToCover Limit price=1064 Stop price=0 Quantity=1 Strategy='RaiderTrendStrat' Type=Limit Tif=Gtc Oco='NT-00415' Filled=0 Fill price=0 Token='6f625381cbf9442dbb0d6598ba2e0007' Gtd='12/1/2099 12:00:00 AM'
                            2/4/2010 3:17:10 PM Cancelled OCO paired order: BarsInProgress=0: Order='NT-00628/Sim101' Name='Profit target' State=Cancelled Instrument='ES 03-10' Action=BuyToCover Limit price=1064 Stop price=0 Quantity=1 Strategy='RaiderTrendStrat' Type=Limit Tif=Gtc Oco='NT-00415' Filled=0 Fill price=0 Token='6f625381cbf9442dbb0d6598ba2e0007' Gtd='12/1/2099 12:00:00 AM'
                            2/4/2010 3:17:10 PM Cancelled pending exit order, since associated position is closed: Order='NT-00630/Sim101' Name='Profit target' State=Working Instrument='ES 03-10' Action=BuyToCover Limit price=1063 Stop price=0 Quantity=1 Strategy='RaiderTrendStrat' Type=Limit Tif=Gtc Oco='NT-00416' Filled=0 Fill price=0 Token='a7fa6a68ac5a4ee7a4b5166c933de444' Gtd='12/1/2099 12:00:00 AM'
                            2/4/2010 3:17:11 PM Cancelled OCO paired order: BarsInProgress=0: Order='NT-00630/Sim101' Name='Profit target' State=Cancelled Instrument='ES 03-10' Action=BuyToCover Limit price=1063 Stop price=0 Quantity=1 Strategy='RaiderTrendStrat' Type=Limit Tif=Gtc Oco='NT-00416' Filled=0 Fill price=0 Token='a7fa6a68ac5a4ee7a4b5166c933de444' Gtd='12/1/2099 12:00:00 AM'

                            PnL was changing under 'Unrealized' but everything else (including the DOM) didn't move.

                            ???

                            UPDATE: It is now placing orders (you got me) but haven't tested the CancelOrder() part.
                            Last edited by dsraider; 02-04-2010, 02:43 PM.

                            Comment


                              #59
                              Dave, ok great - please also add visual checks (for example drawing objects such as dots, arrows) on your conditions evaluating 'true' - this will help you immensly debug those if needed.

                              For the CancelOrder(), please keep in mind GetCurrentBid / Ask is replaced by the Close value in backtesting, thus may have to test in realtime only with this logic...

                              Just add to the OnBarUpdate() start -

                              Code:
                               
                              if (Historical) return;

                              Comment


                                #60
                                Done and done. As far as Bid/Ask is concerned, I wanted to use something like if(CurrentPrice > EntrySignal + 2 * TickSize) but couldn't find it.

                                Will report back. Thanks for another day of help.

                                Dave

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Today, 05:17 AM
                                0 responses
                                25 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                121 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                64 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                41 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                46 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X