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 06-21-2018, 09:58 PM   #1
guidalpi
Junior Member
 
Join Date: Sep 2017
Posts: 6
Thanks: 1
Thanked 0 times in 0 posts
Default Delayed market order execution

Hello,

Im testing my own developed strategy and during the historical processing the orders are not being processed as I expected.

For example, by analysing my strategy logs, the order was submitted on the bar closed at 14/06/2018 11:05:55, and reached the "working state" almost instantly. But it is filled only on the bar closed at 21/06/2018 22:16:58 (see below).

Is this the normal behaviour? Or am I missing something?

Ive tested the same strategy on playback connection (historical and market replay data) and in the strategy analyser and the results are OK (as expected).

Regards.

T14/06/2018 11:05:55;O2786,75;H2792,75;L2786,25;C2792,75;V1694 07
orderId='NT-00000-32' account='Sim101' name='MultiHamaBuy' orderState=Submitted instrument='ES 09-18' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-06-22 00:12:01' gtd='2099-12-01' statementDate='2018-06-22'

orderId='NT-00000-32' account='Sim101' name='MultiHamaBuy' orderState=Accepted instrument='ES 09-18' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-06-22 00:12:01' gtd='2099-12-01' statementDate='2018-06-22'

orderId='NT-00000-32' account='Sim101' name='MultiHamaBuy' orderState=Working instrument='ES 09-18' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-06-22 00:12:01' gtd='2099-12-01' statementDate='2018-06-22'

T21/06/2018 22:16:58;O2750,5;H2756,5;L2750,5;C2756,5;V9800
orderId='NT-00000-32' account='Sim101' name='MultiHamaBuy' orderState=Filled instrument='ES 09-18' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=10 averageFillPrice=2758.5 onBehalfOf='' id=-1 time='2018-06-22 00:12:01' gtd='2099-12-01' statementDate='2018-06-22'
guidalpi is offline  
Reply With Quote
Old 06-22-2018, 08:16 AM   #2
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,857
Thanks: 30
Thanked 1,243 times in 1,162 posts
Default

Hello guidalpi,

Welcome to the NinjaTrader support forums.

I wanted to further clarify what you are seeing here.

From what I can tell, all of your log statements here are on the same date/time: time='2018-06-22 00:12:01' so it seems the submission and progression of the order seem standard.

Where do you currently have your Print statements that you are comparing in your script? Also what bars type is currently being used for the strategy?

I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 06-22-2018, 11:16 AM   #3
guidalpi
Junior Member
 
Join Date: Sep 2017
Posts: 6
Thanks: 1
Thanked 0 times in 0 posts
Default

Hello,

The logs are generated from two different points on my code:

protected override void OnBarUpdate()
{

(...)

Print(string.Format("T{0};O{1};H{2};L{3};C{4};V{5} ", Time[0], Open[0], High[0], Low[0], Close[0], Volume[0]));

(...)

}

protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
Print(order.ToString());
}

OnBarUpdate() is responsible for the strategy logic and on each bar close it also prints to a logfile the Time, Open, High, Low, Close and Volume of that bar.

Ive added OnOrderUpdate just to print to the same logfile the order lifecycle.

The time youve mentioned "2018-06-22 00:12:01" was the clock time on my computer when the strategy was doing the historical processing, just before going real time.

So, from what Ive read on the help guide, the historical processing of orders should respect the bar ordering, and between the two bars in my example (06/14/2018 11:05:55 - 06/21/2018 22:16:58), there are more than 100 other closed bars (I forgot to mention this on the first post).

The bar type is a custom renko bar (ninZaRenko), but the orders are submitted to a 1 Tick secondary data series.

As my english is not so good, Ive uploaded a chart image that tries to show you whats going on.

Regards,

Guilherme.
Attached Images
File Type: png order.png (68.2 KB, 5 views)
guidalpi is offline  
Reply With Quote
Old 06-25-2018, 08:05 AM   #4
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,857
Thanks: 30
Thanked 1,243 times in 1,162 posts
Default

Hello guidalpi,

Thank you for the reply.

I wanted to check, do you also see this when using the standard Renko bars type?

If so, It would be helpful if I could test the script in the same situation and see the same result to better understand what happened here. Based on only the print information, I couldn't really say what may be happening in more detail. Can you tell me, is this something that could be formed into a small sample and uploaded to the forum for review? If not, we could work together through email if you needed to send the overall script.

I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 06-25-2018, 08:50 PM   #5
guidalpi
Junior Member
 
Join Date: Sep 2017
Posts: 6
Thanks: 1
Thanked 0 times in 0 posts
Default

Hello Jesse,

Thanks for your reply.

It also happens when using renko bars type.

Ive made a short version of my strategy (replacing a paid indicator Im using on it), and it keeps showing that strange behaviour.

The strategy is being attached on an ES 09-18 chart, using 24 Renko bars type and it is loaded with the last 200 bars.

Hope it helps you finding what Im doing wrong!

Regards,

Guilherme.
Attached Files
File Type: cs Ninza3HamaDebug.cs (14.8 KB, 5 views)
guidalpi is offline  
Reply With Quote
Old 06-29-2018, 08:13 AM   #6
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,857
Thanks: 30
Thanked 1,243 times in 1,162 posts
Default

Hello guidalpi,

Thank you for providing the file.

I reviewed what you have but I was unable to see the same type of occurrence you had with your test.

As it is now the sample is fairly difficult to follow because there are quite a few logical paths it can follow and other extra code being run. The prints you provided in your original inquiry also don't seem to exactly match any of the prints in this sample so I am unsure if I am looking at the specific portion of the script that I need to.

I would likely suggest at this point to further reduce this sample to a single entry that can demonstrate what you are seeing in a more simple way. Removing the other logic and debugging you have added will make the specific syntax required to see what you are more clear.

I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 06-30-2018, 05:15 PM   #7
guidalpi
Junior Member
 
Join Date: Sep 2017
Posts: 6
Thanks: 1
Thanked 0 times in 0 posts
Default

Hello,

Ive made a new test code, as simple as possible.

On my execution (24 renko, 200 bars, ES 09-18) I got the following:

T27/06/2018 12:26:43;O2738,5;H2738,5;L2732,5;C2732,5;V302009
Vendendo
orderId='NT-00000-3064' account='Sim101' name='Ninza3HamaSell' orderState=Submitted instrument='ES 09-18' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-06-29 17:58:59' gtd='2099-12-01' statementDate='2018-06-30'

orderId='NT-00000-3064' account='Sim101' name='Ninza3HamaSell' orderState=Accepted instrument='ES 09-18' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-06-29 17:58:59' gtd='2099-12-01' statementDate='2018-06-30'

orderId='NT-00000-3064' account='Sim101' name='Ninza3HamaSell' orderState=Working instrument='ES 09-18' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-06-29 17:58:59' gtd='2099-12-01' statementDate='2018-06-30'

(...)

T29/06/2018 16:24:21;O2738;H2738;L2732;C2732;V429926

T29/06/2018 16:50:00;O2732;H2732;L2726;C2726;V114154

orderId='NT-00000-3064' account='Sim101' name='Ninza3HamaSell' orderState=Filled instrument='ES 09-18' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=10 averageFillPrice=2721.5 onBehalfOf='' id=-1 time='2018-06-29 17:58:59' gtd='2099-12-01' statementDate='2018-06-30'


As you can see above, at least for me, the order is not getting the correct historical bar time.

Im sending my code and the complete log file for the execution mentioned above.

Regards,

Guilherme.
Attached Files
File Type: txt Ninza3HamaDebug-ES 09-18-{20180630185637}.txt (13.5 KB, 0 views)
File Type: cs Ninza3HamaDebug.cs (8.2 KB, 2 views)
guidalpi is offline  
Reply With Quote
Old 07-09-2018, 08:03 PM   #8
guidalpi
Junior Member
 
Join Date: Sep 2017
Posts: 6
Thanks: 1
Thanked 0 times in 0 posts
Default

Hello,

Any hint on what can be happening with these orders, or how can I further debug the orders.

Regards.
guidalpi is offline  
Reply With Quote
Old 07-10-2018, 02:35 PM   #9
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,857
Thanks: 30
Thanked 1,243 times in 1,162 posts
Default

Hello,

Thank you for the reply.

I reviewed the file further but I have been unable to see this print happen on my end. From my testing I am getting prints similar to the following reported back:


Quote:
T5/11/2018 1:08:44 AM;O2722.75;H2722.75;L2722.25;C2722.25;V727
Vendendo
5/11/2018 1:08:44 AM Strategy 'Ninza3HamaDebug/142708669': Entered internal SubmitOrderManaged() method at 5/11/2018 1:08:44 AM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=10 LimitPrice=0 StopPrice=0 SignalName='Ninza3HamaSell' FromEntrySignal=''
orderId='NT-00000-136' account='Sim101' name='Ninza3HamaSell' orderState=Submitted instrument='ES 09-18' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-11 01:08:44' gtd='2099-12-01' statementDate='2018-07-10'
orderId='NT-00000-136' account='Sim101' name='Ninza3HamaSell' orderState=Accepted instrument='ES 09-18' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-11 01:08:44' gtd='2099-12-01' statementDate='2018-07-10'
orderId='NT-00000-136' account='Sim101' name='Ninza3HamaSell' orderState=Working instrument='ES 09-18' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2018-05-11 01:08:44' gtd='2099-12-01' statementDate='2018-07-10'
orderId='NT-00000-136' account='Sim101' name='Ninza3HamaSell' orderState=Filled instrument='ES 09-18' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=10 tif=Gtc oco='' filled=10 averageFillPrice=2722.25 onBehalfOf='' id=-1 time='2018-05-11 01:08:44' gtd='2099-12-01' statementDate='2018-07-10'
T5/11/2018 1:10:53 AM;O2722.75;H2723.25;L2722.75;C2723.25;V645
I did note that you are not checking if there is enough data, so this could potentially be applying to this situation. Generally, if you use multiple series, you will also need a check like the following:

Code:
if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
{
	return;
}
Potentially if you are using a different time in the data than I am, you may see different results depending on if both series has been fully loaded or not. If you add the above check-in and retest, do you still see the prints being delayed?

I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Jesse for this post:
Old 07-12-2018, 08:53 PM   #10
guidalpi
Junior Member
 
Join Date: Sep 2017
Posts: 6
Thanks: 1
Thanked 0 times in 0 posts
Default

Hello Jesse,

With your last post I found out what was happening.

As I am adding a secondary 1 tick data series, I cant load my chart with the last 200 bars, as there wont be enough bars for processing. Loading the chart with the days option solves the issue, as well as adding the check you suggested in the last post.

I didnt realized that for the secondary data series the strategy would load only 200 bars. I was expecting that it would load the same period (in days) of the primary data series.

Thank you so much for your time and help!
guidalpi 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
Get the entry execution order bar index from the execution time matrixxx Strategy Development 1 06-11-2018 10:41 AM
CrossAbove/CrossBelow delayed execution tambaa Strategy Development 5 04-09-2015 10:02 AM
Order execution Market Replay calhawk01 Strategy Development 1 10-26-2014 08:00 PM
execution.Order.Filled Vs. execution.Order.Quantity binwang2 General Development 1 08-04-2009 05:52 AM
Error message on Strategy Execution(Market order should be either immediate or cancel SuperDriveGuy Strategy Development 13 03-30-2009 10:38 AM


All times are GMT -6. The time now is 01:46 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 its 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.