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

DOM on chart

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

    DOM on chart

    Hello all, first i am a newbie in coding so i try. What i want is to create an indicator for NT8, that can post on text labels on my chart the available contracts of level 2. I can do that currently but my problem is that when i print to output window it updates the numbers every time there is a change in dom and this is what i want but when i create text objects to my chart and print there it updates only when there is a new tick. Has someone an idea why that happens?

    thank you

    Here is market depth method

    Code:
     
    protected override void OnMarketDepth(MarketDepthEventArgs e)
            {
    			// protect e.Instrument.MarketDepth.Asks and e.Instrument.MarketDepth.Bids against in-flight changes
    			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].MarketMaker	= e.MarketMaker;
    						rows[e.Position].Price			= e.Price;
    						rows[e.Position].Volume			= e.Volume;
    					}
    	            }
    			}
    			
    			ClearOutputWindow();
    			Print(askRows[0].Volume);
    				// Prints the L2 Ask Book we created. Cycles through the whole List and prints the contained objects.
    				
    				if (e.MarketDataType == MarketDataType.Ask && e.Operation == Operation.Update){
    				for (int idx = askRows.Count-1; idx >=0; idx--){
    					Draw.Text(this, "ask"+idx,(askRows[idx].Price+" - "+askRows[idx].Volume).ToString() , 0, askRows[idx].Price, Brushes.Black);
    					
    				}
    				}
    				
    				
    				// Prints the L2 Bid Book we created. Cycles through the whole List and prints the contained objects.
    				
    				for (int idx = 0; idx < bidRows.Count; idx++){
    					//Print("Bid Price=" + bidRows[idx].Price + " Volume=" + bidRows[idx].Volume + " Position=" + idx);
    				}
            }

    #2
    By change in Dom I assume you mean Change in the market depth. Not change in the Last Trade price.
    If the indicator is set to Calculate OnEachTick . There has to be a Trade for a New Tick. There does not have to be a NewTick for the Market Depth to change. ( Level 2) So I believe you can see changes in market depth visually on the Dom in between updates in the indicator on Each Tick. I may be wrong about that but It seems to be what I have observed in running a strategy that updates on EachTick.

    Comment


      #3
      Hello stoxos,

      Welcome to the support forum.

      This is likely due to the charts refresh rate compared to the Doms refresh rate which is faster.

      The chart will update every 250ms if it needs to be updated.There is a list of items that cause a chart to Render located here: http://ninjatrader.com/support/helpG...b=forcerefresh

      The dom has a 25ms ~ 100ms rate so it is quicker at updating.

      In this case, you would likely see more detail using the dom opposed to a chart because of the refresh rate. You can know you see all the values using a Print as you have, so logically this does work as you would expect. Visually this would be delayed in contrast to the dom.

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        First of all thank you for your time!

        Hello again, yes jerrywar you are right i mean the market depth, and yes i can see volume at each price but NinjaTrader_Jesse i want to create something like those :https://futures.io/local_links.php?a...27&linkid=1833
        http://ninjatrader.com/support/forum...ad.php?t=72697

        Is there anyway to force the chart to update as fast as i need?
        Something like ChartRedraw() of mql5.


        UPDATE !!!!! I made it yeah it was ForceRefresh(); and boom everything its ok now!
        Thank you!


        P.S.
        The indicator from futures io is using something more advanced coding in order to set the volume to the text at real time or each not?
        Last edited by stoxos; 07-28-2017, 09:04 AM.

        Comment


          #5
          Hello,

          Thank you for the reply.

          I am glad that was able to give the effect you wanted.

          Regarding the other indicator, that is likely using the OnRender override. This is a more advanced plotting override that can be used for custom drawing.

          To see a sample of this, see the SampleCustomRender that comes with the platforms indicators.

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Jesse
            If Ninjatrader built this display in as a User Selectable feature in Chart Trader.
            For certain trading methodologies you would not need the Dom.
            The reason it is significant is that in the process of trading you have to translate price position on the chart to price position on the Dom. Adding in the Market depth puts most of the Dom except for Single Click operations on the Chart.

            Comment


              #7
              Originally posted by stoxos View Post
              First of all thank you for your time!

              Hello again, yes jerrywar you are right i mean the market depth, and yes i can see volume at each price but NinjaTrader_Jesse i want to create something like those :https://futures.io/local_links.php?a...27&linkid=1833
              http://ninjatrader.com/support/forum...ad.php?t=72697

              Is there anyway to force the chart to update as fast as i need?
              Something like ChartRedraw() of mql5.


              UPDATE !!!!! I made it yeah it was ForceRefresh(); and boom everything its ok now!
              Thank you!


              P.S.
              The indicator from futures io is using something more advanced coding in order to set the volume to the text at real time or each not?
              I looked at the display on Futures.io , that is a pretty neat feature.

              Comment


                #8
                Greetings,
                PROBLEM: Refresh is too slow, data is outdated, especially compared to NT DOM.
                Current Project: (This is working) I place texts of Level 2 market depth on screen…using text for each position and also adding 10 positions together for CumulativeAsk and CumulativeBid.
                MY FAILED ATTEMPTS:
                I would like to cause a ForceRefresh() after each second…as discussed in this forum thread, and I use the code from “SampleLevel2Book” to generate seemingly good data (though outdated).
                In reading:

                the process seems straight forward, however I error out when using “Core.Globals.Now”.
                Perhaps I am not placing these commands in the proper location.
                Does the “private void” and subsequent “if” statement belong inside/outside “protected override void OnBarUpdate” or inside/outside “protected override void OnMarketDepth(MarketDepthEventArgs e)”
                I need to establish a TIME comparison in order to trigger ForceRefresh().
                Currently I use Draw.Text commands after the conclusion of “OnMarketDepth”.

                Thank you in advance!

                Comment


                  #9
                  Hello,

                  In the linked example, the entirety of that sample would go outside of OnBarUpdate as OnBarUpdate is also a void method( a method cannot go inside another method). There is also a private DateTime property that is declared at class level, or where you would see the #Variables region in the script.


                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Jesse!

                    Still having some problems. Attached is the script – with several “Message to NT” within.
                    I created the separate void method; the code is identical to the example (using ForcedRefresh() ).
                    However, I am not achieving a ReFresh. Please see the script.

                    You may want to make a tiny change in the page discussing ForcedRefresh. If used as shown, there is the error:
                    “The type or namespace name ‘GlobalsNow’ does not exist in the namespace ‘NinjaTrader.Core’ “
                    What is missing is “.” Just before “Now”.

                    I am using NT8 Version 8.0.8.0.

                    Please let me know where I am making errors. Thanks, and best regards.
                    Attached Files

                    Comment


                      #11
                      Hello,

                      Thank you for the reply.

                      The reason the code in the void method is not being called is that you are not calling the method anywhere.

                      The override void methods get called automatically because of how NinjaTrader works, void methods do not get called automatically because this is an arbitrary block of code you have created.

                      You would need to call the method from somewhere to have it called, OnBarUpdate as one example:

                      Code:
                      protected override void OnBarUpdate()	 {
                      	MyCustomMethod();
                      }
                      I see that you also have other errors in the script which prevent it from running when used with OnBar Update.

                      Indicator 'AAMarketDepth': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.


                      You would need to ensure to check for enough bars before using a BarsAgo as well, look for the highest number of BarsAgo you use and append a Check to OnBarUpdate:

                      Code:
                      if(CurrentBar < 10) return;

                      Regarding the help guide, I have submitted a feature request to have the sample updated.

                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        can you share the indicator

                        can you share the indicator?

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by aa731, Today, 02:54 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post aa731
                        by aa731
                         
                        Started by thanajo, 05-04-2021, 02:11 AM
                        3 responses
                        469 views
                        0 likes
                        Last Post tradingnasdaqprueba  
                        Started by Christopher_R, Today, 12:29 AM
                        0 responses
                        10 views
                        0 likes
                        Last Post Christopher_R  
                        Started by sidlercom80, 10-28-2023, 08:49 AM
                        166 responses
                        2,237 views
                        0 likes
                        Last Post sidlercom80  
                        Started by thread, Yesterday, 11:58 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post thread
                        by thread
                         
                        Working...
                        X