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

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(double i = Close[0]; i < Close[0] + 10 * TickSize; i += 1 * TickSize)
        {
        	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 buytrueketo, Today, 02:14 AM
        0 responses
        8 views
        0 likes
        Last Post buytrueketo  
        Started by buytrueketo, Today, 02:13 AM
        0 responses
        8 views
        0 likes
        Last Post buytrueketo  
        Started by parkinsonbr, Today, 02:04 AM
        0 responses
        13 views
        0 likes
        Last Post parkinsonbr  
        Started by trueketo, Today, 01:00 AM
        0 responses
        14 views
        0 likes
        Last Post trueketo  
        Started by trueketo, Today, 12:59 AM
        0 responses
        16 views
        0 likes
        Last Post trueketo  
        Working...
        X