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

Text multiple backgrounds

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

    Text multiple backgrounds

    Hello, I would like to add text and have one of three background colors and one of two foreground colors. "Good" White text green background, "Bad" White text red background and "Ok" Black text Yellow background.
    I'd like them to line up in the upper right corner side by side like Good Ok Bad Good
    Is this possible?
    Thanks for your assistance!

    #2
    Hello morrnel,

    Thank you for the post.

    Generally using the drawing objects and the TextFixed would be easiest however if you want two texts with separate colors that would require using OnRende or two separate drawing objects. If you don;t mind using separate corners you could instead use Draw.TextFixed.


    The alternative would be to use OnRender to custom draw the text wherever you need such as the corner. You can see a sample of drawing text using OnRender in the indicator SampleCustomRender that comes with the platform.


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

    Comment


      #3
      TextFixed has predefined placement options. They are:
      TextPosition.BottomLeft
      TextPosition.BottomRight
      TextPosition.Center
      TextPosition.TopLeft
      TextPosition.TopRight

      I can display two boxes at TopLeft and TopRight

      Is TopRight + x possible?

      Comment


        #4
        Hello morrnel,

        No, that's what I had mentioned. If you wanted to use separate corners you could use Draw.TextFixed to have two separate objects. They would otherwise not be able to be used in the same corner. OnRender can be used instead if you wanted the same corner. You could re use the code for rendering the TextFixed in an indicator, the drawing tools all use OnRender to actually draw so the OnRender logic from the existing tool could be referenced for examples.

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

        Comment


          #5
          Where is NinjaTrader.Custom.Resource.SampleCustomPlotLowerR ightCorner located?

          Comment


            #6
            Hello morrnel,

            That would not be something you need to use, thats a Resource string and is used for regionalization, you would just need to use a normal String with your text there.

            "some text"

            I look forward to being of further assistance.

            JesseNinjaTrader Customer Service

            Comment


              #7
              Then why is it in the sample? SharpDX.DirectWrite.TextLayout textLayout2 =
              new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory,
              NinjaTrader.Custom.Resource.SampleCustomPlotLowerR ightCorner, textFormat2, 400, textFormat1.FontSize);

              Comment


                #8
                Hello morrnel,

                Its in the sample so that it can be regionalized, that's because it goes out to many users in different languages. That ensures the end user can read the sample when it runs to understand it.

                You don't need to do that in your code and can instead just use a string there. You would just take out NinjaTrader.Custom.Resource.SampleCustomPlotLowerR ightCorner and use a string:


                Code:
                new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory, "My text", textFormat2, 400, textFormat1.FontSize);
                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Making progress. Plowing through a lot of "Curse of Knowledge".

                  Comment


                    #10
                    Hello morrnel,
                    Just in case you can manage to display 1 text at a time then you can surely use Fixed Text with the colors as needed, or else you can still use fixed text to display all 3 texts but you need to remove background color from your requirement or else the backgrounds for all 3 texts will be overlapping, of course you can use diff text colors the trick is to use new line for 2nd & 3rd text command. Else, the only option is to have a custom text as suggested by Jesse. Hope it helps!

                    Comment


                      #11
                      Thanks, you and Jesse have offered very good advice.

                      Comment


                        #12
                        What samples other than SampleCustomRender is available? I tried the example at https://ninjatrader.com/support/help...?rendering.htm but it doesn't seem to work.

                        Comment


                          #13
                          Hello morrnel,

                          There are many existing scripts that use OnRender, all of the drawing objects do and some indicators as well. What concepts for OnRender where you looking to learn more about? If you can provide more context I can likely provide some guidance toward other samples.

                          One way to get a good idea of all the uses in the existing scripts is to use visual studio. If you click the toolbar button in the NinjaScript editor to open the visual studio solution you can do a control + shift + F or find in solution to search for "OnRender". That would give you a list of all files that use OnRender for many examples.

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

                          Comment


                            #14
                            All I want to create is something that looks like a button; a colored rectangle with text at a location on the top of the window. Multiple items with different text and color.

                            Comment


                              #15
                              Hello morrnel,

                              Thanks for the additional details.

                              Those would be concepts that are shown in the SampleCustomRender. Mainly you would be looking at drawing with the render target and drawing a rectangle. The text can also be created using the same setup as the text in that sample. Was there a part of that you wanted to go over to better understand what the sample is doing or how you may reuse part of its code?

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

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rdtdale, Today, 01:02 PM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by alifarahani, Today, 09:40 AM
                              3 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by RookieTrader, Today, 09:37 AM
                              4 responses
                              18 views
                              0 likes
                              Last Post RookieTrader  
                              Started by PaulMohn, Today, 12:36 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post PaulMohn  
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              41 views
                              0 likes
                              Last Post love2code2trade  
                              Working...
                              X