NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 07-20-2012, 01:26 PM   #1
vsolv
Junior Member
 
Join Date: Jul 2012
Posts: 12
Thanks: 6
Thanked 1 time in 1 post
Default Vertical Bar

Is it possible to draw a vertical line between 2 indicators. For example, if I have 2 moving averages on the chart and I want to draw a vertical line between them, is it possible?

I'm transitioning from traderstation and they had a feature called Paintbar which would allow me to pass a high value and a low value and it would paint a vertical bar on the chart.

Hoping someone can help.
vsolv is offline  
Reply With Quote
Old 07-20-2012, 01:33 PM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi vsolv,

Yes, you could use DrawLine(), which has startY and endY inputs:
http://www.ninjatrader.com/support/h...7/drawline.htm

You may want to check out DrawRegion() as well. There's a sample showing how to work it between Bollinger lines here:
http://www.ninjatrader.com/support/f...ead.php?t=4331
NinjaTrader_RyanM is offline  
Reply With Quote
The following user says thank you to NinjaTrader_RyanM for this post:
Old 07-20-2012, 02:13 PM   #3
vsolv
Junior Member
 
Join Date: Jul 2012
Posts: 12
Thanks: 6
Thanked 1 time in 1 post
Default

When using the Drawline
startY - The starting y value co-ordinate where the draw object will be drawn
EndY - The end y value co-ordinate where the draw object will be drawn

Drawline is expecting me to provide the StartY and EndY values. I'm guessing that the coordinate system is in pixels. So question is, how do I take my indicator's High and Low values and convert it to the proper Y coordinate ?

Sorry --- newbie here and just learning NScript.
vsolv is offline  
Reply With Quote
Old 07-20-2012, 02:27 PM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

StartY and EndY are the values of your moving averages. Let's say you have a 5 period and 50 period SMA. You would draw lines between them with something like this:

Code:
DrawLine("Lines" + CurrentBar, 0, SMA(5)[0], 0, SMA(50)[0], Color.Blue);
This can be a bit of a performance drain, so I would also take a look at that DrawRegion sample which can do this sort of thing with more efficiency.
NinjaTrader_RyanM is offline  
Reply With Quote
The following user says thank you to NinjaTrader_RyanM for this post:
Old 07-20-2012, 03:43 PM   #5
vsolv
Junior Member
 
Join Date: Jul 2012
Posts: 12
Thanks: 6
Thanked 1 time in 1 post
Default

Apologize for these newbie questions.
In my indicator, I have 2 local variables that I'm trying to plot.
MyHigh, MyLow - these are double

I do my calculations to populate these in the indicator.

when I try to plot them as follows:

DrawLine("Lines" + CurrentBar, 0, <MyLocalVar_High>, 0, <MyLocalVar_Low>, Color.Blue);

I get the following errors:

Use of unassigned local variable MyHigh
Use of unassigned local variable MyLow


What am I doing wrong? Can someone help.
vsolv is offline  
Reply With Quote
Old 07-20-2012, 03:46 PM   #6
vsolv
Junior Member
 
Join Date: Jul 2012
Posts: 12
Thanks: 6
Thanked 1 time in 1 post
Default

Mistyped:

in my indicator I try to plot them as follows:

DrawLine("Lines" + CurrentBar, 0, <MyHigh>, 0, <MyLow>, Color.Blue);
vsolv is offline  
Reply With Quote
Old 07-20-2012, 03:54 PM   #7
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

For basic C# syntax, I would check out the following link:
http://www.ninjatrader.com/support/h...sic_syntax.htm

Example with doubles:
double myHigh = SMA(5)[0];
double myLow = Low[0];

Then refer in code with just myHigh or myLow. (no extra < or > needed)
NinjaTrader_RyanM is offline  
Reply With Quote
The following user says thank you to NinjaTrader_RyanM for this post:
Old 07-20-2012, 07:47 PM   #8
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,218
Thanks: 24
Thanked 1,231 times in 1,002 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by vsolv View Post
Mistyped:

in my indicator I try to plot them as follows:

DrawLine("Lines" + CurrentBar, 0, <MyHigh>, 0, <MyLow>, Color.Blue);
Why the pointy brackets?
koganam is offline  
Reply With Quote
Old 07-20-2012, 08:34 PM   #9
vsolv
Junior Member
 
Join Date: Jul 2012
Posts: 12
Thanks: 6
Thanked 1 time in 1 post
Default

Hi Kogaman and Ryan,
The pointy brackets mean nothing. I mistyped. I did not use them in my code. I come from a programming background and that is a way write pseudocode.

Anyway,
What I was trying to ask was that, in my indicator I have 2 variables that I've declared as Double in the OnBarUpdate() procedure as follows:
double MyHigh;
double MyLow;

// I did some calculations to populate MyHigh and MyLow variables
//Now what I want to do is print a vertical line between MyHigh and MyLow
//When I use the Drawline as Ryan suggested
DrawLine("Lines" + CurrentBar, 0, MyHigh, 0, MyLow, Color.Blue);

//I get the following errors:
Use of unassigned local variable MyHigh
Use of unassigned local variable MyLow

Any ideas what I'm doing wrong? From my 1 day experience with NinjaScript, it seems like it is expecting a dataseries (i.e. an array of doubles). For example if I use
DrawLine("Lines" + CurrentBar, 0, High[0], 0, Low[0], Color.Blue);
it compiles fine.

Thanks for helping.
vsolv is offline  
Reply With Quote
Old 07-20-2012, 08:45 PM   #10
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,218
Thanks: 24
Thanked 1,231 times in 1,002 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by vsolv View Post
Hi Kogaman and Ryan,
The pointy brackets mean nothing. I mistyped. I did not use them in my code. I come from a programming background and that is a way write pseudocode.

Anyway,
What I was trying to ask was that, in my indicator I have 2 variables that I've declared as Double in the OnBarUpdate() procedure as follows:
double MyHigh;
double MyLow;

// I did some calculations to populate MyHigh and MyLow variables
//Now what I want to do is print a vertical line between MyHigh and MyLow
//When I use the Drawline as Ryan suggested
DrawLine("Lines" + CurrentBar, 0, MyHigh, 0, MyLow, Color.Blue);

//I get the following errors:
Use of unassigned local variable MyHigh
Use of unassigned local variable MyLow

Any ideas what I'm doing wrong? From my 1 day experience with NinjaScript, it seems like it is expecting a dataseries (i.e. an array of doubles). For example if I use
DrawLine("Lines" + CurrentBar, 0, High[0], 0, Low[0], Color.Blue);
it compiles fine.

Thanks for helping.
It means what it says. You declared the variables without initializing them. Local variables must be initialized before being used in calculations. Try explicitly initializing the doubles (usually to zero).
koganam is offline  
Reply With Quote
The following 2 users say thank you to koganam for this post:
Old 07-20-2012, 08:53 PM   #11
vsolv
Junior Member
 
Join Date: Jul 2012
Posts: 12
Thanks: 6
Thanked 1 time in 1 post
Default

That did the trick. Thanks a lot koganam. Really appreciate it.
vsolv is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vertical Bar Indicator freeway Indicator Development 1 10-29-2011 10:08 AM
TPO and Volume Profile Chart vertical scroll bar arodrigu Version 7 Beta General Questions & Bug Reports 2 03-25-2010 07:49 AM
Range bar vertical gaps ? supertrader Charting 40 12-03-2009 02:38 PM
Drawing 2 Vertical Lines on Same Bar ATLien Indicator Development 1 07-26-2008 12:02 PM
Vertical through all levels Antraman Charting 2 04-24-2006 01:10 AM


All times are GMT -6. The time now is 03:25 PM.