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

easiest way to draw text to left of price level

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

    easiest way to draw text to left of price level

    What is the easiest way to draw text on the chart, but just left of a specific price level?

    I typically have a gap between the current bar and the y vertical label/scale. I want to put text at designated price levels. I will change the value of the text, updating it content.

    Draw fixed text will not wok as the y location is based on price, not a fixed location on the screen. And since I have a gap between the current bar and the right side, I do not think the regular drawtext method will work.

    Any suggestions of simple examples i could use?
    Last edited by tulanch; 10-15-2014, 09:18 AM.

    #2
    tulanch, I would suggest to check into the CustomPlotSample to see how a custom string is drawn using native C# method in the overriden plot.

    From the ChartControls you can get the Y value of your price level and then for example use it as coordinate in your point to draw at -

    Code:
    public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
    		{
    			double yVal = ChartControl.GetYByValue(BarsArray[0], 1867);
    			graphics.DrawString("Level", textFont, textBrush, bounds.X + bounds.Width -70, (float)yVal-5, stringFormat);
    		}
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by tulanch View Post
      What is the easiest way to draw text on the chart, but just left of a specific price level?

      I typically have a gap between the current bar and the y vertical label/scale. I want to put text at designated price levels. I will change the value of the text, updating it content.

      Draw fixed text will not wok as the y location is based on price, not a fixed location on the screen. And since I have a gap between the current bar and the right side, I do not think the regular drawtext method will work.

      Any suggestions of simple examples i could use?
      The regular DrawText() will do what you want. The attachment shows an example, drawn by these code statements.
      Code:
      DrawLine("StopLineTag", true, 1, dblYValueStop, -8, dblYValueStop, colorLineColor, DashStyle.Solid, 2);
      using (Font fontTextFont = new Font(FontFamily.GenericMonospace, 8.0f, FontStyle.Bold))
          {
              DrawText("StopTextTag", true, "StopLoss",    -8, dblYValueStop, fontTextFont.Height, colorLineColor, fontTextFont, StringAlignment.Near, Color.Empty, Color.Empty, 0);
              DrawText("StopValueTag", true, strStopValue, -8, dblYValueStop, 0, colorLineColor, fontTextFont, StringAlignment.Near, Color.Empty, Color.Empty, 0);
          }
      Of course, with values assigned to the dblYValueStop, colorLineColor and sundry other variables.
      Attached Files
      Last edited by koganam; 10-15-2014, 10:05 AM.

      Comment


        #4
        thanks both of you, the - x values working perfectly

        Comment


          #5
          I found this code extremely useful, thanks Bertrand.

          Code:
          public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
          		{
          			double yVal = ChartControl.GetYByValue(BarsArray[0], 1867);
          			graphics.DrawString("Level", textFont, textBrush, bounds.X + bounds.Width -70, (float)yVal-5, stringFormat);
          		}

          But, I need a bit more help. As for I understand, overridden Plot methods invokes not earlier, than close of primary series bar.

          I use 2 bars series: say, primary 1 Hour, and secondary 1 Tick.
          And now I need text to be updates when some condition become true on secondary 1 tick serie.

          Is that possible?

          UPD:
          koganam said here:
          There is a Plot() function that is called by default on OnBarUpdate or chart refresh.
          But, at the time, I can't find on forum how to refresh chart programmatically.

          [SOLVED]:
          Hmm.. I stared for a while and see that my graphics.DrawString() result updated, at least, at each tick (may be, even, on each MarketDebth update.

          It have sense: if custom Plot work after OnBarUpdated(), than each new bars series increase frequency of OnBarUpdated() invokes. Therefore, custom Plot invokes frequency increase too.

          Right?
          Last edited by fx.practic; 04-26-2017, 12:10 PM.
          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment


            #6
            fx.practic, it would be called whenever the chart plot values could be out of date, i.e. new bar update/tick coming in. You can try forcing in a refresh via the ChartControl.Invalidate() on your custom condition. Some also trigger this via a custom timer to have their own custom plot update interval if you want.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by koganam View Post
              The regular DrawText() will do what you want. The attachment shows an example, drawn by these code statements.
              Code:
              DrawLine("StopLineTag", true, 1, dblYValueStop, -8, dblYValueStop, colorLineColor, DashStyle.Solid, 2);
              using (Font fontTextFont = new Font(FontFamily.GenericMonospace, 8.0f, FontStyle.Bold))
                  {
                      DrawText("StopTextTag", true, "StopLoss",    -8, dblYValueStop, fontTextFont.Height, colorLineColor, fontTextFont, StringAlignment.Near, Color.Empty, Color.Empty, 0);
                      DrawText("StopValueTag", true, strStopValue, -8, dblYValueStop, 0, colorLineColor, fontTextFont, StringAlignment.Near, Color.Empty, Color.Empty, 0);
                  }
              Of course, with values assigned to the dblYValueStop, colorLineColor and sundry other variables.
              How would i do the same to use it with COBC = false and keep those drawing object in place?

              Comment


                #8
                Originally posted by outsource View Post
                How would i do the same to use it with COBC = false and keep those drawing object in place?
                I do not see how COBC value affects anything, if the values are unvarying in the bar? Why do you think that it should make a difference?

                Comment


                  #9
                  Originally posted by koganam View Post
                  I do not see how COBC value affects anything, if the values are unvarying in the bar? Why do you think that it should make a difference?
                  It does affect when hitting F5.The draw object disappear.

                  Comment


                    #10
                    Originally posted by outsource View Post
                    It does affect when hitting F5.The draw object disappear.
                    Not on my chart. Try printing out the values that you are using to draw, and see if they are valid after you hit F5. Are there any errors in your log?

                    Comment


                      #11
                      No, there are no errors in the log.

                      Comment


                        #12
                        Originally posted by outsource View Post
                        No, there are no errors in the log.
                        Then the only thing left is to print out and check that the values at which you are drawing remain valid, and have not changed to values that are being drawn outside the visible chart window.

                        Whatever your problem, it is somewhere in your code, not in that simple drawing routine.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by funk10101, Today, 12:02 AM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by GLFX005, Today, 03:23 AM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by nandhumca, Yesterday, 03:41 PM
                        1 response
                        13 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by The_Sec, Yesterday, 03:37 PM
                        1 response
                        11 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by vecnopus, Today, 06:15 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post vecnopus  
                        Working...
                        X