Ninja script question - Text Placement on Chart - futures io
futures io



Ninja script question - Text Placement on Chart


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one markbb10 with 9 posts (1 thanks)
    2. looks_two sg72 with 4 posts (4 thanks)
    3. looks_3 Stevea94 with 2 posts (1 thanks)
    4. looks_4 utilizator with 1 posts (1 thanks)
      Best Posters
    1. looks_one sg72 with 1 thanks per post
    2. looks_two Epistemophilic with 1 thanks per post
    3. looks_3 Stevea94 with 0.5 thanks per post
    4. looks_4 markbb10 with 0.1 thanks per post
    1. trending_up 2,515 views
    2. thumb_up 9 thanks given
    3. group 8 followers
    1. forum 19 posts
    2. attach_file 2 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Ninja script question - Text Placement on Chart

(login for full post details)
  #1 (permalink)
 markbb10 
Morristown NJ USA
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
 
Posts: 101 since Aug 2012
Thanks: 41 given, 42 received

Hello All,

First I am not a programmer but I have been learning and doing OK on that path.

I have written a script that does some correlation work of several other indicators and I want to
print out various output of that correlation on the chart, or in a table or in the MA.

I just want a list of the five outputs that are basically just a red or green long, short indication.

Currently I am using the Draw.TextFixed() call but this limits me to the four corners of the chart
for placement of the text.

What would I use to place the output in a list at some predefined area of the chart

Output one - Long
Output two - Short
Output three - Long

etc.


As always thanks for the input.

Mark

Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
need help writing easylanguage radarscreen weekly perfor …
EasyLanguage Programming
Is there a way to rename an existing trade?
MultiCharts
1-min Intrabar indicator
MultiCharts
Futures education program reviews
Trading Reviews and Vendors
Multichart NET: where can i find esplanation on CustomIn …
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on futures io
How much do you know about Bitcoin?
97 thanks
FIO Journal Challenge - April 2021 w/Jigsaw Trading
38 thanks
I finally blew up an account
38 thanks
EdgeProX from Edge Clear
22 thanks
The tiyfTradePlanFactory indicator
21 thanks
 
(login for full post details)
  #2 (permalink)
utilizator
Moncton Canada
 
 
Posts: 3 since Nov 2017
Thanks: 0 given, 2 received

Hi markbb10, I suggest to first try to output your values to Output window, as shown in the attached image.
From there, you can copy& paste the values in your text editor (Notepad, Wordpad, MS Word etc) and save them.
I hope this helps.

Attached Thumbnails
Click image for larger version

Name:	topic.806937.png
Views:	109
Size:	53.7 KB
ID:	298815  
Reply With Quote
The following user says Thank You to utilizator for this post:
 
(login for full post details)
  #3 (permalink)
 markbb10 
Morristown NJ USA
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
 
Posts: 101 since Aug 2012
Thanks: 41 given, 42 received


Hi Utilizer,

Thanks for the suggestion but this will not accomplish what I am looking for. These values are
changing on every candle, so I want an easy way to visually look at all 5 conditions and
be able to ascertain an entry. Copying and pasting values will not work.

I have all the code written to produce the data I am just looking for the code to use to print those
values on the chart in a table.

Thanks again for your reply.

Mark

Started this thread Reply With Quote
 
(login for full post details)
  #4 (permalink)
NT2005
Bucharest, Romania
 
 
Posts: 1 since Apr 2020
Thanks: 0 given, 1 received


markbb10 View Post
Hi Utilizer,

Thanks for the suggestion but this will not accomplish what I am looking for. These values are
changing on every candle, so I want an easy way to visually look at all 5 conditions and
be able to ascertain an entry. Copying and pasting values will not work.

I have all the code written to produce the data I am just looking for the code to use to print those
values on the chart in a table.

Thanks again for your reply.

Mark

Hi Mark,

I haven't actually tried it, but there's this NinjaTrader support link which I think might be helpful (I assume you are using Ninja Trader 8):

https://ninjatrader.com/support/helpGuides/nt8/?using_sharpdx_for_custom_chart_rendering.htm

Under SharpDX Text Rendering section - I believe it might do sort of what you are trying to achieve, or at least close - place some text at some arbitrary (x,y) coordinates.

Hope this helps,
Sorin

Reply With Quote
The following user says Thank You to NT2005 for this post:
 
(login for full post details)
  #5 (permalink)
 Stevea94 
Newbury, UK
 
Experience: Intermediate
Platform: NinjaTrader
Broker: NinjaTrader, Kinetick
Trading: NQ, CL, 6E
 
Posts: 78 since Oct 2015
Thanks: 1 given, 146 received


markbb10 View Post
Hello All,

First I am not a programmer but I have been learning and doing OK on that path.

I have written a script that does some correlation work of several other indicators and I want to
print out various output of that correlation on the chart, or in a table or in the MA.

I just want a list of the five outputs that are basically just a red or green long, short indication.

Currently I am using the Draw.TextFixed() call but this limits me to the four corners of the chart
for placement of the text.

What would I use to place the output in a list at some predefined area of the chart

Output one - Long
Output two - Short
Output three - Long

etc.


As always thanks for the input.

Mark

Not sure if this will help - this code uses the .NET grid overlay stuff which I borrowed from someone else - I forget who.

I wanted on chart buttons but it also implements text. Essentially, the screen is split into predefined grid of cells and buttons/text can be created in any cell.

The code was never polished so apologies if it's not that clear.

The other way - probably simpler - which I also use, is to draw a block of text (Draw.Text) every bar at a fixed bar on the screen. I use a -ve bar offset so it appears at the right edge. Works for me.

All the best.

Steve

Attached Files
Register to download File Type: cs smaButtonTest.cs (29.6 KB, 17 views)
Reply With Quote
The following user says Thank You to Stevea94 for this post:
 
(login for full post details)
  #6 (permalink)
 markbb10 
Morristown NJ USA
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
 
Posts: 101 since Aug 2012
Thanks: 41 given, 42 received

Thank you all for the suggestions. This will give me some direction to research, very much appreciated.

Mark

Started this thread Reply With Quote
 
(login for full post details)
  #7 (permalink)
 sg72 
Orange County, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader, Fidelity ATP
Trading: ES/NQ/RTY, Equity ETFs, Options
 
Posts: 29 since Sep 2018
Thanks: 31 given, 32 received

If I understand correctly, I think you're just looking for a flexible placement of text on the actual chart. If that's the case, then why don't you use Draw.Text() instead of Draw.TextFixed()? With Draw.Text() you can line up the text above/below a given bar where it belongs and offset it as desired.

https://ninjatrader.com/support/helpGuides/nt8/?draw_text.htm

If you're looking to generate a multi-line text and print it all at once, then you can use string.Format and string concatenation (using + sign) and use the linefeed character \r (backslash r) to insert new lines in your text string.

Here's a sample code snippet:

string format = "{0,4:F0} ({1,5:P1})" ;
string disptext = "Price stats:" ;
disptext += "\rR1=" + string.Format( format , u1+l1 , (double)(u1+l1)/(double)total ) ;
disptext += "\rR2=" + string.Format( format , u1+u2+l1+l2 , (double)(u1+u2+l1+l2)/(double)total ) ;

This will produce something like below:

Price stats:
R1=8354 (36.6%)
R2=15288 (67.0%)

You can look up the string.Format incantations online.

Hope this helps.

Reply With Quote
The following 2 users say Thank You to sg72 for this post:
 
(login for full post details)
  #8 (permalink)
 markbb10 
Morristown NJ USA
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
 
Posts: 101 since Aug 2012
Thanks: 41 given, 42 received

Thank you all for your replies.

I am experimenting with Draw.Text. I have this line of code running and acting as expected.
If I change the "candles back" parameter to 23 versus 22 it does not print. Can anyone explain
why? I have about 100 candles on the chart

Draw.Text(this,"drawtag1","Weis Wave - Red",22,Close[0],Brushes.Black); - This works
Draw.Text(this,"drawtag1","Weis Wave - Red",23,Close[0],Brushes.Black); - This does not

So confusing

Started this thread Reply With Quote
 
(login for full post details)
  #9 (permalink)
 Epistemophilic 
Los Angeles
 
Experience: Advanced
Platform: NT8, Python, and TOS
Trading: NQ, ES & CL
 
Posts: 29 since Oct 2010
Thanks: 28 given, 37 received


markbb10 View Post
Hello All,

First I am not a programmer but I have been learning and doing OK on that path.

I have written a script that does some correlation work of several other indicators and I want to
print out various output of that correlation on the chart, or in a table or in the MA.

I just want a list of the five outputs that are basically just a red or green long, short indication.

Currently I am using the Draw.TextFixed() call but this limits me to the four corners of the chart
for placement of the text.

What would I use to place the output in a list at some predefined area of the chart

Output one - Long
Output two - Short
Output three - Long

etc.


As always thanks for the input.

Mark

I hope this helps.

 
Code
protected override void OnBarUpdate()
{
  if (CurrentBar < 20) {return}

  MyTextBox(TextForBox());    
}


protected string TextForBox()
{
  // add text here
  string yourText = "";
  return yourText;  
}

protected void MyTextBox(string textThatGoesInTheBox)
{
  TextFixed myTF = Draw.TextFixed(this, "MyText", textThatGoesInTheBox, TextPosition.TopRight);
  myTF.TextPosition = TextPosition.TopRight;
  myTF.AreaBrush = Brushes.DimGray;
  myTF.AreaOpacity = 90;
  myTF.TextBrush = Brushes.Black;
}

/* Instantiate a TextFixed object
TextFixed myTF = Draw.TextFixed(this, "tag1", "Text to draw", TextPosition.TopRight);
 
// Change the object's TextPosition
myTF.TextPosition = TextPosition.Center;

TextPosition Possible values are:
TextPosition.BottomLeft
TextPosition.BottomRight
TextPosition.Center
TextPosition.TopLeft
TextPosition.TopRight*/

Reply With Quote
The following user says Thank You to Epistemophilic for this post:
 
(login for full post details)
  #10 (permalink)
 markbb10 
Morristown NJ USA
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
 
Posts: 101 since Aug 2012
Thanks: 41 given, 42 received


I want to thank everyone for their ideas and guidance. I am slowly learning more but I would be lying if I did not say it is driving me crazy.

Here is my latest issue. I have a short code snippet that will print the status of a indicator depending on the value of the variable called trend at a defined location on the chart.

In the format below I get printing of the status correctly in the defined locations. Please note that the first if statement is a Draw.TextFixed call and the second is Draw.Text.

if (trend == 1)
Draw.TextFixed(this,"status","Weis Wave is Green", TextPosition.TopRight,Brushes.White, ChartControl.Properties.LabelFont,Brushes.Black,Brushes.Green,100);

if (trend == -1)
Draw.Text(this,"drawtag1",false,"Weis Wave - Red",18,Close[0],-80,Brushes.Red,myFont,TextAlignment.Center,Brushes.Red,Brushes.LightGray,80);

If I change the first If statement to a Draw.Text, using proper syntax the indicator will compile without error but produces NOTHING on the screen. I have never seen anything more frustrating. Below is the code sequence that will compile but prints no data on the chart.

if (trend == 1)
Draw.Text(this,"drawtag1",false,"Weis Wave - Green",18,Close[0],-70, Brushes.Green,myFont, TextAlignment.Center,Brushes.Green,Brushes.LightGray,80);

if (trend == -1)
Draw.Text(this,"drawtag1",false,"Weis Wave - Red",18, Close[0],-80, Brushes.Red, myFont, TextAlignment.Center,Brushes.Red,Brushes.LightGray,80);

This prints nothing

Started this thread Reply With Quote
 
(login for full post details)
  #11 (permalink)
 sg72 
Orange County, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader, Fidelity ATP
Trading: ES/NQ/RTY, Equity ETFs, Options
 
Posts: 29 since Sep 2018
Thanks: 31 given, 32 received

I think your issue may be that you have the same draw tags overwriting each other. Make each draw tag unique. If you need to place text on multiple bars and you're generating no more than one text object per bar, then one way to make sure your tags are unique is to use CurrentBar in constructing your tag.

Ex:

Draw.Text(this,"DT_"+CurrentBar,false, the rest of your code

If you need more than one text object per bar, then use "DT1_"+CurrentBar, "DT2_"+CurrentBar, so on and so forth.

If you keep using the same draw tag with successive calls to Draw.Text() on different bars, each time the function is executed, it will operate on the same text object instead of generating a new text object for the new bar. Which means the older text will disappear and get replaced with the new text at the new location. If I'm not mistaken, this is what you're seeing.

Hope this is clear.

Good luck.

Reply With Quote
 
(login for full post details)
  #12 (permalink)
 markbb10 
Morristown NJ USA
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
 
Posts: 101 since Aug 2012
Thanks: 41 given, 42 received

@sg72 Thank for the info. I have experimented with tags and that does not appear to make
a difference. When I use the two instances of the Draw.Text not only does the desired text not
appear but all output from the indicator ceases as well.

Thank for the suggestions.

Mark

Started this thread Reply With Quote
 
(login for full post details)
  #13 (permalink)
 Stevea94 
Newbury, UK
 
Experience: Intermediate
Platform: NinjaTrader
Broker: NinjaTrader, Kinetick
Trading: NQ, CL, 6E
 
Posts: 78 since Oct 2015
Thanks: 1 given, 146 received


markbb10 View Post
I want to thank everyone for their ideas and guidance. I am slowly learning more but I would be lying if I did not say it is driving me crazy.

Here is my latest issue. I have a short code snippet that will print the status of a indicator depending on the value of the variable called trend at a defined location on the chart.

In the format below I get printing of the status correctly in the defined locations. Please note that the first if statement is a Draw.TextFixed call and the second is Draw.Text.

if (trend == 1)
Draw.TextFixed(this,"status","Weis Wave is Green", TextPosition.TopRight,Brushes.White, ChartControl.Properties.LabelFont,Brushes.Black,Brushes.Green,100);

if (trend == -1)
Draw.Text(this,"drawtag1",false,"Weis Wave - Red",18,Close[0],-80,Brushes.Red,myFont,TextAlignment.Center,Brushes.Red,Brushes.LightGray,80);

If I change the first If statement to a Draw.Text, using proper syntax the indicator will compile without error but produces NOTHING on the screen. I have never seen anything more frustrating. Below is the code sequence that will compile but prints no data on the chart.

if (trend == 1)
Draw.Text(this,"drawtag1",false,"Weis Wave - Green",18,Close[0],-70, Brushes.Green,myFont, TextAlignment.Center,Brushes.Green,Brushes.LightGray,80);

if (trend == -1)
Draw.Text(this,"drawtag1",false,"Weis Wave - Red",18, Close[0],-80, Brushes.Red, myFont, TextAlignment.Center,Brushes.Red,Brushes.LightGray,80);

This prints nothing

You might want to check you've initialised 'myFont' correctly as this doesn't seem to be used in your TextFixed call.

This is a code snippet I use (as I don't use borders or background):

 
Code
		
else if (State == State.Configure)
{
	if (TextFont == null) TextFont = new SimpleFont("Arial", InfoTextSize);
}


private void DrawText(string Tag, string Text, bool IsAutoScale, int BarOffset, double TickOffset, int PixelOffset, int FontSize, Brush Color)
{
	TextFont.Size = FontSize;
	Draw.Text(this, Tag, IsAutoScale, Text, BarOffset, TickOffset, PixelOffset, Color, TextFont, TextAlignment.Left, Brushes.Transparent, Brushes.Transparent, 0);  
}
I use this in various ways and occasionally with a -15 BarOffset which prints to the right of the price bars.

Steve

Reply With Quote
 
(login for full post details)
  #14 (permalink)
 markbb10 
Morristown NJ USA
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
 
Posts: 101 since Aug 2012
Thanks: 41 given, 42 received

Thanks Steve, myFont is initialized properly as a SimpleFont() and works correctly.

Started this thread Reply With Quote
 
(login for full post details)
  #15 (permalink)
 sg72 
Orange County, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader, Fidelity ATP
Trading: ES/NQ/RTY, Equity ETFs, Options
 
Posts: 29 since Sep 2018
Thanks: 31 given, 32 received

It just occurred to me that you're trying to place your text several bars back. When you loop through the logic inside OnBarUpdate(), that goes through all the bars on the chart starting with the first bar that prints. If for example, OnBarUpdate() happens to be on bar #5 from the beginning and you're trying to place a text 15 bars ago, you're going to get an indexing error. If you haven't don't so already, please open a NinjaScript Output window and watch for errors/warnings there. That might give you a clue as to what's happening.

If this is the issue you're having, you can get around it by having a statement like below so that you'll skip over the logic for the first few bars until you have enough bars that if you attempt to go back a few, it won't give you the indexing error.

protected override void OnBarUpdate()
{
if(CurrentBar < 10 ) { return ; } // Skip the first few bars to let things settle down.
The rest of your logic here
}

You'll have to pick a number that works for you.

Hope this helps. I'm running out of ideas .

Reply With Quote
The following user says Thank You to sg72 for this post:
 
(login for full post details)
  #16 (permalink)
 markbb10 
Morristown NJ USA
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
 
Posts: 101 since Aug 2012
Thanks: 41 given, 42 received

Hi @sg72

Thanks for that, I actually have that test in my code, I had not included it here for clarity.
Thanks for the input but that does not seem to be the issue.

Mark

Started this thread Reply With Quote
 
(login for full post details)
  #17 (permalink)
 sg72 
Orange County, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader, Fidelity ATP
Trading: ES/NQ/RTY, Equity ETFs, Options
 
Posts: 29 since Sep 2018
Thanks: 31 given, 32 received

If you'd like, you can copy the relevant parts of your code into a shorter script and test to make sure it has the same issue and then attach it here and I'll look at it and see if I can figure out what the issue is. Without seeing the code, I'm running out of ideas as to what it could be.

Reply With Quote
The following user says Thank You to sg72 for this post:
 
(login for full post details)
  #18 (permalink)
 markbb10 
Morristown NJ USA
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
 
Posts: 101 since Aug 2012
Thanks: 41 given, 42 received

@sg92 you were right. It is due to number of bars being tested. I was not looking at the logic correctly due to my incompetence.

Thanks so much for all the help as I attempt to learn this.

Always much appreciated.

Mark

Started this thread Reply With Quote
The following user says Thank You to markbb10 for this post:
 
(login for full post details)
  #19 (permalink)
IanC55
Aberdeen Scotland
 
 
Posts: 5 since Feb 2019
Thanks: 0 given, 0 received


sg72 View Post
I think your issue may be that you have the same draw tags overwriting each other. Make each draw tag unique. If you need to place text on multiple bars and you're generating no more than one text object per bar, then one way to make sure your tags are unique is to use CurrentBar in constructing your tag.

Ex:

Draw.Text(this,"DT_"+CurrentBar,false, the rest of your code

If you need more than one text object per bar, then use "DT1_"+CurrentBar, "DT2_"+CurrentBar, so on and so forth.

If you keep using the same draw tag with successive calls to Draw.Text() on different bars, each time the function is executed, it will operate on the same text object instead of generating a new text object for the new bar. Which means the older text will disappear and get replaced with the new text at the new location. If I'm not mistaken, this is what you're seeing.

Hope this is clear.

Good luck.

I agree it is your tag. They need to be unique. However using CurrentBar will give you more than two bits of text. Not sure if that is your intention. If not just use two unique Tags.

Reply With Quote
 
(login for full post details)
  #20 (permalink)
 jalley 
La Grange, CA USA
 
Experience: Intermediate
Platform: Ninjatrader, MetaTrader
Broker: NinjaTrader Brokerage
Trading: MES, MNQ, M2K, MYM
 
Posts: 23 since Jun 2020
Thanks: 14 given, 6 received

Here is a solution: (I see it reformats my code wrong when posting as I indent my code between brackets)

protected void DrawTextFixed(TextPosition textPosition, int row, string tag, string txt, Brush myBrush, int opacity = 85)
{
string output = "";

for (int i = 0; i < row; i++) output += "\r";
output += txt;
Draw.TextFixed(this, tag, output, textPosition, myBrush, myFont, Brushes.Transparent, Brushes.Transparent,
opacity);
}

protected void RenderTextInfo()
{
// This next line draws the box and I use I put \r for each line
Draw.TextFixed(this, "Box","l l\r\r\r\r\r\r\r\r", TextPosition.TopLeft,
Brushes.DarkOliveGreen, myFont, Brushes.DarkOliveGreen, Brushes.Black, 85);
DrawTextFixed(TextPosition.TopLeft, 1, "ATR", String.Format("ATR: {0:0.00}", myATR[0]),
Brushes.Yellow);
// And so on for other lines
}

Visit my futures io Trade Journal Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Ninja script question - Text Placement on Chart


Last Updated on February 25, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing

NEW BlackBird Features + FOREX Support w/Jeremy Tang @ SharkIndicators

Elite only
 

Our 12-year anniversary w/ $$,$$$ prizes (check soon)

June
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts