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!
See more
See less

Partner 728x90

Collapse

Plotting Level 2 Data

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Plotting Level 2 Data

    Hi I would like to know how I can plot level II market depth size, at the position and time it updated on the chart.

    I am attempting to draw boxes for testing so that I may have a visual representation. When a level II level is updated I want a new box to print on the chart.

    Code:
    	protected override void OnMarketDepth(MarketDepthEventArgs e)
    {
        // Print some data to the Output window
        if (e.MarketDataType == MarketDataType.Ask && e.Operation == Operation.Update)
    	{
             Print("The most recent ask change is " + e.Price + " " + e.Volume + " " + e.Position);
    		ISquare square = DrawSquare("tag1", false, 0, e.Price, Color.Red);
    
    	}
    	
    	  if (e.MarketDataType == MarketDataType.Bid && e.Operation == Operation.Update)
    	{
    	
             Print("The most recent bid change is " + e.Price + " " + e.Volume + " " + e.Position);
    ISquare square = DrawSquare("tag1", false, 0, e.Price, Color.Red);
    	}
    }
    I am getting the following from the output window with no plot:

    The most recent bid change is 2710.75 5 0
    The most recent bid change is 2710.5 43 1
    The most recent ask change is 2711 37 0
    Error on calling 'OnMarketDepth' method for indicator 'MarketDepthMap': MarketDepthMap.DrawSquare: bar out of valid range 0 through -1, was 0.

    Also, how can I specify position in the orderbook? -9 would be 9 levels down in the bid, while 9 is 9 levels above market on the ask?
    Last edited by brucelevy; 04-17-2018, 10:32 PM.

    #2
    Hello brucelevy,

    Thank you for the post.

    Your second question:

    The position value is the price's position in the price ladder. This is easiest to see when you compare your scripts output to the SuperDOM. If the bid is 1 below in the price ladder, then the position for the bid would be one; the same goes for the ask price. There will not be negative values because it is an absolute position (as in absolute value).

    I tested your OnMarketDepth method and I did not receive the error you posted here. I will need more details on your chart configuration. This looks like the OnMarketData event method is being called when there are no bars on the chart. Can you please provide details on how your chart is set up and how the indicator is configured?

    My test script is set up on an ES 06-18 1 minute chart.

    I look forward to your reply.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ghoul, Today, 06:02 PM
    0 responses
    4 views
    0 likes
    Last Post ghoul
    by ghoul
     
    Started by Barry Milan, Yesterday, 10:35 PM
    6 responses
    18 views
    0 likes
    Last Post Barry Milan  
    Started by DanielSanMartin, Yesterday, 02:37 PM
    2 responses
    13 views
    0 likes
    Last Post DanielSanMartin  
    Started by DJ888, 04-16-2024, 06:09 PM
    4 responses
    13 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by terofs, Today, 04:18 PM
    0 responses
    12 views
    0 likes
    Last Post terofs
    by terofs
     
    Working...
    X