Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged OCO orders

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

    Unmanaged OCO orders

    Hi,

    I'm trying to send to the market one OCO order for entry one tick above swinghigh or one tick below the swinglow.

    one should be a long stop order and the other one a sell stop order. As I don't know how to do it I have been looking for all examples I could find and this is the result:

    BloqueRap is number of contracts to buy
    DiferencialHigh and DiferencialLow are how many ticks from swinghigh and swinglow entry price must be.


    ocoString = string.Format("EntradaRap{0}",DateTime.Now.ToStrin g("hhmmssffff"));
    //entrada largo
    SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopMarket, BloqueRap, 0, (Swing1.SwingHigh[0] + DiferencialHigh * TickSize), ocoString, "LargoRap");
    //entrada corto
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, BloqueRap, 0, (Swing1.SwingLow[0] + (DiferencialLow * TickSize)), ocoString, "CortoRap");


    I'm not sure even if this oco orders will work.


    Next step is to change the price in the pending orders when the swinghigh or swinglow changes and I don't know how to do it as I'm not sure how to reference the orders. I tried with the entry name LargoRap but it doesn't work. It says: The name LargoRap doesn't exists on actual context (code CS0103)

    ChangeOrder(LargoRap, BloqueRap, 0, (Swing1.SwingHigh[0] + DiferencialHigh * TickSize));


    Thanks

    #2
    Hello aprendiz,

    Thank you for the post.

    It sounds like you have a few problems here, the first is that you need a reference to the orders and also that the variable you entered is not yet defined. Because you don't have the orders stored currently I would suggest to instead take a look at the following example: https://ninjatrader.com/support/foru...926#post486926
    This sample demonstrates doing an OCO bracket along with how to store/reference the order objects. I would likely suggest starting with that sample as it demonstrates the core components needed to do the bracket in unmanaged.

    To clarify the error, that means you have used LargoRap but did not define it. If this was meant to be the order you need to follow the linked example in how it stores the orders as variables and uses them.


    I look forward to being of further assistance.

    Comment


      #3
      Hi,

      I have been looking at the example and I managed to adapt it to what I wanted but I would like to know how I can change the price of one order.
      I tried changeorder, but I can't make it work.

      Can you show me an example please?

      And also what should I change to make it work not only on real-time as I would like to test the strategy historical performance?

      Thanks

      Comment


        #4
        Hello aprendiz,

        What order are you trying to change the price of?

        The unmanaged approach uses ChangeOrder to make modifications to orders. Depending on which order your referring to you would need to supply an order object/ details on the change. There is a quick sample here:



        If you can provide more details on what you tried/whats not working that would be helpful. With the provided details I could only say that you are using the correct method to modify an unmanaged order, you may need to review the situation again to pick out any other details about what you tried.


        The unmanaged sample I had linked to has its code run from OnMarketData, this means that it would work only in realtime. It would need to be modified to use OnBarUpdate instead or you can use TickReplay to simulate OnMarketData in historical however this was not programmed with that in mind to use that data. Please see the SampleMACrossOver and how it makes use of OnBarUpdate, also: https://ninjatrader.com/support/help...and_onexec.htm (this is not unmanaged but shares the same concepts of using orders/OnBarUpdate)



        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        53 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X