Draw.TextFixed and spaces

When using Draw.TextFixed, is the application purposely removing any added spaces to the string? this doesn’t work. Is there any other way to add spaces at the beginning or end of the string here?

Draw.TextFixed(this, mytag, " " + MyString + " ", TextPosition.BottomRight)

@several Someone may have a much simpler answer than mine, but here are two options if nobody else responds with a simpler answer.

If the NinjaScript framework is stripping the ’ ’ character specifically, you could try one of the many other Unicode whitespace characters instead of the ’ ’ character.

If the NinjaScript framework strips all Unicode whitespace characters, you could still accomplish the same visual effect by adding a Windows Presentation Foundation (WPF) Label control to the NinjaScript indicator’s (or strategy’s) “ChartControl” at the same location of the ChartControl you mentioned (BottomRight), and provide the desired number of device-independent pixels to the Label control’s left and/or right margin or padding. That would be a lot more work however, but it would definitely work on NinjaTrader charts that have a “ChartControl”, i.e. live charts and charts in Market Replay, but not Strategy Analyzer back-test charts.

1 Like

I think the easiest way would be to use a fixed font like Consolas as opposed to other scalable fonts. This is especially useful if you have a multi-line string with fields that need to line up together - like decimal points, right or left justified, etc. Scalable fonts will squeeze the text differently depending on the characters in the string.

The Draw.TextFixed() documentation explains how you can print using a specific font.

https://ninjatrader.com/support/helpGuides/nt8/draw_textfixed.htm

Hope this helps

You Might Try This:

string myString = " " + MyString + " ";
Draw.TextFixed(this, mytag, myString, TextPosition.BottomRight);

Be Safe in this Crazy World!
:smiling_face_with_sunglasses:

Thanks but doesn’t work at all, the spaces are ignored.

Try surrounding your text with Unicode NULL characters.

var st = “\u0000” + " testing " + “\u0000”;
Draw.TextFixed(this, “testingfixed”, st, TextPosition.Center, Brushes.Red, yourFont, Brushes.Green, Brushes.Blue, 100);

Cheers!

1 Like

Thanks but sadly also does not work. NinjaTrader must be removing it.

Works for me using the code I posted and using NT version 8.1.3.1 64-bit.

BTW my font statement uses Arial as follows:
yourFont = new Gui.Tools.SimpleFont(“Arial”, 18);

Good Luck!

I used your code:

{
	public class FontSpaceTest : Indicator
	{
		
		private string mystring;
		private NinjaTrader.Gui.Tools.SimpleFont yourFont;

		protected override void OnStateChange()
		{
			if (State == State.SetDefaults)
			{
				Description									= @"Enter the description for your new custom Indicator here.";
				Name										= "FontSpaceTest";
				Calculate									= Calculate.OnBarClose;
				IsOverlay									= false;
				DisplayInDataBox							= true;
				DrawOnPricePanel							= true;
				DrawHorizontalGridLines						= true;
				DrawVerticalGridLines						= true;
				PaintPriceMarkers							= true;
				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
				//See Help Guide for additional information.
				IsSuspendedWhileInactive					= true;
				mystring = "\u0000" + "\u0000" + "\u0000" + "\u0000" + " testing " + "\u0000" + "\u0000" + "\u0000" + "\u0000" +  "\u0000";
			}
			else if (State == State.DataLoaded)
			{
				yourFont = new Gui.Tools.SimpleFont("Arial", 18);
			}
		}

		protected override void OnBarUpdate()
		{
			//Add your custom indicator logic here.
			
			Draw.TextFixed(this, "tag", mystring, TextPosition.TopLeft, Brushes.Red, yourFont, Brushes.Green, Brushes.Blue, 100);
		}
	}
}

Produces this result 8.1.4.2 64-bi

[quote=“several, post:9, topic:2390”]

Sorry I can’t figure out how to post code in a box that maintains the exact formatting (like the code you posted). The leading/trailing spaces in the sample code I posted is being truncating, just like what NT is doing to your code.

Don’t use multiple “\u0000” entries…instead put the desired spaces in the " testing " string, surrounded by a single pair of “\u0000” entries. I believe the pic you posted does have the leading/trailing spaces that are in your code…just add more spaces within the quotes.

1 Like

Fantastic, thanks a lot!

String text = “ Whatever your text is. “ Theres no need to create another set of quotes for your spaces… place the first quotation add spaces write your text add more spaces the close your quote”

Hello, thanks but that’s not the case and was the whole point of the post. See;

The solution mentioned is the only way I managed to fix it. Like this:

1 Like

1 Like

1 Like

You are using Draw.Text

My post refers to Draw.TextFixed. Text that is aligned to the edges of the window, not Text attached to Bars.

1 Like