![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Oct 2009
Location: Madrid (Spain)
Posts: 39
Thanks: 15
Thanked 1 time in 1 post
|
As far as I know there is no way to associate an event to the instrument that generated.
When using multiple time frames for the same instrument, you get as many events as add(instrument) you put. A consequence of this multiply the results unnecessarily I think Barinprogress does not work outside of onbarupdate At least do not .Into OMD Maybe add an implementation with an argument more or increase the DataType enumeration. In my opinion this is necesary Thank you very much, |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello Ramon,
Thanks for writing in and I am happy to assist you. BarsInProgress can be called from the OnMarketData method. If you have a multi-instrument indicator BarsInProgress will be unique for each instrument. But in case of a multi time frame indicator, BarsInProgress will return the first BarsInProgress that matches the instrument i.e. if you have ES 03-12 one minute chart as the primary series and ES 03-12, five minute chart as the secondary series then BarsInProgress will return 0 only. http://www.ninjatrader.com/support/h...marketdata.htm Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Member
Join Date: Oct 2009
Location: Madrid (Spain)
Posts: 39
Thanks: 15
Thanked 1 time in 1 post
|
Something like that:
Code:
protected override void Initialize()
{
Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last);
// Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid);
// Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask);
Add("NQ 03-12", PeriodType.Tick, 1, MarketDataType.Last); // nasdaq
}
protected override void OnMarketData(MarketDataEventArgs e)
{
if(e.MarketDataType==MarketDataType.Last)
{
if (BarsInProgress == 0)
{
Print("BIP==0 Time = " + e.Time);
Print(" BIP==0 Price = " + e.Price);
Print("BIP==0 Volume = " + e.Volume);
}
else if (BarsInProgress == 1)
{
Print("BIP==1 Time = " + e.Time);
Print(" BIP==1 Price = " + e.Price);
Print("BIP==1 Volume = " + e.Volume);
}
else if (BarsInProgress ==2)
{
Print("BIP==2 Time = " + e.Time);
Print(" BIP==2 Price = " + e.Price);
Print("BIP==2 Volume = " + e.Volume);
}
}
}
Quote:
Attach complete indicator if you want to check |
|
|
|
|
|
The following user says thank you to Ramon for this post: |
|
|
|
#4 |
|
Member
Join Date: Oct 2009
Location: Madrid (Spain)
Posts: 39
Thanks: 15
Thanked 1 time in 1 post
|
Right now I'm just interested in BID / ASK / LAST both on-line and historical. This led me to try to add instruments BID / ASK / LAST to basically treat them in back-test.
Finding that OnMarketData going on, I realized that arrived four repeated events and could not distinguish them by BIP. This led me to a wrong conclusion and that is that BIP did not work at OMD. I apologize for this. If you want you can move this thread to general programming or another forum. I have a lot of questions about these issues and I would like to develop in the future.
Last edited by Ramon; 02-17-2012 at 02:40 AM.
|
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello Ramon,
Glad you could understand the concept. Also please note OnMarketData is a real time data stream, and is not called on backtest. For backtest you have to create a multi-series strategy, with the Bid/Ask price as the additional data series. Also as per your request the thread had been moved to general programming. I look forward to assist you further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
#6 | |
|
Member
Join Date: Oct 2009
Location: Madrid (Spain)
Posts: 39
Thanks: 15
Thanked 1 time in 1 post
|
Here I am, again with the same problem. I'm using multiseries to backtest and although data are not very reliable, it serves my purposes.
The problem is that when indicator comes to the present, OMD receives an event for each instrument and all are classified as BIP = 0. OMD is able to distinguish between instruments with different names, ie ES or NQ, but is not able to do so whith same name but different time frames. I can only do the following: Quote:
Can you eliminate instruments with something like Dispose() or other methods? So I can do something like: Code:
if (Historical)
use it;
else dispose it;
Last edited by Ramon; 03-01-2012 at 04:18 AM.
|
|
|
|
|
|
|
#7 | |
|
NinjaTrader Customer Service
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
|
Hello Ramon,
OnMarketData is a realtime stream only. It cannot be backtested. From the help files Quote:
Since it is a realtime stream, only one stream will be created for each instrument. Unfortunately Bars etc classes which are not documented in the help file are not supported. We would not recommend Disposing any BarsArray as this can adversely affect the functioning of the NinjaScript and can break NinjaTrader. Please let me know if I can assist you any further.
Joydeep M.
NinjaTrader Customer Service |
|
|
|
|
|
|
#8 | |
|
Member
Join Date: Oct 2009
Location: Madrid (Spain)
Posts: 39
Thanks: 15
Thanked 1 time in 1 post
|
Quote:
Can I add a bid ,ASK, last series and then access their historical values in a indicator ? http://www.ninjatrader.com/support/h....html?add3.htm Can I use OnMarketData() for realtime use ? Code:
if (Can I use historical series && OnMarketData)
How can you do that if BIP into OMD doesn't work?
else
Good bye. It was a pleasure. I think I 'll know how to manage matters into my own hands
![]() Thanks |
|
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
|
omg. How hard is to explain things properly: [Brett] No problem you explain just fine.
Can I add a bid ,ASK, last series and then access their historical values in a indicator ? http://www.ninjatrader.com/support/h....html?add3.htm [Brett] - Yes you can do that, considering your provider supports ask and bid data or you have recorded this data yourself. Can I use OnMarketData() for realtime use ? [Brett] Yes
Brett
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Contention between T&S and OnMarketData? | Tarkus11 | Charting | 7 | 06-29-2011 01:56 PM |
| OnMarketData Volume & Tick Issues | RJay | General Programming | 4 | 10-11-2010 02:31 PM |
| OnMarketData & Begin of session | cls71 | Version 7 Beta General Questions & Bug Reports | 1 | 07-16-2010 06:33 AM |
| OnMarketData & Market Replay problem | cls71 | Version 7 Beta General Questions & Bug Reports | 13 | 03-31-2010 08:49 AM |
| OnMarketData() & CalculateOnBarClose | mrlogik | Strategy Development | 8 | 07-30-2008 03:22 PM |