Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
pairstrading
Collapse
X
-
imported post
Hi,
NinjaTrader supports multi-timeframe and instrument strategies. This means that you can apply a strategy to a 1 MIN ES Bars object and add a 1 MIN YM Bars object as well.
You can execute trades against each of these instruments but only in the context of their bar update event.
So if a tick comes in for ES, you can execute a trade against the ES, then a tick comes in for YM, you can execute a trade against YM.
What you can't do is the following: A tick comes in for ES, you execute a trade against YM.
Additional information can be found here - http://www.ninjatrader-support.com/H...struments.html
Ray
RayNinjaTrader Customer Service
-
imported post
There is a very detailed explanation in the link I posted below on this. The explanation there will be much better than what I am going to summarize here.
Our strategy concept is event driven. This means each time a bar event is triggered (tick comes in for the bar) the OnBarUpdate() method is called. This method contains your strategy logic. This method can be calledon the close of a bar or for each incoming tick.
When OnBarUpdate() is called from the ES 1 Min bar, you can execute a trade for the ES. When OnBarUpdate() is called for the YM 1 Min bar, you can execute a trade for the YM.
When OnBarUpdate()is calledfrom the ES 1 Min bar, you can't execute a trader for YM etc..
Ray
RayNinjaTrader Customer Service
Comment
-
I have a question related to this:
Could I use the OnMarketData() method to catch updates on any of multiple instruments that have been added in the strategy? And when I have such an update can I then somehow ask what the market are for ALL my instruments, make a calculation and then send limit orders on ALL my instruments, not only on the instrument that triggered the OnMarketData() method?
Comment
-
Originally posted by dantes View PostI have a question related to this:
Could I use the OnMarketData() method to catch updates on any of multiple instruments that have been added in the strategy? And when I have such an update can I then somehow ask what the market are for ALL my instruments, make a calculation and then send limit orders on ALL my instruments, not only on the instrument that triggered the OnMarketData() method?RayNinjaTrader Customer Service
Comment
-
Great news! I am new to your system and I was beginning to be afraid spreads or pairs lay outside of its scope. I have been trying to find an example of a multi instrument strategy code, but all I can find are not really a spread or a pairs setup. Would you have any such example code?
In any case can you show how to ask for market information in several instruments? Would it be that the "MarketDataEventArgs" that is thrown into OnMarketUpdate does hold all instruments? So that you can access the market data with something like
price_instrument1= e[0].Price;
price_instrument2 = e[1].Price;
But if so what is "Price"? What you really would like to do is to be able to ask for e[x].Bid and e[x].Ask
Basically what I would like to be able to do is on every market update on any instrument read in all market data in all instruments and then make a decision for actions based on these numbers.
Thanks!
Comment
-
Thinking some more on this I guess this is what you mean:
first I define a bunch of variables in my strategy class:
//current market information
private double Instrument1bid = 0;
private double Instrument1ask = 0;
private double Instrument1last = 0;
private double Instrument2bid = 0;
private double Instrument2ask = 0;
private double Instrument2last = 0;
and then I create this method:
protected override void OnMarketData(MarketDataEventArgs e)
{
if (BarsInProgress == 0)
{
if (e.MarketDataType == MarketDataType.Last)
Instrument1last = e.Price;
else if (e.MarketDataType == MarketDataType.Ask)
Instrument1ask = e.Price;
else if (e.MarketDataType == MarketDataType.Bid)
Instrument1bid = e.Price;
}
else if (BarsInProgress == 1)
{
if (e.MarketDataType == MarketDataType.Last)
Instrument2last = e.Price;
else if (e.MarketDataType == MarketDataType.Ask)
Instrument2ask = e.Price;
else if (e.MarketDataType == MarketDataType.Bid)
Instrument2bid = e.Price;
//here we use the market info variables to calculate stuff and then send some orders
}
}
Comment
-
Great, on a related note: can I write a strategy for two instruments in a generic way? From what I have read so far the method is to use
Add("IBM",PeriodType.Minute,1);
But of course I dont want to write one strategy for every "pair" so I would like to be able to do
Add(instrument2,PeriodType.Minute,1);
Where instrument2 is a variable containing a specific instrument only when I start a specific instance of my strategy. How do I do this?
Comment
-
ok too bad, maybe I can be so bold as suggest you add support for it? You would have a considerable more powerful product.
Anyways, I have just figured out that my approach posted earlier is flawed. This:
protected override void OnMarketData(MarketDataEventArgs e)
{
if (BarsInProgress == 0)
{
if (e.MarketDataType == MarketDataType.Last)
Instrument1last = e.Price;
else if (e.MarketDataType == MarketDataType.Ask)
Instrument1ask = e.Price;
else if (e.MarketDataType == MarketDataType.Bid)
Instrument1bid = e.Price;
}
else if (BarsInProgress == 1)
{
if (e.MarketDataType == MarketDataType.Last)
Instrument2last = e.Price;
else if (e.MarketDataType == MarketDataType.Ask)
Instrument2ask = e.Price;
else if (e.MarketDataType == MarketDataType.Bid)
Instrument2bid = e.Price;
does not work until market updates have made sure that all my variables contain current market data. How do I set values in the beginning? Is there no way to read market data based on start of a strategy rather then based on market updates?
Comment
-
Thanks for your suggestion. We'll add it to the list of future considerations.
>> How do I set values in the beginning?
I suggest recoding your logic such that it would not depend on data which is not available yet.
In addition you could check out e.MarketData.Ask etc. properties holding the last value seen. However, this is beyond what we provide support for.
Comment
-
>> In addition you could check out e.MarketData.Ask etc. properties holding the last value seen.
Could you provide some additional information on this? By trial and error it seems e.MarketData.Ask is a bool and not a number. Where can I find more information? Thanks!
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by 1001111, Today, 01:35 AM
|
0 responses
1 view
0 likes
|
Last Post
by 1001111
Today, 01:35 AM
|
||
Started by ETFVoyageur, Yesterday, 07:05 PM
|
1 response
15 views
0 likes
|
Last Post
by ETFVoyageur
Today, 01:33 AM
|
||
Started by MarianApalaghiei, Today, 12:35 AM
|
1 response
7 views
0 likes
|
Last Post Today, 01:17 AM | ||
Started by Rogers101, 05-05-2024, 11:30 AM
|
17 responses
56 views
0 likes
|
Last Post
by Rogers101
Today, 01:14 AM
|
||
Started by haas88, 03-21-2024, 02:22 AM
|
13 responses
155 views
0 likes
|
Last Post
by haas88
Today, 01:13 AM
|
Comment