Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 05-31-2018, 05:06 PM   #1
studio3d
Junior Member
 
Join Date: May 2018
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
Default SubmitOrderUnmanaged Orders Ignored in Real-time Paper Trading

I have a strategy that works perfectly in historical simulation. Orders execute properly, but when I run the identical code in paper trading, no orders are ever placed. Strategies NOT using unmanaged orders work properly in paper trading. When using unmanaged orders, I set IsUnmanaged = true; in the State.SetDefaults as the documentation specifies.

To debug the issue, I enabled TraceOrders = true; in the State.SetDefaults section, but no error messages show in the NJ global log or NinjaScript Output windows. I know the code is running because I can see my Print() statements indicating entry attempts at price X, etc. However no orders are ever submitted.

You'll see my code here that enters at an offset of the last closing price from data set [1].
Code:
orderEntryLimit = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, 1, Closes[1][0]-EnterLimitOffset*0.25, 0, "", "EntryLimitOrder");
If someone could explain to me why none of my orders execute in paper trading if I code them as unmanged, that would be great. I am using a NinjaTrader demo account.
studio3d is offline  
Reply With Quote
Old 06-01-2018, 08:49 AM   #2
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 1,677
Thanks: 91
Thanked 447 times in 424 posts
Default

Welcome to the forums studio3d!

Without the full context of the code, I am only left to speculate at what the issue may be. Taking a guess, the strategy may be restricting order submissions based on the BarsRequiredToTrade property or the strategy may be using WaitUntilFlat and is in a virtual position that needs to be closed before new orders are allowed to be submitted. There may also be an issue with the strategy's behavior for realtime processing. The Playback Connection can be used while testing and debugging to focus on realtime processing.

Start behaviors can be referenced here - https://ninjatrader.com/support/help..._positions.htm

Playback connection - https://ninjatrader.com/support/help...connection.htm

I have tested on my end just now and I have not had an issue using an UnmanagedTemplate strategy and a NinjaTrader Continuum demo account. I have attached this strategy so you may perform the same test on your end. You may also use this template for any debugging and personal development.

Demo: https://www.screencast.com/t/7XeYxdPAlWex

Please let me know if there is anything else we can do to assist.
Attached Files
File Type: zip UnmanagedTemplate_NT8 09-17.zip (3.0 KB, 7 views)
NinjaTrader_Jim is offline  
Reply With Quote
The following 2 users say thank you to NinjaTrader_Jim for this post:
Old 06-03-2018, 01:14 PM   #3
franki
Junior Member
 
Join Date: Jan 2016
Posts: 21
Thanks: 11
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_Jim View Post
I have tested on my end just now and I have not had an issue using an UnmanagedTemplate strategy and a NinjaTrader Continuum demo account.
Hello NinjaTrader_Jim

I have used your script as a template to develop a complete strategy, sincerely it has been of great and great help. But I have found a bug, in the quantity part of SubmitOrderUnmanaged I have changed quantity by a variable to assign from the interface of the script the amount of contracts desired.
In very high volatility events, when the number of contracts is higher than 1, stop and profit orders are not logically managed, being able to have more stop orders than profit and on the contrary, even being in the market when it should be flat .
I have not modified the structure of the script, I have added external modifications that should not affect the operation of the script.
I remind you that this happens only in events of very high volatility, in simulation it works well.
for now the solution I do is not very orthodox and I loading the script with the same number of contracts I want.
Do you have any ideas about it?
I have reviewed the documentation of the order filling and the partial filling of orders without finding a solution.
I also thank you for the contribution of the script UnmanagedTemplate_NT8 09-17
Thanks
franki is offline  
Reply With Quote
Old 06-04-2018, 07:36 AM   #4
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 1,677
Thanks: 91
Thanked 447 times in 424 posts
Default

Hello franki,

I'm glad you have made use of the template.

The purpose of the strategy is to provide a working example and point out how an Unmanaged strategy can be written. It doesn't necessarily provide a working example for all concepts and things you might run into when deployed live. The partial fill handling could be improved for example, but at this time the script was not written to encounter partial fills and merely points you in the right direction for handling them. I'll see about improving the example script later down the line to better demonstrate partial fill handling.

Thanks for pointing out an area where it can be improved.
NinjaTrader_Jim is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jim for this post:
Old 06-13-2018, 08:16 AM   #5
ours_solaire
Member
 
Join Date: Mar 2014
Posts: 60
Thanks: 18
Thanked 4 times in 3 posts
Default

I would like to add my thanks to Jim for providing his Unmanaged example strategy - very useful for anyone trying to make a start with this approach!

I have a question, however. Just looking through the code, in OnOrderUpdate(), near the end where the stops and target orders are set to null, you comment :
Quote:
//PLEASE NOTE: setting IOrders to null ***DOES NOT*** cancel them
, but give no further advise. Then at the end of the script there is a method called CancelAll() which cancels all orders, but this method is not called anywhere in the strategy, unless I totally missed something. Where would be the most appropriate place to put the CancelAll method in your script?

If I want a strategy that placed new simultaneous LongStopLimit and ShortStopLimit orders on the first tick of every 15min bar to be concelled if unfilled on the close of the bar, then I guess the best place to cancel the them would be in OnBarUpdate() { OnFirstTickOfBar{ CancelAll() -> check for null, then SumbitOrderUnmanaged().

Any thoughts or suggestions welcome!
ours_solaire is offline  
Reply With Quote
Old 06-13-2018, 09:40 AM   #6
NinjaTrader_Jim
NinjaTrader Customer Service
 
NinjaTrader_Jim's Avatar
 
Join Date: Nov 2016
Location: Denver, CO
Posts: 1,677
Thanks: 91
Thanked 447 times in 424 posts
Default

Hello ours_solaire,

CancelAll() just shows a method that can be called to cancel all of the orders used in the strategy by checking if that order is null, and then calling CancelOrder(). Order objects should be set to null after cancellation or after a fill in OnOrderUpdate() so the order can be submitted again. This method is not called in this example and there is not a place where it should be called in the context of this example; the script is only meant to show how a basic unmanaged strategy can be written.

If you are submitting new limit orders on every bar you could could call CancelOrder() for that order and resubmit, or you can call ChangeOrder() to update that order as needed.

As a rough example:
Code:
if (longEntry == null && shortEntry == null
    && Position.MarketPosition == MarketPosition.Flat)
{
    // Entry
}
else if (longEntry != null && shortEntry != null
    && Position.MarketPosition == MarketPosition.Flat)
{
	ChangeOrder(shortEntry, shortEntry.Quantity+1, Close[0]+EntryDistance*TickSize, 0);
	ChangeOrder(longEntry, longEntry.Quantity+1, Close[0]-EntryDistance*TickSize, 0);
}
Referencing the documentation for the methods and properties used in this strategy can help give further direction. I'll include links for ChangeOrder() and CancelOrder() below.

CancelOrder() - https://ninjatrader.com/support/help...ancelorder.htm

ChangeOrder() - https://ninjatrader.com/support/help...hangeorder.htm

Please let me know if you have any questions.
NinjaTrader_Jim is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jim for this post:
Old 06-13-2018, 01:01 PM   #7
ours_solaire
Member
 
Join Date: Mar 2014
Posts: 60
Thanks: 18
Thanked 4 times in 3 posts
Default

Hello Jim,

Thanks for the prompt and detailed reply. I appreciate you taking the time to explain. I will definitely try your idea of using ChangeOrder() instead of cancelling and re-submitting the orders on each bar close - that option has the potential for more real-time problems than ChangeOrder() I'm guessing...
ours_solaire is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
while in real-time auto trading also trading in Sim account while ... GTBrooks Strategy Development 3 09-11-2017 09:33 AM
From paper- to real-trading fliesen Platform Technical Support 9 05-17-2016 09:47 AM
Real trading: Market orders Vs Limit orders pstrusi Platform Technical Support 7 12-29-2015 11:04 AM
ExitLongStopLimit in real-time trading? bluelou Platform Technical Support 10 08-01-2014 08:27 AM
Using NT’s Live trading license with IB’s paper-trading account JoeStein Platform Technical Support 2 03-24-2009 10:18 AM


All times are GMT -6. The time now is 07:16 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.