Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLong not firing when called in OnExecutionUpdate

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

    EnterLong not firing when called in OnExecutionUpdate

    Hi,

    I hope you can help me please. I'm trying to code an iceberg order that places an initial long order, waits to monitor the fills, and once filled submits a further long order (rinsing and repeating). My code isn't working as only the first order submits and fills, the second order is not firing (but should, my debug statements before my EnterLong() request are being called). I've tried simplifying the code down to its very basics in an attempt to debug but it's still not working. I'm sharing the basic code below and example print statements. Please could anyone take a look at the code and print statements here and let me know if I'm missing something fundamental? I've run this on Sim101 for ticker AMZN on 10sec bars using Chart and adding Strategy.

    Firstly I've attached the code - it does a basic entry if Close is above a moving average. There's no exit logic in here (just trying to enter properly first).

    Secondly, here is the print statement when testing this using my Sim101 account. You can see that it fires the initial EnterLong correctly, and this first batch fills. The last two lines are debug statements that surround the EnterLong request within OnExecutionUpdate that should make a second order for qty=100. This implied that the code is being called within OnExecutionUpdate, but for an unknown reason its not firing. When I look at my control center orders tab, it doesn't show any second order of 100 qty.

    Code:
    Enabling NinjaScript strategy 'TestingEnterLongWIthinOnExecutionUpdate/238461547' : On starting a real-time strategy - StartBehavior=WaitUntilFlat AccountPosition=AMZN 600L EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
    Debug1 Time: 9/8/2022 3:55:50 PM, State: Realtime, Close[0]: 129.57, _emaClose[0]: 129.500466717952
    Debug2 Time: 9/8/2022 3:55:50 PM, State: Realtime, Close[0]: 129.57, _emaClose[0]: 129.500466717952
    Entry OnOrderUpdate Ticker: AMZN, Time[0]: 9/8/2022 3:55:50 PM, BarsInProgress: 0, Setting entryOrder = order: orderId='27330b53a8ca4846a8b12fe00c666648' account='Sim101' name='BuyLong1' orderState=Submitted instrument='AMZN' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=200 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=1107 time='2022-09-08 15:55:52' gtd='2099-12-01' statementDate='2022-09-08'. Rule: order.Name == BuyLong1
    Entry OnOrderUpdate Ticker: AMZN, Time[0]: 9/8/2022 3:55:50 PM, BarsInProgress: 0, Setting entryOrder = order: orderId='27330b53a8ca4846a8b12fe00c666648' account='Sim101' name='BuyLong1' orderState=Accepted instrument='AMZN' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=200 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=1107 time='2022-09-08 15:55:52' gtd='2099-12-01' statementDate='2022-09-08'. Rule: order.Name == BuyLong1
    Entry OnOrderUpdate Ticker: AMZN, Time[0]: 9/8/2022 3:55:50 PM, BarsInProgress: 0, Setting entryOrder = order: orderId='27330b53a8ca4846a8b12fe00c666648' account='Sim101' name='BuyLong1' orderState=Working instrument='AMZN' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=200 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=1107 time='2022-09-08 15:55:52' gtd='2099-12-01' statementDate='2022-09-08'. Rule: order.Name == BuyLong1
    Entry OnOrderUpdate Ticker: AMZN, Time[0]: 9/8/2022 3:55:50 PM, BarsInProgress: 0, Setting entryOrder = order: orderId='27330b53a8ca4846a8b12fe00c666648' account='Sim101' name='BuyLong1' orderState=Filled instrument='AMZN' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=200 tif=Gtc oco='' filled=200 averageFillPrice=129.58 onBehalfOf='' id=1107 time='2022-09-08 15:55:52' gtd='2099-12-01' statementDate='2022-09-08'. Rule: order.Name == BuyLong1
    ENTRY OnExecutionUpdate Ticker: AMZN, execution.Time: 9/8/2022 3:55:52 PM, Time[0]: 9/8/2022 3:55:50 PM, BarsInProgress: 0, CurrentBar: 6994, execution.Order.OrderState: Filled, execution.Order.Filled: 200, sumFilled: 200, entryOrder: orderId='27330b53a8ca4846a8b12fe00c666648' account='Sim101' name='BuyLong1' orderState=Filled instrument='AMZN' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=200 tif=Gtc oco='' filled=200 averageFillPrice=129.58 onBehalfOf='' id=1107 time='2022-09-08 15:55:52' gtd='2099-12-01' statementDate='2022-09-08', execution.OrderId: 27330b53a8ca4846a8b12fe00c666648, execution.Name: BuyLong1, Message: We sum the quantities of each execution making up the entry order.
    0. Time: 9/8/2022 3:55:50 PM, buyBatchQty: 200, sumFilled: 200, buyBatchQty == sumFilled: True, execution.Order.OrderState: Filled,
    1a. Time: 9/8/2022 3:55:50 PM
    1b. Time: 9/8/2022 3:55:50 PM
    3. Time: 9/8/2022 3:55:50 PM
    5. Time: 9/8/2022 3:55:50 PM
    6. Time: 9/8/2022 3:55:50 PM, startBuyingSlot: 2, buyBatchQty: 100, myBuyOrder: BuyLong2, BarsInProgress: 0, latestBuyBar: 6994
    7. Time: 9/8/2022 3:55:50 PM, startBuyingSlot: 2, buyBatchQty: 100, myBuyOrder: BuyLong2, BarsInProgress: 0, latestBuyBar: 6994
    Request, would anyone be able to please help me understand if I'm missing something in the code, or if its just not possible to submit orders via OnExecutionUpdate, or something else?

    Many thanks in advance

    ChainsawDR
    Attached Files

    #2
    Hello ChainsawDR,

    Thank you for your post.

    It is certainly possible to submit orders via OnExecutionUpdate() as demonstrated in the reference sample here:


    In your case, rather than submitting protective orders you are trying to add additional orders to your open position. As an additional debugging tool, you could enable Trace Orders to get additional information in the NinjaScript Output window regarding orders. This can be enabled by setting TraceOrders to true in State.SetDefaults. For more information:


    Additionally, I see in State.SetDefaults that you have EntriesPerDirection set to 1. This will limit your strategy from placing additional orders in the same direction, and could be the cause of the behavior you are experiencing. This may be adjusted for the default number of EntriesPerDirection in your code directly, or you may adjust it when enabling the strategy within the Strategy Properties window under the "Order Handling" section. For more information:


    After making these adjustments to further debug your script, please let me know if you are still experiencing unexpected behavior or have further questions.

    Comment


      #3
      *face palm* - doh so sorry for missing that EntriesPerDirection miss. I spent at least 2hrs trying to chase that down. Thanks for spotting that Emily!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      62 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      134 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X