NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 02-16-2012, 03:06 PM   #1
Ramon
Member
 
Join Date: Oct 2009
Location: Madrid (Spain)
Posts: 39
Thanks: 15
Thanked 1 time in 1 post
Default OnMarketData & Multiinstruments

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,
Ramon is offline  
Reply With Quote
Old 02-16-2012, 03:35 PM   #2
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 02-16-2012, 04:16 PM   #3
Ramon
Member
 
Join Date: Oct 2009
Location: Madrid (Spain)
Posts: 39
Thanks: 15
Thanked 1 time in 1 post
Default

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);
                }
         
                    }
        }
give that results:
Quote:
BIP==0 Time = 16/02/2012 23:59:53
BIP==0 Price = 1355,25
BIP==0 Volume = 2
BIP==2 Time = 16/02/2012 23:59:53
BIP==2 Price = 2593,75
BIP==2 Volume = 2
BIP==0 Time = 16/02/2012 23:59:54
BIP==0 Price = 1355,25
BIP==0 Volume = 252
BIP==0 Time = 16/02/2012 23:59:54
BIP==0 Price = 1355,25
BIP==0 Volume = 252
BIP==2 Time = 16/02/2012 23:59:54
BIP==2 Price = 2593,75
BIP==2 Volume = 3
BIP==0 Time = 16/02/2012 23:59:55
BIP==0 Price = 1355
BIP==0 Volume = 3
BIP==0 Time = 16/02/2012 23:59:55
BIP==0 Price = 1355
BIP==0 Volume = 3
BIP==0 Time = 16/02/2012 23:59:56
BIP==0 Price = 1355
BIP==0 Volume = 1
BIP==0 Time = 16/02/2012 23:59:56
BIP==0 Price = 1355
BIP==0 Volume = 1
BIP==0 Time = 16/02/2012 23:59:57
BIP==0 Price = 1355
BIP==0 Volume = 6
BIP==0 Time = 16/02/2012 23:59:57
BIP==0 Price = 1355
BIP==0 Volume = 6
All of BIP==0 are duplicated.
Attach complete indicator if you want to check
Attached Files
File Type: cs OMDTest.cs (6.0 KB, 4 views)
Ramon is offline  
Reply With Quote
The following user says thank you to Ramon for this post:
Old 02-17-2012, 02:35 AM   #4
Ramon
Member
 
Join Date: Oct 2009
Location: Madrid (Spain)
Posts: 39
Thanks: 15
Thanked 1 time in 1 post
Default

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.
Ramon is offline  
Reply With Quote
Old 02-17-2012, 07:41 AM   #5
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

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.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 03-01-2012, 03:36 AM   #6
Ramon
Member
 
Join Date: Oct 2009
Location: Madrid (Spain)
Posts: 39
Thanks: 15
Thanked 1 time in 1 post
Default

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:
protected override void OnMarketData(MarketDataEventArgs e)
(if (dLastPrice==e.Price && lLastVolume==e.Volume && tStamp==e.Time)
return;
)
I don't now if I'm doing the right thing. Is there any native way to distinguish events? TThere are a lot of unexplored stuff like : "Bars." , "Instrument." , "BarsPeriod." etc.
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;
Thanks
Last edited by Ramon; 03-01-2012 at 04:18 AM.
Ramon is offline  
Reply With Quote
Old 03-01-2012, 07:15 AM   #7
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello Ramon,
OnMarketData is a realtime stream only. It cannot be backtested.

From the help files
Quote:
This method is not called on historical data (backtest)
http://www.ninjatrader.com/support/h...marketdata.htm

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.
NinjaTrader_Joydeep is offline  
Reply With Quote
Old 03-01-2012, 10:50 AM   #8
Ramon
Member
 
Join Date: Oct 2009
Location: Madrid (Spain)
Posts: 39
Thanks: 15
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by NinjaTrader_Joydeep View Post
Hello Ramon,
OnMarketData is a realtime stream only. It cannot be backtested.
.
omg. How hard is to explain things properly:
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
Ramon is offline  
Reply With Quote
Old 03-01-2012, 12:27 PM   #9
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

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
NinjaTrader_Brett 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
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


All times are GMT -6. The time now is 09:42 AM.