Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

graphics.DrawString multiple objects

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

    graphics.DrawString multiple objects

    Hi,

    I have been trying to get an understanding of the public override void Plot method and after searching the forum for posts on the topic and using various indicators including the pivots.cs indicator as a guide.

    I would like to find out how I can get the following code to plot at each bid price level. I want it to draw each time it visits a price level, not be removed and placed at the current level as it is with the code below. Do I need a 'tag' or similar? Is there a reference as to how I can achieve this?

    Code:
    graphics.DrawString("Right Hand Side"+bidPrice, textFont, textBrush, bounds.X + 1000, ChartControl.GetYByValue(this,bidPrice), stringFormat);
    Regards,
    suprsnipes.

    #2
    Hello,

    Thank you for the post.

    To draw at each level, you would need to create your own logic that accomplishes that.

    The graphics.DrawString will render only what is supplied in that single line of code once per render at the specified location. If you wanted 10 strings, you would need 10 lines of code drawing at those values with those 10 strings.

    To be more efficient you could potentially use for loops to draw X number of lines at X prices, but again this would depend on the logic you write.

    Here is a simple example of a for loop, you could use something similar to the following to iterate X number of times. This may or may not be useful for what you are trying and is simply to demonstrate drawing multiple texts.

    Code:
    for(int i = 0; i < 10; i++)
    {
       graphics.DrawString("Text# " + i, textFont, textBrush, bounds.X + 1000, ChartControl.GetYByValue(this,bidPrice + i), stringFormat);
    }
    I look forward to being of further assistance.

    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks for your suggestion. After using the loop suggested I found the following whilst it did plot at multiple levels it is not quite what I am after. I have spent the day on the forum trying to find similar queries without much progress.

      How can I use a for loop to achieve a graphics plot at each price level?

      I have attempted to use the code from the VolumeProfile indicator shipped with NinjaTrader using custom variables. Whilst it works as it does in the original indicator my main goal is to use DrawString to simply show a numerical value at each price level which is to be updated each time price visits the same Y coordinate.

      The issue I am having is the same as my previous forum post where I don't quite have the programming skills to understand exactly how I can create a 'tag' for each price level and would appreciate any guidance.

      Regards,
      suprsnipes
      Last edited by suprsnipes; 09-21-2016, 06:14 AM.

      Comment


        #4
        Hello,

        Thank you for the reply.

        Because you are using the Plot override, you can forget any concept of "Tags" you know from the DrawingObjects. DrawingObjects use a tagging system to know if a new object is needed or to use the existing object, in the plot override there are no Tags or Objects but only what you program to render.

        As for price levels, do you mean at each TickSize interval, for example on the ES every 0.25? Or at the Even price levels with no remainder?

        The for loop can be made to iterate how you need it to, for example you can do 10 iterations of X tick size to achieve a loop at each TickSize

        Code:
        for([COLOR="SeaGreen"]double i = Close[0];[/COLOR] [COLOR="purple"]i < [B]Close[0] + 10 * TickSize[/B][/COLOR]; [COLOR="darkorange"]i += [B]1 * TickSize[/B][/COLOR][B][/B])
        {
        	Print(i);
        }
        This would start at the Current close, if the Current i value is less than the Current Close plus 10 ticks, we add 1 tick to i and continue.

        It would really just depend on what Price level you want to set it at, and would need to configure the Loop to do a dynamic loop over X price levels. The counter part to this would be to write out one line for every price level you want to see. Remember there is no Tag, so 1 syntax line to Draw is needed for each level you want to see. The for loop makes this dynamic instead of having X number of lines of levels pre made.

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by fingers, 10-12-2024, 06:01 AM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by mtamaku, 10-12-2024, 09:44 AM
        1 response
        21 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by alchippe441, Today, 07:19 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by gig618, Yesterday, 10:34 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by several, 08-27-2024, 03:10 PM
        3 responses
        24 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Working...
        X