NexusFi: Find Your Edge


Home Menu

 





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 Epistemophilic with 1 posts (1 thanks)
      Best Posters
    1. looks_one sg72 with 1 thanks per post
    2. looks_two utilizator with 1 thanks per post
    3. looks_3 NT2005 with 1 thanks per post
    4. looks_4 markbb10 with 0.1 thanks per post
    1. trending_up 6,699 views
    2. thumb_up 9 thanks given
    3. group 8 followers
    1. forum 19 posts
    2. attach_file 2 attachments




 
Search this Thread

Ninja script question - Text Placement on Chart

  #1 (permalink)
 markbb10 
Treasure Coast, Florida
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
Posts: 135 since Aug 2012
Thanks Given: 57
Thanks Received: 50

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 NexusFi?
Quantum physics & Trading dynamics
The Elite Circle
Cheap historycal L1 data for stocks
Stocks and ETFs
Trade idea based off three indicators.
Traders Hideout
About a successful futures trader who didnt know anythin …
Psychology and Money Management
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #2 (permalink)
utilizator
Moncton Canada
 
Posts: 8 since Nov 2017
Thanks Given: 0
Thanks Received: 7

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:	400
Size:	53.7 KB
ID:	298815  
Reply With Quote
Thanked by:
  #3 (permalink)
 markbb10 
Treasure Coast, Florida
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
Posts: 135 since Aug 2012
Thanks Given: 57
Thanks Received: 50


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
  #4 (permalink)
NT2005
Bucharest, Romania
 
Posts: 1 since Apr 2020
Thanks Given: 0
Thanks Received: 1


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
Thanked by:
  #5 (permalink)
 Stevea94 
Newbury, UK
 
Experience: Intermediate
Platform: NinjaTrader
Broker: NinjaTrader, Kinetick
Trading: NQ, CL, 6E
Posts: 78 since Oct 2015
Thanks Given: 1
Thanks Received: 150


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
Elite Membership required to download: smaButtonTest.cs
Reply With Quote
Thanked by:
  #6 (permalink)
 markbb10 
Treasure Coast, Florida
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
Posts: 135 since Aug 2012
Thanks Given: 57
Thanks Received: 50

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

Mark

Started this thread Reply With Quote
  #7 (permalink)
 sg72 
Orange County, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader, Fidelity ATP
Trading: ES/NQ/RTY, Equity ETFs, Options
Posts: 59 since Sep 2018
Thanks Given: 44
Thanks Received: 48

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
Thanked by:
  #8 (permalink)
 markbb10 
Treasure Coast, Florida
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
Posts: 135 since Aug 2012
Thanks Given: 57
Thanks Received: 50

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
  #9 (permalink)
 Epistemophilic 
Los Angeles
 
Experience: Advanced
Platform: NT8, Python, and TOS
Trading: NQ, ES & CL
Posts: 29 since Oct 2010
Thanks Given: 28
Thanks Received: 37


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
Thanked by:
  #10 (permalink)
 markbb10 
Treasure Coast, Florida
 
Experience: Advanced
Platform: Ninja 8
Trading: Futures
Posts: 135 since Aug 2012
Thanks Given: 57
Thanks Received: 50


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




Last Updated on February 25, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts