Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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);
-
stocktraderbmp would be correct - it would be important to know first how this line is drawn. Further you would need to set the datetime or bars into the future tied to your target end point, so you cannot extend simply to a price because that's just one coordinate needed.BertrandNinjaTrader Customer Service
Comment
-
-
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).BertrandNinjaTrader Customer Service
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,
if not the correct price, at least a "0" should be anyway displayed, shouldn't it ?
will the following lines solve the problem ?
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 ?
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 George21, Today, 10:07 AM
|
0 responses
4 views
0 likes
|
Last Post
by George21
Today, 10:07 AM
|
||
Started by Stanfillirenfro, Today, 07:23 AM
|
8 responses
23 views
0 likes
|
Last Post Today, 10:02 AM | ||
Started by DayTradingDEMON, Today, 09:28 AM
|
2 responses
16 views
0 likes
|
Last Post Today, 09:56 AM | ||
Started by navyguy06, Today, 09:28 AM
|
1 response
6 views
0 likes
|
Last Post Today, 09:54 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
8 responses
32 views
0 likes
|
Last Post Today, 09:34 AM |
Comment