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

What idea is behind changing Color on Brushes?

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

    What idea is behind changing Color on Brushes?

    Here is NT7 code:

    Code:
    ITextFixed info_text = DrawTextFixed("info_text", "some text", TextPosition.TopLeft, Color.FromArgb( 200, 70, 70, 70), new Font("Arial Narrow", 14, FontStyle.Bold), Color.FromArgb( 255, 000, 000, 000), Color.FromArgb( 100, 100, 100, 255), 1);
    And here is same NT8 code:
    Code:
    SolidColorBrush unnesessary_text_brush = new SolidColorBrush( Color.FromArgb( 100, 000, 000, 000));
    unnesessary_text_brush.Freeze();
    SolidColorBrush unnesessary_outline_brush = new SolidColorBrush( Color.FromArgb( 255, 000, 000, 000));
    unnesessary_outline_brush.Freeze();
    SolidColorBrush unnesessary_area_brush = new SolidColorBrush( Color.FromArgb( 100, 100, 100, 255));
    unnesessary_area_brush.Freeze();				
    NinjaTrader.Gui.Tools.SimpleFont unnesessary_font  = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 50, Bold = true };
    TextFixed info_text = Draw.TextFixed(this, "Info_Text", "some text, TextPosition.TopLeft, unnesessary_text_brush, unnesessary_font, unnesessary_outline_brush, unnesessary_area_brush, 1);
    Just want to know - what's the idea behind such changes in NT8 NinjaScript?
    May be there is more compact way to put fixed text on chart?

    At the time I see only one way out: to create add-on and to encapsulate all this code in static methods with short names.
    Last edited by fx.practic; 03-03-2017, 12:11 PM.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    Thank you for your questions fx.practic. This change was a side effect of using DirectX and WPF to power NT8. While this does add some coding overhead, as you have pointed out, this has dramatically improved NT8 over NT7's use of WinForms technology.

    This said, there are ways to take this code on multiple lines and create a long single line of the type you posted for your NT7 code. I would recommend using the BrushConverter class. This is documented at this publicly available link,



    You can create a brush from a hex value as follows

    Code:
    [FONT=Courier New](SolidColorBrush)(new BrushConverter().ConvertFrom("#abcdef"));[/FONT]
    Further, there is no preparation or clean-up of the SimpleFont, as shown in this HelpGuide page,



    Therefore, this, too, can be constructed in a manner similar to the NT7 font you created.

    Combining these two pieces of advice leaves you with a single long line of code in both NT7 and NT8. Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thanks a lot. Jessica!
      I just can't imagine logical way to find this by myself.

      This long line compiled and works fine:
      Code:
      TextFixed info_text = Draw.TextFixed(this, "Info_Text", "info text", TextPosition.TopLeft, (SolidColorBrush)(new BrushConverter().ConvertFrom("#ff808080")), new NinjaTrader.Gui.Tools.SimpleFont("Arial Narrow", 14) { Bold = true },  (SolidColorBrush)(new BrushConverter().ConvertFrom("#00000000")),  (SolidColorBrush)(new BrushConverter().ConvertFrom("#00000000")), 10);
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mestor, 03-10-2023, 01:50 AM
      16 responses
      389 views
      0 likes
      Last Post z.franck  
      Started by rtwave, 04-12-2024, 09:30 AM
      4 responses
      31 views
      0 likes
      Last Post rtwave
      by rtwave
       
      Started by yertle, Yesterday, 08:38 AM
      7 responses
      29 views
      0 likes
      Last Post yertle
      by yertle
       
      Started by bmartz, 03-12-2024, 06:12 AM
      2 responses
      23 views
      0 likes
      Last Post bmartz
      by bmartz
       
      Started by funk10101, Today, 12:02 AM
      0 responses
      7 views
      0 likes
      Last Post funk10101  
      Working...
      X