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

How to Draw Line in OnMarketDepth

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

    #16
    1. As I understand it, OnMarketData only updates on every tick. I want to update the indicator on every best bid or ask price or volume change (my earlier statement on this may have been misleading), There is already an indicator floating around called ShowBidAsk that works well and udpates on OnMarketData-




    2. I think the code is ok -- I come from a software background and worked on trading floors and in other environments for many -- ahem, some time. I will post the indicator at some point.

    Comment


      #17
      For your perusal

      I have attached the indicator, called "TrackBidAsk". It is not ready for prime time, but won't ever be if it is not possible to update the chart in real time on OnMarketDepth() events. The "Update()" calls that I have commented do not seem to make any difference.

      On slow markets like E7 or QM the indicator does update, but seems to only update on tick (or OnMarketData()) events. I need it to update on every DrawRay(...).
      Attached Files

      Comment


        #18
        Originally posted by MSEtrader View Post
        1. As I understand it, OnMarketData only updates on every tick. I want to update the indicator on every best bid or ask price or volume change (my earlier statement on this may have been misleading), There is already an indicator floating around called ShowBidAsk that works well and udpates on OnMarketData-




        2. I think the code is ok -- I come from a software background and worked on trading floors and in other environments for many -- ahem, some time. I will post the indicator at some point.
        Oh well, if you insist. I do not really care to see the indicator; I just wanted to cross-check your syntax on the OnMarketDepth() call alone.

        I have found that for me, when I cannot get something simple working, another pair of eyes have often proven invaluable, usually because I end up finding that I have overlooked something and that I keep reading my own code to be what I think that I wrote rather than what I wrote.

        If you change your mind ...

        Comment


          #19
          I have uploaded the code in a previous post ...

          Comment


            #20
            Originally posted by MSEtrader View Post
            I have attached the indicator, called "TrackBidAsk". It is not ready for prime time, but won't ever be if it is not possible to update the chart in real time on OnMarketDepth() events. The "Update()" calls that I have commented do not seem to make any difference.

            On slow markets like E7 or QM the indicator does update, but seems to only update on tick (or OnMarketData()) events. I need it to update on every DrawRay(...).
            You are not filtering for the action that you are wanting to trap. Try this as your filter:

            Code:
            if (e.MarketDataType == MarketDataType.Ask [COLOR=blue][B]&& e.Operation == Operation.Update[/B][/COLOR])
            et.c.,

            Though, on reading your code, you are only asking for Ask[0], which is the inside Ask, the same that is returned by OnMarketData(). If you were querying any other level on the depth ladder, that would be a different matter.
            Last edited by koganam; 02-12-2013, 06:17 PM.

            Comment


              #21
              K - Thanks for your attention on this. Actually, I had to add this to get all of the B/A changes:

              (e.Operation == Operation.Update || e.Operation == Operation.Insert)

              Without understanding the nuances of e.Operation, it does get the changes.

              The reason this is in OnMarketDepth is not just to get the Bid[0] and Ask[0] data points -- it is to get every change in those points even between trades. If I understand NT 's event structure correctly, these two data points can change many times (theoretically infinitely many times) while a tick (trade) never comes in on OnMarketData().

              I will also want to look at Bid/Ask [1] and maybe higher at some point.

              But I'm going to back off on this for now, other things to do. Thanks again.

              Comment


                #22
                koganam - after studying OnMarketData(), I understood what you meant with your item (1) -- indeed you can get the best bid and ask in OnMarketData, a little more simply than in OnMarketDepth().

                Unfortunately, drawing on the chart from OnMarketData() behaves the same as drawing from OnMarketDepth -- it seems there must be something in MT's event model that causes the screen to update only when a trade comes in, so I can draw many different lines between trades but I only see that last one that I drew before the trade. Not sure that is what is going on though.

                NinjaTrader_JC, could you possibly clarify this?

                Comment


                  #23
                  Originally posted by MSEtrader View Post
                  koganam - after studying OnMarketData(), I understood what you meant with your item (1) -- indeed you can get the best bid and ask in OnMarketData, a little more simply than in OnMarketDepth().

                  Unfortunately, drawing on the chart from OnMarketData() behaves the same as drawing from OnMarketDepth -- it seems there must be something in MT's event model that causes the screen to update only when a trade comes in, so I can draw many different lines between trades but I only see that last one that I drew before the trade. Not sure that is what is going on though.

                  NinjaTrader_JC, could you possibly clarify this?
                  Are you expecting to see multiple lines?

                  What you have coded will show only one line for each of the Bid and Ask; the line drawn at the last update.

                  Comment


                    #24
                    Hello MSEtrader,

                    I am not quite sure what you are expecting, but in NinjaTrader you may use a Drawing object inside of Market Depth and inside OnMarketDepth will be called on eaching incoming Market Depth data.

                    Viewing the code you are using now it is drawing one ray for the ask and one ray for the bid. Are you expecting different results?
                    JCNinjaTrader Customer Service

                    Comment


                      #25
                      I'll try to explain with a scenario that describes what I see and what I am trying for (for bids only to keep it simple). I only expect to see a single bid ray (or ask ray) at any time.

                      1. A trade comes in at 1.3456 -- the price bar shows a last price (close) at 1.3456
                      2. A bid quote comes in at 1.3444 -- I call DrawRay for a "BidLine" ray at 1.3444 -- it does not show up on the chart
                      3. Another bid quote comes in at 1.3445 -- I call DrawRay for a "BidLine" ray at 1.3445 -- it does not show up up the chart
                      4. Another bid quote comes in at 1.3442 -- I call DrawRay for a "BidLine" ray at 1.3442 -- it does not show up on the chart
                      5. A trade comes in at 1.3445 (say it was at the ask, which is not relevant to this) - I now see the "BidLine" ray I drew in step (4) at 1.3442

                      I never see the rays that I drew in steps (2) and (3). That is the problem -- I want to see every ray show up on the chart when I call DrawRay(). Steps (2,3,4) could go on 10 or 20 or any number of times before the next trade price event comes in.

                      I have discovered that if I position the mouse pointer in a blank area of the chart and click it steadily, I will see the most recent bid/ask ray as soon as DrawRay is called even though a trade has not come in. Obviously this is not a solution but it indicates something about how NT handles chart updates (not sure what it means though).

                      Here is how it should look -- for an instrument where the quotes are changing rapidly you would see the bid/ask lines moving around almost continuously even if there were no trades. But you would only ever see one bid line and one ask line at at time, maybe just for a split second before you see the next one.

                      Again this indicator would really be more useful for instruments that are thinly traded where quotes don't change so rapidly.

                      Comment


                        #26
                        I thought of a simple example -- what I am going for is very like the Level II window, drawing the horizontal bars (rays) for Bid[0] and Ask[0] on the chart at the price level -- the rays on the chart should change exactly in sync with the ones in the Level II window.

                        Comment


                          #27
                          Originally posted by MSEtrader View Post
                          I'll try to explain with a scenario that describes what I see and what I am trying for (for bids only to keep it simple). I only expect to see a single bid ray (or ask ray) at any time.

                          1. A trade comes in at 1.3456 -- the price bar shows a last price (close) at 1.3456
                          2. A bid quote comes in at 1.3444 -- I call DrawRay for a "BidLine" ray at 1.3444 -- it does not show up on the chart
                          3. Another bid quote comes in at 1.3445 -- I call DrawRay for a "BidLine" ray at 1.3445 -- it does not show up up the chart
                          4. Another bid quote comes in at 1.3442 -- I call DrawRay for a "BidLine" ray at 1.3442 -- it does not show up on the chart
                          5. A trade comes in at 1.3445 (say it was at the ask, which is not relevant to this) - I now see the "BidLine" ray I drew in step (4) at 1.3442

                          I never see the rays that I drew in steps (2) and (3). That is the problem -- I want to see every ray show up on the chart when I call DrawRay(). Steps (2,3,4) could go on 10 or 20 or any number of times before the next trade price event comes in.

                          I have discovered that if I position the mouse pointer in a blank area of the chart and click it steadily, I will see the most recent bid/ask ray as soon as DrawRay is called even though a trade has not come in. Obviously this is not a solution but it indicates something about how NT handles chart updates (not sure what it means though).

                          Here is how it should look -- for an instrument where the quotes are changing rapidly you would see the bid/ask lines moving around almost continuously even if there were no trades. But you would only ever see one bid line and one ask line at at time, maybe just for a split second before you see the next one.

                          Again this indicator would really be more useful for instruments that are thinly traded where quotes don't change so rapidly.
                          I thought that that was what you were trying to achieve. We must look at things as they are though, not as we think that they should be.

                          You are drawing at the Bid (talking of one side only). The market depth size at the Bid can change without the Bid price changing, so in that case, the line will be drawn in the same place.

                          If you want to be absolutely certain that the code is being reached on each change, you may want to Print() to the Output Window, the Bid value and Time and Volume, to see that despite the changes, the line will not draw anywhere else because while the sizes may be changing, the Bid may not. Alternatively, write code to actually draw the line at a different place on every update, just so as to confirm that the line is in fact being drawn on each update.

                          Comment


                            #28
                            koganam -

                            I'm aware of the size change item -- you may note that the code I uploaded has a little algorithm to adjust the length of the bid/ask lines based on the ratio of the bid/ask size. It is not quite right but allows you to see line length changes on most events when the price levels don't change. I have imporoved this further since the upload.

                            I agree that a serious debugging investigation is warranted, using Print and so on. I don't know when I'll get around to it as active market hours are for something else. Maybe one night.

                            Thanks

                            Comment


                              #29
                              Originally posted by MSEtrader View Post
                              koganam -

                              I'm aware of the size change item -- you may note that the code I uploaded has a little algorithm to adjust the length of the bid/ask lines based on the ratio of the bid/ask size. It is not quite right but allows you to see line length changes on most events when the price levels don't change. I have imporoved this further since the upload.

                              I agree that a serious debugging investigation is warranted, using Print and so on. I don't know when I'll get around to it as active market hours are for something else. Maybe one night.

                              Thanks

                              OKAY - I'm going on some theory and stuff I think I've read or at least remember...

                              I've read here before about NT chart updates being every 50 ms minimum or something (or at least chart trader is)... you can't have more...

                              DOM i think takes priority.. hence why the chart and or chart trader can appear to be out of sync or a step or 2 behind.

                              How fast is your system? The CPU has to be going crazy over your code if an older machine. My dual cores would probably melt down

                              Please remember, there are minimum specs that NT tries to adhere too, and you might be hitting limit imposed on chart updates, etc...

                              If you have a fast machine, you could possibly delve into ChartControl, and manually calling a refresh.... which may or may not work... I'm not an expert in that....

                              Comment


                                #30
                                Sledge - ChartControl.Refresh() does it! Thanks very much. After some refinement I'll post the indicator for those who can use it, here and at Big Mike's. I have definitely benefited from other people's work so need to give back a little ...

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by cre8able, Today, 03:20 PM
                                0 responses
                                5 views
                                0 likes
                                Last Post cre8able  
                                Started by Fran888, 02-16-2024, 10:48 AM
                                3 responses
                                47 views
                                0 likes
                                Last Post Sam2515
                                by Sam2515
                                 
                                Started by martin70, 03-24-2023, 04:58 AM
                                15 responses
                                114 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Started by The_Sec, Today, 02:29 PM
                                1 response
                                8 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Started by jeronymite, 04-12-2024, 04:26 PM
                                2 responses
                                32 views
                                0 likes
                                Last Post NinjaTrader_BrandonH  
                                Working...
                                X