NexusFi: Find Your Edge


Home Menu

 





Need to draw vertical and horizontal lines


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one jsk123 with 2 posts (0 thanks)
    2. looks_two roelop with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 TradingOgre with 1 posts (0 thanks)
    1. trending_up 6,058 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Need to draw vertical and horizontal lines

  #1 (permalink)
jsk123
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

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
REcommedations for programming help
Sierra Chart
Exit Strategy
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 
gregid's Avatar
 gregid 
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

Reply With Quote
Thanked by:
  #4 (permalink)
jsk123
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 View Post
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


Reply With Quote
  #5 (permalink)
 roelop 
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.

Follow me on Twitter Reply With Quote
  #6 (permalink)
 
TradingOgre's Avatar
 TradingOgre 
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 View Post
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.

Visit my NexusFi Trade Journal Reply With Quote




Last Updated on July 13, 2018


© 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