Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by warreng86, 11-10-2020, 02:04 PM
        7 responses
        1,360 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Perr0Grande, Today, 08:16 PM
        0 responses
        5 views
        0 likes
        Last Post Perr0Grande  
        Started by elderan, Today, 08:03 PM
        0 responses
        9 views
        0 likes
        Last Post elderan
        by elderan
         
        Started by algospoke, Today, 06:40 PM
        0 responses
        10 views
        0 likes
        Last Post algospoke  
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        14 views
        0 likes
        Last Post maybeimnotrader  
        Working...
        X