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

Help to fix coding error Cannot Convert String to NijaTrader.Gui.Tools.Simplefont

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

    Help to fix coding error Cannot Convert String to NijaTrader.Gui.Tools.Simplefont

    I am a newbie coding C# and/or NinjaScript.

    Looking for some other codes and reading some documentation I tried to assemble the code attached but I am not able to get what I aimed for:

    1. I want these variables to be accessible to end users to define values as it can be done with other indicators when adding them to a chart
    • ShowBullish (bool)
    • ShowBearish (bool)
    • ShowStrong (bool)
    • ShowNeutral (bool)
    • ShowWeak (bool)
    • TextColor (brush)
    • TextSize (int)
    • TextOffset (int)
    • TextFont (string)

    2. Depending on the selection done for the boolean variables listed before, I pretend this code to print above the candles the text "SB", "NB" or "WB" (text characteristics defined by the "Text..." variables listed before) in case of:
    • "SB" if the close of the candle is in the highest third of the candle range (for bulling candle) or in the lowest third of the candle range (for bearish candle)
    • "NB" if the close of the candle is in the middle third of the candle range
    • "WB" if the close of the candle is in the lowest third of the candle range (for bulling candle) or in the upper highest of the candle range(for bearish candle)
    When compiling the code I got error messages pointing to Draw.Text lines.

    I appreciate any help in fixing these errors.

    Thank you


    Code: BarThirds.cs
    Attached Files
    Last edited by rafo05; 07-27-2022, 05:36 PM.

    #2
    Hello rafo05,

    Thanks for your post.

    I see in the script that you shared that you do not have a SimpleFont object created to use for the Draw.Text() method.

    To draw text on a chart with a customized font, you would need to create and pass in a 'SimpleFont font' argument as seen in the Draw.Text() syntax in the help guide page.

    Draw.Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, int barsAgo, double y, int yPixelOffset, Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity)

    See this help guide page for more information about using Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm

    See this help guide page for more information about SimpleFont and sample code: https://ninjatrader.com/support/help...font_class.htm

    Let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello rafo05,

      Thanks for your post.

      I see in the script that you shared that you do not have a SimpleFont object created to use for the Draw.Text() method.

      To draw text on a chart with a customized font, you would need to create and pass in a 'SimpleFont font' argument as seen in the Draw.Text() syntax in the help guide page.

      Draw.Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, int barsAgo, double y, int yPixelOffset, Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity)

      See this help guide page for more information about using Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm

      See this help guide page for more information about SimpleFont and sample code: https://ninjatrader.com/support/help...font_class.htm

      Let me know if I may assist further.
      Hi NinjaTrader_BrandonH

      Thank you for your reply.

      I assume if I had C# experience this hint "you do not have a SimpleFont object created to use for the Draw.Text() method. To draw text on a chart with a customized font, you would need to create and pass in a 'SimpleFont font' argument as seen in the Draw.Text() syntax in the help guide page" would had been valuable.

      Before I asked for help in the forum I had read the links you shared and those were too generic.

      Finally, I got direct-to-the-point help from aBarTimer.cs in https://ninjatrader.com/support/foru...ize-of-my-font.

      This is how I got what I needed

      Code:
      [FONT=Courier New][COLOR=black]if (State == State.SetDefaults)[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]{[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]Description = @"Indicator that...";[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]Name = "IndicatorName";[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]:[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]:[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]TextFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 14);[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]:[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]}[/COLOR][/FONT]
      
      
      
      [FONT=Courier New][COLOR=black]#region Properties[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]:[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]:[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]:[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black][Display(ResourceType = typeof(Custom.Resource), Name = "TextFont", Description = "Default setting for Text Font", Order=6, GroupName="Parameters")][/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]public NinjaTrader.Gui.Tools.SimpleFont TextFont[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]{ get; set; }[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]:[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]:[/COLOR][/FONT]
      [FONT=Courier New][COLOR=black]#endregion[/COLOR][/FONT]

      Comment


        #4
        Hello rafo05,

        Thanks for your note.

        I am happy to hear you got the issue resolved.

        If you ever need to reference sample code to see how to create a SimpleFont and use it with Draw.Text, you could view the SimpleFont help guide page linked in post #2.

        From the help guide:

        Code:
        // create custom Courier New, make it big and bold
        NinjaTrader.Gui.Tools.SimpleFont [B]myFont[/B] = new Ninj aTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 50, Bold = true };
        
        Draw.Text(this, "myTag", false, "Hi There!", 0, Low[0], 5, Brushes.Blue,[B] myFont[/B], TextAlignment.Center, B rushes.Black, null, 1);
        Let me know if I may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        6 responses
        3,290 views
        1 like
        Last Post jgualdronc  
        Started by Touch-Ups, Today, 10:36 AM
        0 responses
        9 views
        0 likes
        Last Post Touch-Ups  
        Started by geddyisodin, 04-25-2024, 05:20 AM
        11 responses
        62 views
        0 likes
        Last Post halgo_boulder  
        Started by Option Whisperer, Today, 09:55 AM
        0 responses
        8 views
        0 likes
        Last Post Option Whisperer  
        Started by halgo_boulder, 04-20-2024, 08:44 AM
        2 responses
        25 views
        0 likes
        Last Post halgo_boulder  
        Working...
        X