thanks
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How get the last text on a chart?
Collapse
X
-
How get the last text on a chart?
Hi, i have a indicator that draw on a chart one text when meet conditions. How can get the last text, with the last N bars traded?
thanksTags: None
-
-
No, i don't have the source code. I use this code to find it, but get an error:
foreach (DrawingTool draw in DrawObjects)
{
if (draw != null) {
if (draw.Tag.Contains("up"))
{
Log ("fond text: " + draw.Tag, LogLevel.Information);
Text texto = draw as DrawingTools.Text; // when do this, i receive this error: Default Strategy 'AlertBullBear': Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object.
// DrawingTools.Text texto = draw as DrawingTools.Text; // and get the same error
Log ("Bars ago: " + texto.Anchor.BarsAgo, LogLevel.Information);
Log ("play the sound", LogLevel.Information);
NinjaTrader.Core.Globals.PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\CompiledSuccessfully.wav");
}}
}
could it be a different type of object?
Comment
-
Hello Pbarrionuevo,
Thanks for your reply.
Yes, I think it should be DrawingTools.Text texto as in your commented example.
Here is a similar example I have used to read text on the chart, please give this a try:
foreach (DrawingTool draw in DrawObjects.ToList())
{
if (draw is DrawingTools.Text)
{
DrawingTools.Text myText = draw as DrawingTools.Text;
Print("Tag name: "+myText.Tag+" Displayed text: "+myText.DisplayText);
}
}
Note: Print will send the text to the New>Ninjascript output window which is the recommended place to send debugging text. Excessive use of Log() can lead to performance issues.
Comment
-
-
Hello Pbarrionuevo,
Thanks for your reply.
You might try checking the DrawObjects.Count and when it changes (meaning you should save it to a variable so you can compare) then perhaps that is your trigger to read.
When you process each (foreach loop) object you can save the anchor time to a variable and the next time through the list skip anything before that time, when the object is a later time then likely that is your candidate to check.
DrawingTools.Text myText = draw as DrawingTools.Text;
Print("Tag name: "+myText.Tag+" Displayed text: "+myText.DisplayText);
Print("startPrice: " + myText.Anchor.Price);
Print("startTime: " + myText.Anchor.Time);
Comment
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
49 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
67 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment