NexusFi: Find Your Edge


Home Menu

 





NT 7/8 experts - Exporting market replay data from ninjatrader


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one sifumech with 3 posts (0 thanks)
    2. looks_two sam028 with 1 posts (2 thanks)
    3. looks_3 iantg with 1 posts (2 thanks)
    4. looks_4 logindejavu27 with 1 posts (0 thanks)
    1. trending_up 2,278 views
    2. thumb_up 4 thanks given
    3. group 5 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

NT 7/8 experts - Exporting market replay data from ninjatrader

  #1 (permalink)
 sifumech 
Orlando Florida
 
Experience: Intermediate
Platform: ninjatrader
Trading: Emini ES Treasures
Posts: 5 since Aug 2014
Thanks Given: 1
Thanks Received: 0

I am looking for some cheap continuous ES Depth of Market (level II) data along with level I to use in a program I wrote. This kind of data is pretty expensive but Ninjatrader has some cheap options like MarketReplay.net and marketreplaydata.net. Used marketreplaydata before and it seemed fine. This data however goes directly into ninja. I would love to know if there is a way to export that data out of ninja. Has anyone done this? Any ninja scripts people are willing to share? I need both L1 and L2.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
22 thanks
My NQ Trading Journal
16 thanks
HumbleTraders next chapter
9 thanks
  #2 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

It's very simple, use OnMarketDepth() the record in a file or whatever all updates. There are examples in Ninja help guide.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
 sifumech 
Orlando Florida
 
Experience: Intermediate
Platform: ninjatrader
Trading: Emini ES Treasures
Posts: 5 since Aug 2014
Thanks Given: 1
Thanks Received: 0



sam028 View Post
It's very simple, use OnMarketDepth() the record in a file or whatever all updates. There are examples in Ninja help guide.

Thanks I think I am missing a few things -- since I am not at all familiar with how to extend NT functionality. I looked at the nt doc for the OnMarketDepth and it looks to run real-time for strategies or indicators. So a few questions.
1) Would the code to do this run as an "Indicator" or a strategy or is there some other way to interface with NT to do the extract.
2) I am having trouble finding what class I would call to read a bunch of market replay files. Would using "File" work? Do you happen to know what object that would be?
3) Is there a similar call to OnMarketDepth but for Level I? Would this be OnBarUpdate?

Much appreciated.

Started this thread Reply With Quote
  #4 (permalink)
 iantg 
charlotte nc
 
Experience: Advanced
Platform: My Own System
Broker: Optimus
Trading: Emini (ES, YM, NQ, ect.)
Posts: 408 since Jan 2015
Thanks Given: 90
Thanks Received: 1,148


sifumech View Post
Thanks I think I am missing a few things -- since I am not at all familiar with how to extend NT functionality. I looked at the nt doc for the OnMarketDepth and it looks to run real-time for strategies or indicators. So a few questions.
1) Would the code to do this run as an "Indicator" or a strategy or is there some other way to interface with NT to do the extract.
2) I am having trouble finding what class I would call to read a bunch of market replay files. Would using "File" work? Do you happen to know what object that would be?
3) Is there a similar call to OnMarketDepth but for Level I? Would this be OnBarUpdate?

Much appreciated.

Hi sifumech,

You should run this as a strategy and within the strategy either create print statements to the output window or if you are serious programmer you can send the data somewhere... such as a SQL Server table, or a file. If you are starting out I would stick with just doing a print to the output window. Then you just open your output window and copy it from there.

I should mention this gets a little tricky because the way that you run your print will need to contain some sort of delimiter logic otherwise you just end up with everything running together in one giant cell with no logical way to split it into columns. Here is an example from something I am doing that sounds similar.

Code first, then explanation.

protected override void OnMarketDepth(MarketDepthEventArgs marketDepthUpdate)
{

if (marketDepthUpdate.MarketDataType == MarketDataType.Ask && marketDepthUpdate.Operation == Operation.Update && GetCurrentAsk() == marketDepthUpdate.Price)

{



if(MDEaskV != marketDepthUpdate.Volume || MDEaskP != marketDepthUpdate.Price)

{
Print("Ask Update" +"/" +
Time[0] +"/"+
Time[0].Hour +"/"+
Time[0].Minute +"/"+
Time[0].Second +"/"+
Time[0].Millisecond +"/"+
GetCurrentBid() +"/"+
GetCurrentAsk() +"/"+
lastprice +"/"+
GetCurrentBidVolume() +"/"+
GetCurrentAskVolume() +"/"+
MDEbidP +"/"+
marketDepthUpdate.Price +"/"+
MDEbidV +"/"+
marketDepthUpdate.Volume);

}



MDEaskV = marketDepthUpdate.Volume;
MDEaskP = marketDepthUpdate.Price;
}


if (marketDepthUpdate.MarketDataType == MarketDataType.Bid && marketDepthUpdate.Operation == Operation.Update && GetCurrentBid() == marketDepthUpdate.Price)

{

if(MDEbidV != marketDepthUpdate.Volume || MDEbidP != marketDepthUpdate.Price)

{
Print("Bid Update" +"/" +
Time[0] +"/"+
Time[0].Hour +"/"+
Time[0].Minute +"/"+
Time[0].Second +"/"+
Time[0].Millisecond +"/"+
GetCurrentBid() +"/"+
GetCurrentAsk() +"/"+
lastprice +"/"+
GetCurrentBidVolume() +"/"+
GetCurrentAskVolume() +"/"+
marketDepthUpdate.Price+"/"+
MDEaskP +"/"+
marketDepthUpdate.Volume +"/"+
MDEaskV);

}

MDEbidV = marketDepthUpdate.Volume;
MDEbidP = marketDepthUpdate.Price;
}


}


I declare a few variables earlier... so that is why you do see this, but MDEbidV for example will hold the last known update to the bid volume. I run this after my update, because i use some logic to catch if there has been any change in this variable. So this will only print new values. Otherwise you end up with tons and tons of duplicated extraneous data.


For level 1 data you want to use the OnMarketData event handler. Something like this.

protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
{



if(Bars.Count > 20)
{


// Market Update

if (marketDataUpdate.MarketDataType == MarketDataType.Last)
{
if (marketDataUpdate.Price >= marketDataUpdate.Ask)
{
MDaskV = marketDataUpdate.Volume;
MDaskP = marketDataUpdate.Ask;
}


if (marketDataUpdate.Price >= marketDataUpdate.Bid)
{
MDbidV = marketDataUpdate.Volume;
MDbidP = marketDataUpdate.Bid;
}


lastprice = marketDataUpdate.Price;
}




}

}


I didn't put print statements in there, but you can easily just copy the idea from the level 2 code block i posted above and get your level 1 objects. You should separate your print statements with some sort of identifier so you can tell your level 1 prints from your level 2 prints if you try to run this on the same strategy, otherwise it will get confusing.

Also, as I am sure you are wondering, if you want to capture level 2 prices further out. (Resting volumes several price levels out in the DOM for example) you will need to add multiple levels to the code example I provided. For each of these you will just need to capture the applicable price level by doing GetCurrentBid() -.25 or GetCurrentAsk() + .25 (These will give you the first resting level out.) Then just increment by .25 to get each additional level. You would just replace each of these in the if statement (&& GetCurrentAsk() == marketDepthUpdate.Price) where it is looking for the mareketDepthUpdate.Price... You just tell it which price level it is updaing. .25, .5, .75, 1.25, etc. Just add this to your getcurrentbid, or getcurrentask statements.

A bit complex, but totally easy using the examples I provided.

Happy Coding!

Ian

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #5 (permalink)
 sifumech 
Orlando Florida
 
Experience: Intermediate
Platform: ninjatrader
Trading: Emini ES Treasures
Posts: 5 since Aug 2014
Thanks Given: 1
Thanks Received: 0

Ian, I bow down to your generosity and knowledge. A very heartfelt 'thank you' . One small question though: How do you specify that you want this to run against Market replay data? Ideally I would like to run this code against a number of days held in market replay files. Do I need to replay each day in order for this code to run or is there some sort of calls I can make to read from files directly.

Thanks again so much.

!! Whoops nevermind. You said this was a strategy so I can just select backtest and give it a date range. Awesome. Ian thanks again!

Started this thread Reply With Quote
  #6 (permalink)
 logindejavu27 
Berlin, Germany
 
Experience: None
Platform: NinjaTrader, Custom
Broker: NinjaTrader, IB
Trading: Moving prices
Posts: 9 since Mar 2019
Thanks Given: 3
Thanks Received: 10


sifumech View Post
I am looking for some cheap continuous ES Depth of Market (level II) data along with level I to use in a program I wrote. This kind of data is pretty expensive but Ninjatrader has some cheap options like MarketReplay.net and marketreplaydata.net. Used marketreplaydata before and it seemed fine. This data however goes directly into ninja. I would love to know if there is a way to export that data out of ninja. Has anyone done this? Any ninja scripts people are willing to share? I need both L1 and L2.

Here is strategy to convert market replay to csv/ticks: NT8 Download section link

Reply With Quote




Last Updated on December 3, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts