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

    How to Draw Line in OnMarketDepth

    How do I draw a line from the last (rightmost) bar back X bars in OnMarketDepth, using DrawRay preferably? It is throwing exceptions saying:

    DrawRay: anchor1BarsAgo out of valid range 0 through -1, was 10.

    or can this be done?

    #2
    Hello MSEtrader,

    It is possible to Draw object inside of the OnMarketDepth, although the object maybe drawn multiple times within a Bar.

    How are you calling DrawRay?

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      DrawRay("AL", true, 10, askPrice, 0, askPrice, Color.Red, DashStyle.Dash,1);

      The intent is to draw a dashed line from the last bar back 10 bars at the ask price. I'm checking for a valid ask price before executing this.

      Comment


        #4
        Hello MSEtrader,

        That should work. You may want to check to make sure that you have enough bars of data before trying to draw the object.

        Also, to prevent your DrawRay from being drawn everytime OnMarketDepth() is called you may want to move the DrawRay into OnBarUpdate().

        Let us know if the issue persists.
        JCNinjaTrader Customer Service

        Comment


          #5
          Error on calling 'OnMarketDepth' method for indicator 'TrackBidAsk': TrackBidAsk.DrawRay: anchor1BarsAgo out of valid range 0 through -1, was 10.

          The code is:

          if (Bars.Count > 100) {

          if (askPrice != 0) {
          //Print("ASK=" + askPrice.ToString());
          DrawRay("Ask", true,lineLength, askPrice, 0, askPrice, alColor, lineStyle,lineWidth);
          }
          if (bidPrice != 0) {
          //Print("BID=" + bidPrice.ToString());
          DrawRay("Bid", true,lineLength, bidPrice, 0, bidPrice, blColor, lineStyle,lineWidth);
          }
          }

          Is there a better way to check for sufficient bars? I really just want to update on every depth change on the last bar.

          Comment


            #6
            I think I understand the problem with multple updates -- does NT redraw the chart when it updates a tick? Otherwise how could indicators that redraw on every tick erase stale objects. So for my scheme to work I would have to force a redraw on every market depth event?

            Comment


              #7
              Sorry to keep second-guessing myself -- it looks like I can use the object tag and RemoveDrawObject to keep the chart up to date with only the last levels.

              Comment


                #8
                Hello MSEtrader,

                You would check to make sure that you have enough bars by using something like "if ( CurrentBar < 20 )".



                Yes, NinjaTrader will redraw the object with each incoming tick of data as it is coming in from the OnMarketDepth(). With the "tag" name being the same name you will not have to remove it as it will be moved to the current location. If that is how you want your indicator to be processed then you may keep it that way.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Getting there -- it s working partway. I added this code:

                  protectedoverridevoid OnMarketDepth(MarketDepthEventArgs e)
                  {

                  Print(
                  "CurrentBar = " + CurrentBar.ToString());

                  if (CurrentBar < 50)
                  return;

                  I am seeing "CurrentBar = -1" quite a bit. What does this mean?

                  Comment


                    #10
                    Originally posted by MSEtrader View Post
                    Error on calling 'OnMarketDepth' method for indicator 'TrackBidAsk': TrackBidAsk.DrawRay: anchor1BarsAgo out of valid range 0 through -1, was 10.

                    The code is:

                    if (Bars.Count > 100) {

                    if (askPrice != 0) {
                    //Print("ASK=" + askPrice.ToString());
                    DrawRay("Ask", true,lineLength, askPrice, 0, askPrice, alColor, lineStyle,lineWidth);
                    }
                    if (bidPrice != 0) {
                    //Print("BID=" + bidPrice.ToString());
                    DrawRay("Bid", true,lineLength, bidPrice, 0, bidPrice, blColor, lineStyle,lineWidth);
                    }
                    }

                    Is there a better way to check for sufficient bars? I really just want to update on every depth change on the last bar.
                    You just need to ensure that you have sufficient bars to draw to. Refer to this post, which is essentially the same issue. http://www.ninjatrader.com/support/f...37&postcount=8

                    Comment


                      #11
                      Thanks K and N_JC. It is working but with this strange issue -- the indicator lines (DrawRay) do not update. If I click on the chart they do update -- they just don't update on the chart when DrawRay is called. I tried calling Update() after DrawRay, no luck. Is there a way to force the update?

                      Comment


                        #12
                        Hello MSEtrader,

                        You will need incoming Data for OnMarketDepth() or OnBarUpdate() to be called to drive your NinjaScript code to be processed. Please note that you may use the Simulated Data Feed for testing purposes if you like.

                        Download NinjaTrader FREE at http://www.ninjatrader.comThis video demonstrates understanding and working with the Simulated Data Feed with NinjaTrader 7. Nin...
                        JCNinjaTrader Customer Service

                        Comment


                          #13
                          I am testing with live data (MB Trading live connection, Kinetick history). I definitely get L2 for the futures I am testing with (E7 and NQ so far).

                          Comment


                            #14
                            Let me clarify -- the purpose of this indicator is to see the market on very thin futures or stocks where the bid/ask can move significantly away from the last tick -- so you might be sitting on a profit or loss and not kjnow it. Some of these instruments can go for some time without trading even when the quotes are liquid and moving.

                            Basically the indicator will draw lines where the ChartTrader A/B levels are, in real time.

                            I am filtering to only display the new lines when the best bid or ask size changes, so most OnMarketDepth events are ignored.

                            As it is now, the lines do update, but just not on every depth event (possibly on every tick), so the indicator is not very useful. I plan to post this one when/if it is working.

                            Comment


                              #15
                              Originally posted by MSEtrader View Post
                              Let me clarify -- the purpose of this indicator is to see the market on very thin futures or stocks where the bid/ask can move significantly away from the last tick -- so you might be sitting on a profit or loss and not kjnow it. Some of these instruments can go for some time without trading even when the quotes are liquid and moving.

                              Basically the indicator will draw lines where the ChartTrader A/B levels are, in real time.

                              I am filtering to only display the new lines when the best bid or ask size changes, so most OnMarketDepth events are ignored.

                              As it is now, the lines do update, but just not on every depth event (possibly on every tick), so the indicator is not very useful. I plan to post this one when/if it is working.
                              1. Why then are you not more simply using OnMarketData()?
                              2. You might have to provide the entire syntax with which you are calling OnMarketDepth(), rather than the skeleton that you posted. It seems to me that you may not be calling with a fine enough syntax.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by carnitron, 04-27-2024, 08:42 PM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by WHICKED, 04-26-2024, 12:56 PM
                              3 responses
                              24 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by zstheorist, 04-26-2024, 07:52 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by Touch-Ups, 04-27-2024, 10:36 AM
                              2 responses
                              21 views
                              0 likes
                              Last Post Touch-Ups  
                              Started by needsomehelp147, Today, 06:43 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post needsomehelp147  
                              Working...
                              X