Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

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

Reply
 
Thread Tools Display Modes
Old 05-06-2012, 03:44 AM   #1
bigben1
Junior Member
 
Join Date: May 2012
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
Default Some doubt about order management

Hey Ninjas,

I need some help about order management, I have read the help page, but there is a point i am not sure about.

I am currently running a multi instrument strategy, and under some conditions, I want to submit orders on each instrument. For now, I use this syntax:

EnterLong(Which Instrument ,How many, signal name);

and I do something like that for every instrument I have. When I try to use:

if (BarsInProgress == compteur){
EnterLong(How many, signal name);
}

the result is not the same. What is the difference between the two?

Moreover, let's say I have 2 Long position on an instrument, and now my algorithm tell me to be flat. Currently, I do:
ExitLong("", signal name);
and when my algorithm tell me to have 1 short position, I use:
Exitlong("", signal name);
EntryShort(Instrument, 1, signal name);
Is it correct? What about going from 2 Long to 1 Long? And to 3 Long?
I keep last actions required by my algorithm in an int array...

Thank you.
bigben1 is offline  
Reply With Quote
Old 05-06-2012, 04:55 PM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 381 times in 371 posts
Default

bigben,

The first option would submit an order to the instrument from the data series.

The second option would wait until the OnBarUpdate() method is called for that specific data series before it enters the order.

Here is a reference sample on scaling out of a position.

http://www.ninjatrader.com/support/f...ead.php?t=3751
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-07-2012, 12:34 AM   #3
bigben1
Junior Member
 
Join Date: May 2012
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you for your reply.

Say I'm working on a 45 minutes time frame for all instruments. I need to wait to have all data to submit orders. How can I do that? Can I check if OnBarUpdate() has been called for all instruments?

Thank you
bigben1 is offline  
Reply With Quote
Old 05-07-2012, 07:13 AM   #4
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,568
Thanks: 111
Thanked 314 times in 299 posts
Default

Quote:
I need to wait to have all data to submit orders
What exactly do you mean by that.If you give us some more detail on specificly what you are trying to do we may be able to offer some additional information.

OnBarUpdate() is called for each series and each change in the bar. Each OnBarUpdate call has an BarsInProgress and each one of these are called individually.

They are their own separate units until you add code to take action based on them.

In the case you describe the best idea I have for you is to set a flag for all OnBarUpdate()'s to set to true. Once all OnBarUpdate()s flag to true then you can take some action.

Waiting for confirmation for ALL BIP's would delay your entry an OnBarUpdate() call most likely.

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Old 05-07-2012, 02:10 PM   #5
bigben1
Junior Member
 
Join Date: May 2012
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you Brett.

What I do is a computation on historical closes in a multi instrument strategy. Indeed, even if I can have the price of every instrument 10 second before the bar close, I think it would be ok. I tried to do it with CalculateOnBarClose = false, coupled with if (DateTime.Now < Time[0].AddSeconds(-10)), but when I try to access the price with Closes[i][0], is it really the last tick for all instruments? And Closes[i][1] is the previous close?

Then I can use a flag to prevent the computation from being done twice.

It would be simplier for me even to store data whenever I want this way. So I can create my own bar, in order to avoid different bars for different instruments... For example, YG and TF don't have the same 45 minutes bars...

I really appreciate your help.
Last edited by bigben1; 05-07-2012 at 02:13 PM.
bigben1 is offline  
Reply With Quote
Old 05-07-2012, 02:18 PM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 381 times in 371 posts
Default

Quote:
Originally Posted by bigben1 View Post
I think it would be ok. I tried to do it with CalculateOnBarClose = false, coupled with if (DateTime.Now < Time[0].AddSeconds(-10)), but when I try to access the price with Closes[i][0], is it really the last tick for all instruments? And Closes[i][1] is the previous close?

Then I can use a flag to prevent the computation from being done twice.
I really appreciate your help.

With calculate on bar close = false, Closes[i][0] will always be the latest tick. OnBarUpdate() would be called once every incoming tick.

I am not sure what you mean here as far as preventing calculations from being done twice. Each calculation will be unique if you have CalculateOnBarClose() = false for those series with 0 indices since OnBarUpdate() would be called for each tick.

You could try the following reference sample, it may be what you are looking for.

http://www.ninjatrader.com/support/f...ad.php?t=19387
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-07-2012, 02:30 PM   #7
bigben1
Junior Member
 
Join Date: May 2012
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks, but it is not really what I'm looking for. Sorry for my poor English...

Let's consider an example. I would like to trade 5 Instruments. To do so, my algorithm need historical data. But my problem today is that those historical data are not synchronized, and if I try to wait for the last OnBarsUpdate with a flag or something like that, it would delay my trade. So what I need is to store data every "real" 45 minutes for example. So, once I have enough historical data, my algorithm can pass order every 45 minutes on these 5 instruments.

Am I clear enough?
bigben1 is offline  
Reply With Quote
Old 05-07-2012, 02:49 PM   #8
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 381 times in 371 posts
Default

bigben,

You can use the term :

if( Historical )
{

}

To check if you are on a historical bar. For CalculateOnBarClose = false, I would suggest using the BarsInProgress along with FirstTickOfBar to check when a new bar just opened. This would be one tick after the closing of the last bar.

For example :

If ( BarsInProgress == 0 && FirstTickOfBar)
{

// OnBarUpdate() was called for the primary (chart) instrument
// do something

}

If ( BarsInProgress == 1 && FirstTickOfBar)
{

// OnBarUpdate() was called for the first added instrument
// do something

}

If ( BarsInProgress == 2 && FirstTickOfBar)
{

// OnBarUpdate() was called for the second added instrument
// do something

}

I believe this is what you are asking, but feel free to let me know if this is not sufficient. I would be happy to make more suggestions.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 05-07-2012, 03:11 PM   #9
bigben1
Junior Member
 
Join Date: May 2012
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you, I'll try something like this, but "do something" should be "do nothing". I need to wait for all updates, and I guess I can deal with that with a flag. What is the idea with placing a FirstTickOfBar in the condition? Isn't it the definition of OnBarsProgress?
Would it be possible to create my own Data series?

Thank you again
bigben1 is offline  
Reply With Quote
Old 05-07-2012, 03:26 PM   #10
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 381 times in 371 posts
Default

bigben,

You can create your own dataseries.

http://www.ninjatrader.com/support/f...ead.php?t=4991

As far as the first tick of bar, this is built in for use when CalculateOnBarClose = false, since OnBarUpdate() would be called multiple times per bar as its updated tick by tick for real time data.

BarsInProgress can be checked to see which series is being updated, however it doesn't guarantee this data series is being updated on the closing of the bar since it can be updated tick by tick. FirstTickOfBar can be used to check if a new bar just opened when CalculateOnBarClose = false.
NinjaTrader_AdamP 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
Order Management tbmuc Strategy Development 1 01-19-2012 02:08 PM
Order doubt dvercher Automated Trading 3 07-01-2011 01:27 PM
Order Management ScoobyStoo General Programming 6 01-13-2010 03:06 AM
Order Management--Order Via Strategy and SuperDOM? djdinut1 Strategy Development 3 05-28-2009 12:58 PM
order management monas Miscellaneous Support 1 03-22-2005 01:57 AM


All times are GMT -6. The time now is 06:26 AM.

FULL RISK DISCLOSURE: Futures 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.