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 junkone, Today, 11:37 AM
    2 responses
    15 views
    0 likes
    Last Post junkone
    by junkone
     
    Started by frankthearm, Yesterday, 09:08 AM
    12 responses
    44 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by quantismo, 04-17-2024, 05:13 PM
    5 responses
    35 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by proptrade13, Today, 11:06 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    36 views
    0 likes
    Last Post love2code2trade  
    Working...
    X