Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

2 entry orders help!

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

  • bobperez
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello bobperez,

    Yes, this would be necessary to have independent OCO pairing. Use two entry orders with unique signal names and two exit orders with the from entry signals of those entries.
    Hi Chelsea,

    I am getting the attached errors after a while Click image for larger version  Name:	F4.jpg Views:	19 Size:	107.7 KB ID:	1296087 .



    Is there anything missing?

    BobPerez
    Last edited by bobperez; 03-18-2024, 01:34 PM.

    Leave a comment:


  • bobperez
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello bobperez,

    Yes, this would be necessary to have independent OCO pairing. Use two entry orders with unique signal names and two exit orders with the from entry signals of those entries.
    Ok, thank you, Chelsea.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello bobperez,

    Yes, this would be necessary to have independent OCO pairing. Use two entry orders with unique signal names and two exit orders with the from entry signals of those entries.

    Leave a comment:


  • bobperez
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello bobperez,

    In the UnmanagedOCOBracketExample_NT8 note I've used OrderType.StopMarket orders.
    A buy stop order would be placed above the ask, a sell stop order would be placed below the bid.

    In this code you have chosen to use OrderType.Limit which are placed on the reverse side of the market.
    A buy limit would be placed below the ask, a sell limit would be placed above the bid.

    I see in your code you've submitted the buy limit at the High of the most recently closed bar and the sell limit at the Low of the most recently closed bar. These orders will most likely be on the wrong side of the market when the new bar opens.
    With some brokerages that order will be immediately filled (including NinjaTrader), with other brokerages that order would be rejected (such as Forex brokerages).

    Also, orders should be assigned to variables in OnOrderUpdate() and not directly from the order method.

    I've changed is and tested the suggested code and I am finding this is working.

    Below is a link to a video of the test.

    [ATTACH]n1295472[/ATTACH]

    There are no exit orders or setting the variables back to null so it only places orders once, but this works as expected.
    Hi Chelsea,

    If I want to enter the oco trades with 2 contracts instead of 1, and each contract with a different target, will I need to send one pair of orders for each contract separately?
    Last edited by bobperez; 03-15-2024, 10:37 AM.

    Leave a comment:


  • bobperez
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello bobperez,

    In the UnmanagedOCOBracketExample_NT8 note I've used OrderType.StopMarket orders.
    A buy stop order would be placed above the ask, a sell stop order would be placed below the bid.

    In this code you have chosen to use OrderType.Limit which are placed on the reverse side of the market.
    A buy limit would be placed below the ask, a sell limit would be placed above the bid.

    I see in your code you've submitted the buy limit at the High of the most recently closed bar and the sell limit at the Low of the most recently closed bar. These orders will most likely be on the wrong side of the market when the new bar opens.
    With some brokerages that order will be immediately filled (including NinjaTrader), with other brokerages that order would be rejected (such as Forex brokerages).

    Also, orders should be assigned to variables in OnOrderUpdate() and not directly from the order method.

    I've changed is and tested the suggested code and I am finding this is working.

    Below is a link to a video of the test.

    [ATTACH]n1295472[/ATTACH]

    There are no exit orders or setting the variables back to null so it only places orders once, but this works as expected.
    Hi Chelsa,

    Thank you so much for your continued support. I'll check the video and your suggestions and will let you know later my results.

    I've implemented your suggestions and they work perfectly. I've also changed the entry Limit orders for Stop Orders.

    Cheers!

    Bob Perez
    Last edited by bobperez; 03-13-2024, 11:41 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello bobperez,

    In the UnmanagedOCOBracketExample_NT8 note I've used OrderType.StopMarket orders.
    A buy stop order would be placed above the ask, a sell stop order would be placed below the bid.

    In this code you have chosen to use OrderType.Limit which are placed on the reverse side of the market.
    A buy limit would be placed below the ask, a sell limit would be placed above the bid.

    I see in your code you've submitted the buy limit at the High of the most recently closed bar and the sell limit at the Low of the most recently closed bar. These orders will most likely be on the wrong side of the market when the new bar opens.
    With some brokerages that order will be immediately filled (including NinjaTrader), with other brokerages that order would be rejected (such as Forex brokerages).

    Also, orders should be assigned to variables in OnOrderUpdate() and not directly from the order method.

    I've changed is and tested the suggested code and I am finding this is working.

    Below is a link to a video of the test.

    BobperezTest_NT8.zip

    There are no exit orders or setting the variables back to null so it only places orders once, but this works as expected.

    Leave a comment:


  • bobperez
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello bobperez,

    If you want to wait until after the bar closes to submit the order using the high and low values of the previous fully closed bar while Calculate is OnPriceChange and TickReplay is enabled, do this when IsFirstTickOfBar is true and use 1 bar ago indexes.

    Code:
    if (IsFirstTickOfBar)
    {
    int barsAgoIndex = Calculate != Calculate.OnBarClose && (State == State.Realtime || (State == State.Historical && BarsArray[0].IsTickReplay)) ? 1 : 0;
    Print(string.Format("{0} | barsAgoIndex selected: {1}, {2}, High[{1}]: {3}, Low[{1}]: {4}", Time[0], barsAgoIndex, Time[barsAgoIndex], High[barsAgoIndex], Low[barsAgoIndex]));
    }
    Hi Chelsea,

    Here's what I interpreted from your suggestion. With this code, the chart freezes, and I have to force Ninjja to shut down with Ctr+Alt+Del.




    Code:
                if ( (longStopEntry == null && shortStopEntry == null && IsFirstTickOfBar )        
                    && ((ToTime(Time[0]) == 82900   )
                    ||    (ToTime(Time[0]) == 113000  )
                    ||  (ToTime(Time[0]) == 113800  )
                    ||    (ToTime(Time[0])  == 142000 )
                    )
                    )                
                    
                {
                    int barsAgoIndex = Calculate != Calculate.OnBarClose && (State == State.Realtime || (State == State.Historical && BarsArray[0].IsTickReplay)) ? 1 : 0;
                    Print(string.Format("{0} | barsAgoIndex selected: {1}, {2}, High[{1}]: {3}, Low[{1}]: {4}", Time[0], barsAgoIndex, Time[barsAgoIndex], High[barsAgoIndex], Low[barsAgoIndex]));
                    ocoString        = string.Format("unmanagedentryoco{0}", DateTime.Now.ToString("hhmmssffff"));
                    longStopEntry    = SubmitOrderUnmanaged(1, OrderAction.Buy, OrderType.Limit, 1, 0, (High[barsAgoIndex] + 4 * TickSize), ocoString, "longStopEntry");
                    shortStopEntry    = SubmitOrderUnmanaged(1, OrderAction.SellShort, OrderType.Limit, 1, 0, (Low[barsAgoIndex] - 4 * TickSize), ocoString, "shortStopEntry");
                    
                }
                    
    ​
    BobPerez
    Last edited by bobperez; 03-12-2024, 02:15 PM.

    Leave a comment:


  • bobperez
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello bobperez,

    If you want to wait until after the bar closes to submit the order using the high and low values of the previous fully closed bar while Calculate is OnPriceChange and TickReplay is enabled, do this when IsFirstTickOfBar is true and use 1 bar ago indexes.

    Code:
    if (IsFirstTickOfBar)
    {
    int barsAgoIndex = Calculate != Calculate.OnBarClose && (State == State.Realtime || (State == State.Historical && BarsArray[0].IsTickReplay)) ? 1 : 0;
    Print(string.Format("{0} | barsAgoIndex selected: {1}, {2}, High[{1}]: {3}, Low[{1}]: {4}", Time[0], barsAgoIndex, Time[barsAgoIndex], High[barsAgoIndex], Low[barsAgoIndex]));
    }
    Hi Chelsea,

    Great! Thank you!

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello bobperez,

    If you want to wait until after the bar closes to submit the order using the high and low values of the previous fully closed bar while Calculate is OnPriceChange and TickReplay is enabled, do this when IsFirstTickOfBar is true and use 1 bar ago indexes.

    Code:
    if (IsFirstTickOfBar)
    {
    int barsAgoIndex = Calculate != Calculate.OnBarClose && (State == State.Realtime || (State == State.Historical && BarsArray[0].IsTickReplay)) ? 1 : 0;
    Print(string.Format("{0} | barsAgoIndex selected: {1}, {2}, High[{1}]: {3}, Low[{1}]: {4}", Time[0], barsAgoIndex, Time[barsAgoIndex], High[barsAgoIndex], Low[barsAgoIndex]));
    }

    Leave a comment:


  • bobperez
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello bobperez,

    The orders are being submitted while the bar is still open, are you wanting to wait until after the bar has closed to submit the orders?

    In this output what is the behavior you are seeing that is incorrect?
    Hi Chelsea,

    I expect a behavior similar to your plain example. The orders should be placed about 2-3 ticks above/below the bars, instead of 15 ticks as you have in your example. They should be submitted when the timed bar closes to identify its final High/Low.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello bobperez,

    The orders are being submitted while the bar is still open, are you wanting to wait until after the bar has closed to submit the orders?

    In this output what is the behavior you are seeing that is incorrect?

    Leave a comment:


  • bobperez
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello bobperez,

    I'm seeing that the first two orders were submitted at 8:29. These were limit orders, and not market orders, so may not fill immediately and may fill at a later time when the limit price is reached.

    2024-03-01 8:29:00 AM order.ToString()orderId='NT-00000-1378' account='Sim101' name='longStopEntry' orderState=Submitted instrument='CL 04-24' orderAction=Buy orderType='Limit' limitPrice=0 stopPrice=79.79 quantity=1 tif=Gtc oco='unmanagedentryoco0639187450' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-03-01 08:28:59' gtd='2099-12-01' statementDate='2024-03-11'

    2024-03-01 8:29:00 AM order.ToString()orderId='NT-00001-1378' account='Sim101' name='shortStopEntry' orderState=Submitted instrument='CL 04-24' orderAction=SellShort orderType='Limit' limitPrice=0 stopPrice=79.72 quantity=1 tif=Gtc oco='unmanagedentryoco0639187450' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-03-01 08:28:59' gtd='2099-12-01' statementDate='2024-03-11'​

    Is the issue that the orders are being submitted at the correct time but are not filling until a later bar due to being limit orders and not market orders?


    I should have had you put the print in a separate condition for the time, so we can see this print for each bar update at that time, and see if there are more bar updates after the order is submitted.

    Code:
    if ((ToTime(Time[0]) == 82900 )
    || (ToTime(Time[0]) == 113000 )
    || (ToTime(Time[0]) == 113800 )
    || (ToTime(Time[0]) == 142000 )
    )
    )
    
    {
    Print(Time[0]+ " bar update" );
    }​
    
    if ( (longStopEntry == null && shortStopEntry == null )
    && ((ToTime(Time[0]) == 82900 )
    || (ToTime(Time[0]) == 113000 )
    || (ToTime(Time[0]) == 113800 )
    || (ToTime(Time[0]) == 142000 )
    )
    )
    
    {
    ocoString = string.Format("unmanagedentryoco{0}", DateTime.Now.ToString("hhmmssffff"));
    longStopEntry = SubmitOrderUnmanaged(1, OrderAction.Buy, OrderType.Limit, 1, 0, (High[0] + 2 * TickSize), ocoString, "longStopEntry");
    shortStopEntry = SubmitOrderUnmanaged(1, OrderAction.SellShort, OrderType.Limit, 1, 0, (Low[0] - 2 * TickSize), ocoString, "shortStopEntry");
    
    Print(Time[0]+ " From OnBarUpdate after order submission" );
    }
    Hello Chelsea,

    I expect to place only one oco order per each time bar, at the High[0]+2 ticks and Low[0]-2 ticks. There should only be a total of 4 orders, one for each bar. So, on bar 8:29, the oco order should be placed immediately after the bar closes, when its final high and low are known.
    Attached Files

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello bobperez,

    I'm seeing that the first two orders were submitted at 8:29. These were limit orders, and not market orders, so may not fill immediately and may fill at a later time when the limit price is reached.

    2024-03-01 8:29:00 AM order.ToString()orderId='NT-00000-1378' account='Sim101' name='longStopEntry' orderState=Submitted instrument='CL 04-24' orderAction=Buy orderType='Limit' limitPrice=0 stopPrice=79.79 quantity=1 tif=Gtc oco='unmanagedentryoco0639187450' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-03-01 08:28:59' gtd='2099-12-01' statementDate='2024-03-11'

    2024-03-01 8:29:00 AM order.ToString()orderId='NT-00001-1378' account='Sim101' name='shortStopEntry' orderState=Submitted instrument='CL 04-24' orderAction=SellShort orderType='Limit' limitPrice=0 stopPrice=79.72 quantity=1 tif=Gtc oco='unmanagedentryoco0639187450' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-03-01 08:28:59' gtd='2099-12-01' statementDate='2024-03-11'​

    Is the issue that the orders are being submitted at the correct time but are not filling until a later bar due to being limit orders and not market orders?


    I should have had you put the print in a separate condition for the time, so we can see this print for each bar update at that time, and see if there are more bar updates after the order is submitted.

    Code:
    if  ((ToTime(Time[0]) == 82900 )
    || (ToTime(Time[0]) == 113000 )
    || (ToTime(Time[0]) == 113800 )
    || (ToTime(Time[0]) == 142000 )
    )
    )
    
    {
    Print(Time[0]+ " bar update" );
    }​
    
    if ( (longStopEntry == null && shortStopEntry == null )
    && ((ToTime(Time[0]) == 82900 )
    || (ToTime(Time[0]) == 113000 )
    || (ToTime(Time[0]) == 113800 )
    || (ToTime(Time[0]) == 142000 )
    )
    )
    
    {
    ocoString = string.Format("unmanagedentryoco{0}", DateTime.Now.ToString("hhmmssffff"));
    longStopEntry = SubmitOrderUnmanaged(1, OrderAction.Buy, OrderType.Limit, 1, 0, (High[0] + 2 * TickSize), ocoString, "longStopEntry");
    shortStopEntry = SubmitOrderUnmanaged(1, OrderAction.SellShort, OrderType.Limit, 1, 0, (Low[0] - 2 * TickSize), ocoString, "shortStopEntry");
    
    Print(Time[0]+ " From OnBarUpdate after order submission" );
    }

    Leave a comment:


  • bobperez
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello bobperez,

    Can you print the bar time from inside of the entry condition in OnBarUpdate() and print the order.ToString() object in OnOrderUpdate(), then post the output text file?

    I just want to confirm we are seeing multiple updates for the bar on each price change in OnBarUpdate() and that the order is being submitted immediately.
    Chelsea,

    Code:
            protected override void OnBarUpdate()
            {
                
                if ( (longStopEntry == null && shortStopEntry == null )        
                    && ((ToTime(Time[0]) == 82900 )
                    ||    (ToTime(Time[0]) == 113000 )
                    || (ToTime(Time[0]) == 113800 )
                    ||    (ToTime(Time[0])  == 142000 )
                    )
                    )                
                    
                {
                    ocoString        = string.Format("unmanagedentryoco{0}", DateTime.Now.ToString("hhmmssffff"));
                    longStopEntry    = SubmitOrderUnmanaged(1, OrderAction.Buy, OrderType.Limit, 1, 0, (High[0] + 2 * TickSize), ocoString, "longStopEntry");
                    shortStopEntry    = SubmitOrderUnmanaged(1, OrderAction.SellShort, OrderType.Limit, 1, 0, (Low[0] - 2 * TickSize), ocoString, "shortStopEntry");
                    
                    Print(Time[0]+ " From OnBarUpdate after order submission" );
                }
                    
            
            }
    Attached Files

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello bobperez,

    Can you print the bar time from inside of the entry condition in OnBarUpdate() and print the order.ToString() object in OnOrderUpdate(), then post the output text file?

    I just want to confirm we are seeing multiple updates for the bar on each price change in OnBarUpdate() and that the order is being submitted immediately.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by CarlTrading, 05-11-2026, 05:56 AM
0 responses
56 views
0 likes
Last Post CarlTrading  
Started by CarlTrading, 05-10-2026, 08:12 PM
0 responses
33 views
0 likes
Last Post CarlTrading  
Started by Hwop38, 05-04-2026, 07:02 PM
0 responses
195 views
0 likes
Last Post Hwop38
by Hwop38
 
Started by CaptainJack, 04-24-2026, 11:07 PM
0 responses
359 views
0 likes
Last Post CaptainJack  
Started by Mindset, 04-21-2026, 06:46 AM
0 responses
280 views
0 likes
Last Post Mindset
by Mindset
 
Working...
X