Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Draw line
Collapse
X
-
Draw line
I have a problem on drawing a line up to the price I want. I have attached an image on it. Thanks in advance.Tags: None
-
You need to be more specific - for example - how are you selecting the end point of the line? If you just want to end it an arbitrary number of bars in the future use a negative number for the end bar.
From the help guide
// Draws a dotted lime green line from 10 bars back to 10 bars in the future with a width of 2 pixels
DrawLine("tag1", false, 10, 1000, -10, 1001, Color.LimeGreen, DashStyle.Dot, 2);
-
-
drawing lines within a strategy
I don't know whether this is the right place to post my question, but I'd like to print or to draw something (a line, a square, "Buy", the current price, ....) on the chart - if possible just above/below the current bar - whenever the conditions of my preferred strategy or indicator are triggered.
Can someone please show to me in the praxis how this may be done either on the Strategy Wizard or with NinjaScript C++ (something similar to DrawText("My text "+Close[0], CurrentBar, 0, 0, Color.Red), in order to have a visual display (and control) of my signals and my entry points ?
Thank youLast edited by fliesen; 01-20-2014, 12:42 PM.
Comment
-
Fliesen,
Thank you for your post.
You will need to decide with draw object you would want to use and where on the chart you would want to place it.
If you are looking to do a box with text then you would want to use DrawRectangle and DrawText to place those above or below the CurrentBar.
DrawRectangle
DrawTextCal H.NinjaTrader Customer Service
Comment
-
So why does the following code not work (= not draw), and how must I change it ?
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Stoch+Fastoch+ Macd; and Ichimoku
/// </summary>
[Description("Stoch+Fastoch+ Macd; and Ichimoku")]
public class AllWIZARD : Strategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (Close[0] > 1) // condition always TRUE, should always draw something
{
BackColor = Color.Black;
DrawDot("My dot" + CurrentBar, false, 0, 0, Color.Blue); // just draws a dot
DrawRectangle("My rectangle" + CurrentBar, 0, 0, 0, 0, Color.Blue); // just a rectangle above the current bar ?
DrawText("My text" + CurrentBar, "Do something", 0, 0, Color.Red); // a text within the rectangle ?
Alert(...........);
}
Comment
-
fliesen, would be expected since you are literally drawing those objects at a price value of 0
DrawDot("My dot" + CurrentBar, false, 0, 0, Color.Blue); // just draws a dot
DrawRectangle("My rectangle" + CurrentBar, 0, 0, 0, 0, Color.Blue); // just a rectangle above the current bar ?
DrawText("My text" + CurrentBar, "Do something", 0, 0, Color.Red); // a text within the rectangle ?
So those would then not be visualized - please try passing in a more meaningful price based value (i.e. Close[0] +/- an offset).
Comment
-
Drawing on charts
Thanks for your answer, however there is something I don't understand:
- if not the correct price, at least a "0" should be anyway displayed, shouldn't it ?
- similarly, I suppose the "DrawDot" script had to print a dot in any case, and not a price;
- will the following lines solve the problem ?
DrawDot("My dot" + CurrentBar, false, 0, Close[0], Color.Blue);
DrawRectangle("My rectangle" + CurrentBar, 0, Close[1], 0, Close[0], Color.Blue);
DrawText("My text" + CurrentBar, "Do something", 0, Close[0], Color.Red);
- which chart will be affected by these lines, or in other words, which chart will display the price on the CurrentBar ?
- finally, how must I thank in order to avoid that "Thanks: 0" in my profile ?
Comment
-
Hello,
Yes and no. The DrawDot as the property of Autoscale to allow you to choose if the dot gets scaled into the chart with the price bars. This was set to false and therefore not scaled in.if not the correct price, at least a "0" should be anyway displayed, shouldn't it ?
Yes, however, I recommend that you set start and end bars ago values for the DrawRectangle, or you could end up with a line on the current bar (0) and not a rectangle.will the following lines solve the problem ?
The only chart that will be affected will be the chart that you apply this indicator to.which chart will be affected by these lines, or in other words, which chart will display the price on the CurrentBar ?
To 'Thank' a post there is a Thanks with a smiley face in the lower right hand corner of each post that you can click to thank the user for that post.finally, how must I thank in order to avoid that "Thanks: 0" in my profile ?
Let me know if I can be of further assistance.Cal H.NinjaTrader Customer Service
Comment
-
Also with the new code, I'm still not able to print anything on my charts.
Could you kindly give me a short, real example of a "DrawText" script printing whatever on the current bar of an opened chart ?
No rectangle is needed. Please, also consider that I'm not applying an indicator on a chart, but simply editing a normal strategy code or strategy wizard.
Comment
-
DrawText("MyTag" + CurrentBar, "String to be displayed", 0, High[0], Color.Black);
This snippet will print "String to be displayed at each current bar at the High price value.
If you only just want one text being displayed and not every bar, then drop the + CurrentBarCal H.NinjaTrader Customer Service
Comment
-
I opened a brand new strategy, only with your snippet + a visual alert "DrawText", timeframe 1 minute, but when I click on the alert and open a chart with the same timeframe, I see nothing.
Where is the string going to be printed ???
Please see the chart: https://www.dropbox.com/s/lxawez690c...%20drawing.JPG
and the code: https://www.dropbox.com/s/n66mjarskm6exk2/Strategy.cs
Comment
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
602 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
347 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
559 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
559 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment