Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

2 entry orders help!

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

  • tgn55
    replied
    Hi, I've been looking at coding OCO brackets... found this thread - great, but I have a question for Chelsea...

    The sample OCO code you provided states explicitly it is designed to work ONLY on live data... not historical. But you say above it can be back-tested (ie, on historical data).
    Can you please clarify?

    And yes, my intended purpose is to have both pending long and short MIT orders active.

    Thanks,
    T.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello davizz,

    Welcome to the NinjaTrader forums!

    Yes, strategies with unmanaged orders that use oco can be backtested.

    Leave a comment:


  • davizz
    replied
    Hello ChelseaB, with Unmanaged OCO orders type can I backtest my strategy? Thanks

    Leave a comment:


  • DayTrader12
    replied
    Thanks Chelsea, I will give it a shot.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello DayTrader12,

    This example was created to demonstrate that OCO works as documented in the help guide.

    Below I am providing public links to the help guide on creating inputs.



    I would recommend using the SampleMACrossOver included with NinjaTrader for an example of how to add inputs to your script.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.

    Leave a comment:


  • DayTrader12
    replied
    Hi Chelsea,

    I downloaded your code for the OCO entries.
    Thank you for posting it.
    Any chance you could upgrade the original code to make the entries and exits inputs?
    Thanks for the help.

    DT_12


    Originally posted by NinjaTrader_ChelseaB View Post
    Hello Andrea,

    To clarify your original question, you are wanting to have opposing orders working at the same time, is this correct?

    I have an example that you may find helpful that uses the unmanaged approach to submit a pair of opposing orders using oco (One Cancels Other) I've made for NinjaTrader 7.

    I've ported this to NT8 for you and I'm attaching both versions so you can compare.


    (Updated July 17th, 2018 - corrected assigning the variables to null when the exit on close occurs. Also corrected preventing orders after the exit on close until the new session)

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello JMont1,

    The Strategy Builder uses the Managed approach.

    The Managed approach does not allow for OCO.

    Leave a comment:


  • JMont1
    replied
    Strategy Builder OCO implant

    @NinjaTrader_ChelseaB, Great example for the OCO's needed for NT8....=>
    Any chance you can devise a method to implement that for Strategy Builder?

    I.e... Person builds their strategy logic and then has a method through an indicator or method to place the order(s) with OCO? This would allow for continuing to build the logic further while in Strategy Builder.

    I already assume the main answer is no, but it projects the essence of the request. Would there be some method to then use the unlock the code (in a copy) and insert a standard code set regions for the OCOs?

    This way the Strategy Builder could go on building out further logic, save to a temporary version, unlock that versions code and insert the regions for the OCO. And of course then redo for future logic additions to the original file.

    This may be best if there was a method in Strategy Builder to sort of make an easy place holder for where the OCO region(s) would paste in. Perhaps he a single order entry in the Strategy Builder where the OCO regions are just placed.

    This would expand the benefits of Strategy Builder OCO greatly.

    ANY OTHER CODERS SUGGESTIONS ARE EAGERLY APPRECIATED.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello YoutingChu,

    This post appears to be a duplicate of https://ninjatrader.com/support/foru...426#post547426.

    I will respond in the other thread.

    Leave a comment:


  • YoutingChu
    replied
    Dear Chelsea,

    Thank you very much for your great sample codes!

    But when I tried to run your code, the whole thing stopped at Exit on session close! All the bars after that have absolutely no trades!!!

    Could you teach me how to fix that, please!? Appreciated!
    Last edited by YoutingChu; 07-16-2018, 08:23 PM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello fx.practic,

    The UnmanagedOCOBracketExample_NT7 does not assign the longProfitTarget/longStopLoss/shortProfitTarget/shortStopLoss to IOrder objects, because there isn't any need to. I'm not needing to reference these orders at a later time. You could if you wanted to. But the script doesn't need to assign these to IOrder objects to function.

    If trade was closed from an order that is not one of these orders, no, the script would not cancel these. (But the script is coded to only allow these orders to close the position, cancel the opposing order with OCO, or with the ExitOnClose which would cancel all working orders anyway)

    With NinjaTrader 7 assigning orders to IOrder objects should be done in OnOrderUpdate, because OnOrderUpdate can run for the order before the order submission method returns the IOrder object.

    From the help guide:
    "If you are relying on the OnOrderUpdate() method to trigger actions such as the submission of a stop loss order when your entry order is filled ALWAYS reference the properties on the IOrder object passed into the OnOrderUpdate() method."

    Below is a public link.
    https://ninjatrader.com/support/help...rderupdate.htm

    However, in practice I've never run into this issue personally with NinjaTrader 7.
    (So I'm being lazy with the code. It would be better practice to assign the IOrder from OnOrderUpdate())

    (corrected)
    This is definitely an issue with NinjaTrader 8. With NinjaTrader 8, the order object returned isn't updated when OnBarUpdate() runs and will definitely cause issues if the Order object is assigned from OnBarUpdate().
    Last edited by NinjaTrader_ChelseaB; 12-26-2021, 03:35 PM.

    Leave a comment:


  • fx.practic
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello Andrea,

    To clarify your original question, you are wanting to have opposing orders working at the same time, is this correct?

    I have an example that you may find helpful that uses the unmanaged approach to submit a pair of opposing orders using oco (One Cancels Other) I've made for NinjaTrader 7.


    I've ported this to NT8 for you and I'm attaching both versions so you can compare.

    Great example, thanks!

    I looked carefully and have a questions:

    1. "No IOrder variable is used as a handle to track the stop loss and profit target".
    What if position will be closed not by stop loss or profit target - say, position reversed by some opposite order.

    In that case do stop loss or profit target orders will keeping alive and fully "unmanaged"?

    2. In Managed approach IOrder object should be assigned in OnOrderUpdate() method only, after Order object created.

    Otherwise, in Your example
    PHP Code:
    OnBarUpdate()
    {
    longStopEntry = SubmitOrderUnmanaged();
    } 
    
    Why? Isn't it unsafe?
    Last edited by fx.practic; 05-22-2018, 11:36 AM.

    Leave a comment:


  • endystrike
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello Andrea,

    To clarify your original question, you are wanting to have opposing orders working at the same time, is this correct?

    I have an example that you may find helpful that uses the unmanaged approach to submit a pair of opposing orders using oco (One Cancels Other) I've made for NinjaTrader 7.


    I've ported this to NT8 for you and I'm attaching both versions so you can compare.
    Thanks a lot, I'll have a look as soon!

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello Andrea,

    To clarify your original question, you are wanting to have opposing orders working at the same time, is this correct?

    I have an example that you may find helpful that uses the unmanaged approach to submit a pair of opposing orders using oco (One Cancels Other) I've made for NinjaTrader 7.

    I've ported this to NT8 for you and I'm attaching both versions so you can compare.

    Below are links to the help guide on using the unmanaged approach.
    https://ninjatrader.com/support/help...d_approach.htm
    https://ninjatrader.com/support/help...runmanaged.htm

    These examples are designed to place orders in real-time so that you can see the orders appear and try and cancel one to see the behavior.
    Unmanaged orders can also be submitted in historical data and be backtested by removing the check for real-time.

    (Updated July 17th, 2018 - corrected assigning the variables to null when the exit on close occurs. Also corrected preventing orders after the exit on close until the new session)

    UnmanagedOCOBracketExample_NT8.zip
    UnmanagedOCOBracketExample_NT7.zip
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 01-04-2023, 08:36 AM.

    Leave a comment:


  • endystrike
    replied
    Originally posted by NinjaTrader_RyanL View Post
    Hello endystrike,


    You can search our extensive library of NinjaScript consultants through the link below to assist with any conversions of NinjaScript orders to the unmanaged approach.

    Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more!





    This NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.



    Please let me know if you have any questions, concerns or if I can provide any further assistance by responding to this thread at your convenience.
    Hello,
    thanks for your reply!
    Isn't it available a tutorial to use "Unmanaged Approach" or a sample file for NinjaTrader 8?

    Thanks a lot

    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