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

Placing Labels Next to Each Other on a Chart

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

    Placing Labels Next to Each Other on a Chart

    Dear NT Indicator Forum,

    I'm trying to work out how to draw labels next to each other on a chart. To clarify my request, let's say I have 3 indicators on my chart - a MACD, a Stochastic and an ATR. I would like to display 3 labels on my chart: ATR(8): <ATR value> MACD: Trend Up Stoch: Trend Up

    How would I accomplish this? To display a single label, I use the Draw,TextFixed method which offers predefined locations on the chart. I did a little research and there's also Draw.Text which offers more flexibility, but I'm not sure how to use this.

    When using labels in Thinkorswim, the platform recognizes multiple labels and automatically displays them one after another (see photo attached). No additional programming required. How would I get the equivalent functionality in NT8?

    One way I can think of is to code a single indicator and embed all 3 indicators into this custom indicator, and concatenate the string value for all 3 labels - I feel that's just improper and brute-force coding. There must be a better, more elegant way to do this.

    Thanks!
    Attached Files
    Last edited by aguison; 06-19-2024, 02:45 PM.

    #2
    Hello aguison,

    Labels like that would require using Draw.TextFixed which can't offset or know about other fixed texts meaning they will overlap or using OnRender which would require using X/Y positioning. For separate indicators there would not be a good way to accomplish that because the indicators won't know what other indicators are applied and may calculate in different orders, there wouldn't be an easy way to offset the labels. A single script could accomplish this and offset all the labels it creates because it would be able to keep track of what has been drawn already. A single script can use Draw.TextFixed and make multiple vertical texts by using the newline character \n after each part you want on a new line. OnRender could be used to create what you have in the image which would offset the next rendering by X amount based on the texts width.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse. There are two OnRender methods - one is OnRender (Chartstyle) and the other is OnRender (Rendering). I assume you're talking about the second one? Do you have any sample code you can give out to get an idea of how to use it? Thanks
      Last edited by aguison; 06-20-2024, 06:09 AM.

      Comment


        #4
        Hello aguison, OnRender is the same for all types of objects so the area where you found the information in the help guide is not necessarily relevant, the concepts of rendering something to the chart would be the same and many NinjaScript types use OnRender. You can find a sample of drawing text and other items from an indicator by looking at the SampleCustomRender script that comes with NinjaTrader.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Maybe make a 'display' indicator that takes output of other indicators and renders them on the chart.

          Comment


            #6
            Thanks Mice1999 - yes, that is one way Jesse was suggesting

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DayTradingDEMON, Yesterday, 08:54 AM
            12 responses
            36 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by reekotubbs, Today, 01:09 PM
            0 responses
            8 views
            0 likes
            Last Post reekotubbs  
            Started by aligator, 06-05-2018, 01:25 AM
            60 responses
            5,917 views
            10 likes
            Last Post aligator  
            Started by tony_28217, 06-15-2024, 12:55 PM
            7 responses
            53 views
            1 like
            Last Post svikari
            by svikari
             
            Started by pvtrader, 07-01-2024, 09:02 AM
            4 responses
            84 views
            0 likes
            Last Post Sparkyboy  
            Working...
            X