Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 12-22-2017, 10:26 AM   #1
keepsimple
Senior Member
 
Join Date: May 2014
Posts: 126
Thanks: 8
Thanked 9 times in 8 posts
Default Limited DOM Rows

Hi,

to make it it easy I took a code snippet of a reference sample which builds a list of market depth and populates or updates that list.

protected override void OnMarketDepth(MarketDepthEventArgs e)
{
lock (e.Instrument.SyncMarketDepth)
{
List<LadderRow> rows = (e.MarketDataType == MarketDataType.Ask ? askRows: bidRows);
LadderRow row = new LadderRow { MarketMaker = e.MarketMaker, Price = e.Price, Volume = e.Volume };

if (e.Operation == Operation.Add || (e.Operation == Operation.Update && (rows.Count == 0 || rows.Count <= e.Position)))
{
if (rows.Count <= e.Position)
rows.Add(row);
else
rows.Insert(e.Position, row);
}
else if (e.Operation == Operation.Remove && rows.Count >= e.Position)
{
rows.RemoveAt(e.Position);
}
else if (e.Operation == Operation.Update)
{
if (rows[e.Position] == null)
{
rows[e.Position] = row;
}
else
{
rows[e.Position].Price = e.Price;
rows[e.Position].Volume = e.Volume;
}
}
}
}

Question is:

How can I modify the above or a overall comparable code to only store and or update a limited amount of depth rows e.g. 10 bid and ask depth rows.

I tried different ways, but cannot get the desired outcome.

Regards and thanks in advance.
Last edited by keepsimple; 12-22-2017 at 10:30 AM.
keepsimple is offline  
Reply With Quote
Old 12-22-2017, 10:37 AM   #2
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 5,065
Thanks: 30
Thanked 1,291 times in 1,209 posts
Default

Hello,

Thank you for the post.

In this situation, the number of rows would be controlled by the data provider being used. I could not suggest any ways to increase the number of rows. To limit the number of rows to 10, you would need to use logic.

Are you trying to only store the first 5 rows of the ask and bid or reset the collection at a specific time?

Please let me know if I may be of further assistance.
Last edited by NinjaTrader_Jesse; 12-22-2017 at 10:40 AM.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 12-22-2017, 10:41 AM   #3
keepsimple
Senior Member
 
Join Date: May 2014
Posts: 126
Thanks: 8
Thanked 9 times in 8 posts
Default

Hi Jesse,

I want to have an updating window of e.g. 10 levels of bids and offers as displayed in the superdom. in crude for example the code stores way more levels, so have can I limit that to 10.
Last edited by keepsimple; 12-22-2017 at 10:43 AM.
keepsimple is offline  
Reply With Quote
Old 12-22-2017, 10:42 AM   #4
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 5,065
Thanks: 30
Thanked 1,291 times in 1,209 posts
Default

Hello,

Thank you for the reply.

Yes, Are you trying to only store the first 5 rows of the ask and bid or reset the collection at a specific time?

Please let me know if I may be of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 12-22-2017, 10:44 AM   #5
keepsimple
Senior Member
 
Join Date: May 2014
Posts: 126
Thanks: 8
Thanked 9 times in 8 posts
Default

Hi Jesse,

I want to have an updating window of e.g. 10 levels of bids and offers as displayed in the superdom. in crude for example the code stores way more levels, so how can I limit that to 10.
keepsimple is offline  
Reply With Quote
Old 12-22-2017, 10:51 AM   #6
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 5,065
Thanks: 30
Thanked 1,291 times in 1,209 posts
Default

Hello,

If you are going to iterate through the list yourself, you could just use a for loop with 10:

Code:
for(int i = 0; i < 10; i++)
{
    LadderRow row = rows[i];
}
If you want the list to only contain 10 total elements, you would need to modify the logic that fills the list to stop once a count of 10 is reached.

I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 12-22-2017, 01:00 PM   #7
keepsimple
Senior Member
 
Join Date: May 2014
Posts: 126
Thanks: 8
Thanked 9 times in 8 posts
Default

is it possible to use something like this in an indicator? Found this in the addon section.

private void OnMarketDepth(object sender, MarketDepthEventArgs e)
{


for (int i = 0; i < marketDepth.Asks.Count; i++)
{

}
}


Loop through 10 Levels and copy them into the list?
keepsimple is offline  
Reply With Quote
Old 12-22-2017, 03:57 PM   #8
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 5,065
Thanks: 30
Thanked 1,291 times in 1,209 posts
Default

Hello,

The private void specifically could not be used in an Indicator.

The private void you have shown is part of a greater sample for Addons specifically where you subscribe to the market data events from an instrument picker. This process is not needed in an indicator because an indicator already has the override which references the series the indicator is interested in:

Code:
protected override void OnMarketDepth(MarketDepthEventArgs e)
{

}
In the sample you originally posted, to limit the items in the lists in the or limit how many are displayed, you would either need to only add the number of items you want to each list or iterate over each list the number of elements you want.

The ask and bid rows are added to the two lists: askRows: bidRows.

To find 10 ask rows, you could loop over the collection 10 times:

Code:
for(int i = 0; i < 10; i++)
{
    LadderRow row = askRows[i];
}

The sample you had originally posted about would be the suggested way to retrieve and build the rows of market depth from an indicator. You can expand off of that example in any way you wish, but that would be the correct way to build the rows. How you later access the rows in those lists would be up to you.


Please let me know if I may be of additional assistance.
NinjaTrader_Jesse 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
DOM appears limited ONLY to markets listed in Default List.... Pipskateer Platform Technical Support 2 09-16-2016 12:59 PM
onMarketDepth limited to 10 rows of depth? DionysusToast General Development 5 12-13-2012 12:36 PM
Switching columns to rows? adamus Platform Technical Support 3 08-23-2011 03:07 PM


All times are GMT -6. The time now is 11:49 AM.

Futures, foreign currency and options 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.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.