Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Need to draw vertical and horizontal lines
Updated July 13, 2018
Top Posters
looks_one
jsk123
with 2 posts (0 thanks)
looks_two
Quick Summary
with 1 posts (0 thanks)
looks_3
roelop
with 1 posts (0 thanks)
looks_4
TradingOgre
with 1 posts (0 thanks)
trending_up
6,062 views
thumb_up
2 thanks given
group
4 followers
forum
5 posts
attach_file
0 attachments
Need to draw vertical and horizontal lines
March 20th, 2015, 09:34 PM
Hyderabad,India
Posts: 88 since Oct 2013
Thanks Given: 44
Thanks Received: 21
hello,
I have some price levels and certain dates (pre determined). I want to put that info into an indicator so that whenever I open the chart and load this indicator they are always there.
I tried to draw a vertical line on 17th march 2015, but it is not showing up. There are no errors in the code btw.
Code
public class Dates : Indicator
{
#region Variables
// Wizard generated variables
private uint date; // Default setting for MyInput0
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
// if (date == 20150317 && FirstTickOfBar)
// DrawVerticalLine("MyVerticalLine", 0, Color.Blue);
if (ToTime(Time[0]) == 00000 && ToDay(Time[0]) == 20150317 && FirstTickOfBar)
DrawVerticalLine( "myTag", 20150317 , Color.Blue, DashStyle.Dash , 2);
Why is this not working ?
Also please mention how to draw lines at specific price levels using ninjascript
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
March 20th, 2015, 11:31 PM
Wrocław, Poland
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623
Since you want to use the overload with date, you need to call the method with the following arguments:
Code
DrawVerticalLine(string tag, DateTime time, Color color, DashStyle dashStyle, int width)
In your code:
Code
DrawVerticalLine( "myTag", 20150317 , Color.Blue, DashStyle.Dash , 2);
you are not providing the DateTime but an int which is interpreted by NT as barsAgo, hence no error as it "draws" a line 20150317 bars ago. Read more on DateTime structure here:
C# DateTime Examples
Another problem in your code will be the tag which is not unique this will cause NT keeping only the last drawn line on the chart.
Try using the following:
Code
DrawVerticalLine("myVL" + 20150317, new DateTime(2015, 3, 17), Color.Blue, DashStyle.Dash, 2);
PS. For specific price level you probably want horizontal line, read here:
https://ninjatrader.com/support/helpGuides/nt7/index.html?drawhorizontalline.htm
March 21st, 2015, 01:28 AM
Hyderabad,India
Posts: 88 since Oct 2013
Thanks Given: 44
Thanks Received: 21
Thanks a lot gregid!! Didn't expect to do this so fast!
I messed around with the code and found that the integer no. after the tag is also not mandatory along with the 'dumb' if clause I used -_-
Thanks
Code
// DrawVerticalLine("MyVerticalLine", 0, Color.Blue);
// if (ToTime(Time[0]) == 00000 && ToDay(Time[0]) == 20150317 && FirstTickOfBar)
// this if is useless piece of crap!!!
// DrawVerticalLine( "myTag", 20150317 , Color.Blue, DashStyle.Dash , 2);
DrawVerticalLine("myV3L" , new DateTime(2015, 3, 17), Color.Blue, DashStyle.Dash, 2);
DrawVerticalLine("myVL" , new DateTime(2015, 3, 18), Color.Green, DashStyle.Dash, 2);
DrawHorizontalLine("myhl", true, 162.125, Color.Red, DashStyle.Solid, 2);
DrawVerticalLine("myVL4" , new DateTime(2015, 3, 23), Color.Green, DashStyle.Dash, 2);
Makes me feel that I cant do much relying solely on NT manual -_-
gregid
Since you want to use the overload with date, you need to call the method with the following arguments:
Code
DrawVerticalLine(string tag, DateTime time, Color color, DashStyle dashStyle, int width)
In your code:
Code
DrawVerticalLine( "myTag", 20150317 , Color.Blue, DashStyle.Dash , 2);
you are not providing the DateTime but an int which is interpreted by NT as barsAgo, hence no error as it "draws" a line 20150317 bars ago. Read more on DateTime structure here:
C# DateTime Examples
Another problem in your code will be the tag which is not unique this will cause NT keeping only the last drawn line on the chart.
Try using the following:
Code
DrawVerticalLine("myVL" + 20150317, new DateTime(2015, 3, 17), Color.Blue, DashStyle.Dash, 2);
PS. For specific price level you probably want horizontal line, read here:
NinjaTrader Version 7
July 13th, 2018, 03:32 PM
Denton, TX
Experience: Beginner
Platform: NinjaTrader
Trading: NQ, CL, AD
Posts: 1 since Nov 2016
Thanks Given: 0
Thanks Received: 0
How to draw a global verticalline.
I want to draw a verticalline in multiple open chart.
This code is working well, but I want to draw this line in all my charts.
Draw.VerticalLine(this, @"buy " + CurrentBars[0].ToString(), 0, Brushes.Lime, DashStyleHelper.Solid, 2);
Thanks.
July 13th, 2018, 06:20 PM
Evans GA/USA
Legendary Market Wizard
Experience: Intermediate
Platform: NinjaTrader
Broker: NinjaTrader Brokerage - Philip Capital
Trading: NQ,ES,6E,CL
Posts: 556 since Jul 2018
Thanks Given: 908
Thanks Received: 1,672
roelop
How to draw a global verticalline.
I want to draw a verticalline in multiple open chart.
This code is working well, but I want to draw this line in all my charts.
Draw.VerticalLine(this, @"buy " + CurrentBars[0].ToString(), 0, Brushes.Lime, DashStyleHelper.Solid, 2);
Thanks.
If you are using NT 8, have you tried turning on global drawing objects? Tools->Options->General->Global Drawing Objects Across Workspaces.
not sure if that will work just something I noticed the other day.
Edit: Never mind. Just tried it and it didn't do what I thought.
Last Updated on July 13, 2018