NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader.

Reply
 
Thread Tools Display Modes
Old 04-02-2007, 12:23 AM   #1
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Guys

I have been thoroughly testing today. Everything is going reasonable well.

I have encountered the following problem:

An order is submitted from inside OnBarUpdate.

It can take a second to go from accepted->working->filled.

In that time, a new TICK arrived. OnBarUpdate is retriggered and a new order is submitted. Like I said this happens in the space between accepted and filled.

I have been looking in the reference for a function/method that gives something along the lines of: OrderState that returns Working/Accepted etc... does this exist somewhere?

Also: I am seeing a lot of State=PendingChange. What causes this?
Oli is offline  
Reply With Quote
Old 04-02-2007, 01:12 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

Oli,

Would you mind eloborating on your initial concern? I can't make out what behaviour you are seeing that you are not expecting.

There are not methods in the NinjaScript layer that return order status. In concept, this should not be required since the NinjaScript layer takes care of managing order submission, re-submission and cancellation.

PendingChange is caused when an order is changed. The following code sample would do this if called on the close of each bar.


EnterLongLimit(Low[0]);

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-02-2007, 02:04 AM   #3
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Hey Ray,

sorry for the lack of clarity. I'll try again:

When an order is submiited from inside OnBarUpdate (EnterLongLimit say), what happens next? Is the script somehow halted at that point until the order filled, or does the next line of code execute immediately?
Oli is offline  
Reply With Quote
Old 04-02-2007, 02:07 AM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

Processing is not halted, the next line of code is executed. The only time code is not executed is when an exception is trapped at which time the strategy stops running and an error is logged in the Control Center log tab.

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-02-2007, 02:11 AM   #5
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

OK - good.

So then When the EnterLongLimit line is execute, an order is sent. This order takes time to go from PendingSubmit->Accepted->Working->Filled, right? This isn't at all instantaneous is it?
Oli is offline  
Reply With Quote
Old 04-02-2007, 02:14 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

Correct, it is not instantaneous. There is always a delay with live account orders and in the Sim101 account.

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-02-2007, 02:20 AM   #7
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

OK - great.

So this is where there is a problem.

EnterLongLimit executes.

Order is Pending.

OnBarUpdate method finishes = waiting for next TICK.

Order is Accepted.

New TICK arrives.

Position.MarketPosition == MarketPosition.Flat

Order is Working.

EnterLongLimit executes a second time.

Order is filled just before new order is pending.

I now have TWO, instead of ONE, orders off the same trade signal.

I MUST have a logic switch that says something like:

Position.MarketPosition == MarketPosition.PENDING

PENDING is not Flat.

This is the problem...
Oli is offline  
Reply With Quote
Old 04-02-2007, 02:23 AM   #8
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

here is a screen shot of two exact same order executing within a half second of one another:




Attached Images
File Type: png 14.png (25.7 KB, 28 views)
Oli is offline  
Reply With Quote
Old 04-02-2007, 02:29 AM   #9
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

When run your strategy,

Set your "Entries per direction" to a value of 1 if you only ever want to have one of the orders executed.

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-02-2007, 02:33 AM   #10
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Ray,

thanks for the suggestion but it is not a solution. A good stratgey never simply runs long then short then long then short. In theory my strategies can go LONG an infinite number of time without ever being short.

What does that then mean - my Strat only trades once? This is limited and not workable unfortunately.
Oli is offline  
Reply With Quote
Old 04-02-2007, 02:40 AM   #11
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

Oli,

Doyou want to golong multiple times on the same trade signal?

If no, then provide a unique signal name for each trade signal in the long direction and set the "Entries per direction" to a value of 1, set "Entry handling" to Unique Entries.

If yes, but you only want to enter while an order is NOT pending, then you have to get creative and add some logic to check for pending conditions.

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-02-2007, 02:49 AM   #12
Oli
Member
 
Join Date: Feb 2007
Location: , ,
Posts: 83
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Thanks Ray,

I'll have a closer look at the handling = unique side of the coin. That soundspromising.I do not want to enter multiple trades off of one signal. But I do want a long to be able to follow a long...

"add some logic to check for pending conditions."

I have looked for a method that will access the State=[Pending*, Accepted, Working, Filled] but can't see any...and I think you said below that there are none.

Oli is offline  
Reply With Quote
Old 04-02-2007, 03:13 AM   #13
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

Check for pending means adding your own variables to track when an order is submitted, cancelled, filled by checking the market position etc... That's what I meant by creative.

Ray
NinjaTrader_Ray 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


All times are GMT -6. The time now is 08:02 AM.