NinjaTrader Support Forum  

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

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 10-07-2008, 08:20 PM   #1
RandyT
Member
 
Join Date: Sep 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default Add indicator line with configurable level

Is it possible to add a horizontal line to an indicator with:

Add(new Line(Color.Gray, SetLevelVar, "whatever"));

where it is possible to configure the level in SetLevelVar through the Indicator parameters?

Since the Add() function much be called in Initialize() I am not finding how I can change this variable and plot the line at different levels.
RandyT is offline  
Reply With Quote
Old 10-07-2008, 10:04 PM   #2
anachronist
Senior Member
 
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
Default

I assume you mean you want to change the level dynamically by passing different parameters to your indicator on each bar. Correct?

To change it dynamically, I would write

Whatever.value = newvalue;

but you need to make sure that there's an entry for "Whatever" in your indicator properties section.

For me, an easier way would simply be to use DrawLine(). The first time you call it, it creates a line. The second time you call it with the same identifier, it simply moves the line to the new location you set.

-Alex
anachronist is offline  
Reply With Quote
Old 10-07-2008, 10:35 PM   #3
RandyT
Member
 
Join Date: Sep 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default

Not quite..

I want to configure horizontal lines in an indicator based on input in the Parameters dialog box.

Depending on the instrument I am trading, I may be looking for the oscillator or plot to reach a different level. I want to be able to configure that in the parameters dialog box. From what I have working now, it is not possible to change the level since the Add() function is called in Initialize().

As I type, it does not make sense that I need this in OnBarUpdate(), but the lines are being created in Initialize() and the system throws an error if I try to create the lines in OnBarUpdate().
RandyT is offline  
Reply With Quote
Old 10-07-2008, 11:28 PM   #4
anachronist
Senior Member
 
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
Default

Well, the first time you load an indicator into a chart, the parameters box shows you options for the line levels you want. However, once, set, you can't change them. I tried this in one of my indicators:

(intitialize)
Add(upperline = new Line(System.Drawing.Color.Silver, 55, "Upper"));

and then I set upperline.Value to some other value and nothing happened. It didn't matter if I set this on every bar in OnBarUpdate() either.

As I said before, your best bet is to call DrawLine() in OnBarUpdate like this:

DrawLine("MyLine", CurrentBar-1, linevalue, 0, linevalue, Color.Gray, DashStyle.Solid, 1);

Linevalue is your parameter. If you call that on every bar, the line should always update its length to span all the bars.

-Alex
anachronist is offline  
Reply With Quote
Old 10-14-2008, 08:39 PM   #5
zeller4
Senior Member
 
Join Date: Sep 2008
Posts: 185
Thanks: 20
Thanked 2 times in 2 posts
Default Sample of This "DrawLine" indicator

Have either of you been able to make a sample of this indicator that the rest of us can test along with you?

Please post and let us know your findings.

KZ
zeller4 is offline  
Reply With Quote
Old 10-14-2008, 09:16 PM   #6
RandyT
Member
 
Join Date: Sep 2008
Posts: 75
Thanks: 0
Thanked 0 times in 0 posts
Default

Not sure I understand your question entirely, but here is what I did to get to a point where I can draw lines in an indicator that have configurable "levels" on the y-axis.

Initialize () {
DrawOnPricePanel = false;
}

OnBarUpdate() {
DrawHorizontalLine("TagName", false, AxisLevel, Color.Yellow, DashStyle.Dot, 1);
}

The only downside to this method is that the lines are selectable and moveable.
(or a feature...) :-)
RandyT 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
Indicator: Using custom events to output the current Level II data book NinjaTrader_Josh Reference Samples 0 03-04-2008 11:40 AM
Level 2 indicator DrDeath Indicator Development 2 02-10-2008 06:00 AM
Bugs with DrawTextFixed and saving templates with configurable fonts Wizard Historical NinjaTrader 6.5 Beta Threads 4 12-12-2007 07:57 AM
Configurable Daily Session Start/End times? Pivots? Drew Historical NinjaTrader 6.5 Beta Threads 3 12-03-2007 07:03 AM
Indicator: Creating your own Level II data book NinjaTrader_Josh Reference Samples 0 09-30-2007 10:52 PM


All times are GMT -6. The time now is 04:16 PM.