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 12-01-2009, 05:47 AM   #1
Precisely
Member
 
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
Default Constant line(MIN(BB bandwidth, period))

With my limited programming skills I'm trying to plot the minimum value of an indicator looking back n periods. I would like that value as a constant line. Any ideas? Tried to modify the constant line indicator without any success. Shouldn't be too difficult, or?
Precisely is offline  
Reply With Quote
Old 12-01-2009, 06:26 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Precisely, do you get any errors in your code or as you apply the script? Did you add an index to the MIN method to return a double value and not a dataseries?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 12-01-2009, 09:35 AM   #3
Precisely
Member
 
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
Default

Oh, I get a lot of errors I'm afraid... I think the core issue though is what you suggest; to index the MIN method. But how do i do that? Using the private double method, or? I'd really appreciate if you could give me an example then I can fiddle with it a bit more.
Precisely is offline  
Reply With Quote
Old 12-01-2009, 09:46 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

MIN(some parameters)[0]

The red index tells the code to use the latest min value as seen on the most current bar.
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-01-2009, 11:50 AM   #5
Precisely
Member
 
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you both for your replies. I'm almost there now, but it doesn't exactly do what I want. Here is the code:

#region Variables

privateint minperiod = 100;

#endregion

protectedoverridevoid Initialize()
{
Add(
new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
CalculateOnBarClose =
true;
Overlay =
false;
PriceTypeSupported =
false;
}

protectedoverridevoid OnBarUpdate()
{
double minimum = MIN(Bollingerbandwidth(2,14), minperiod)[0];
Plot0.Set(minimum);

Please take a look at this picture I uploaded: http://www.pixbox.se/pic_show_id29954163.html If you look at the 2nd last panel you'll see the "constant" minimum value plotted. You see that there is a drop in the last values. Why is that? It is set on exclude weekends and calculate on bar close: false.
Precisely is offline  
Reply With Quote
Old 12-01-2009, 11:54 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Please open the called Bollingerbandwidth script and remove any CalculateOnBarClose reference from the Initialize() - then recompile, and reload the indicator you created fresh by pressing F5 on the chart. Does the value stay stable now?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 12-01-2009, 12:01 PM   #7
Precisely
Member
 
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
Default

Sweet. Yes they do. Thx!
Precisely is offline  
Reply With Quote
Old 12-04-2009, 10:23 AM   #8
Precisely
Member
 
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
Default

Well, it appears it doesn't really do what I want it to do (se the simple code below).

I would like it to take the minimum value of Bollingerband n days back (including checking the latest close) and plot that value as a constant line (for all days), like a support line.

protectedoverridevoid OnBarUpdate()
{
double minimum = MIN(Bollingerbandwidth(2,18), minperiod)[0];
Plot0.Set(minimum);
}

Possible?
Precisely is offline  
Reply With Quote
Old 12-04-2009, 10:57 AM   #9
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Precisely, it seems like you would need to higher then a higher lookback setting for the MIN() method to incorporate more bars back into creating those support / resistance levels.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 12-04-2009, 11:13 AM   #10
Precisely
Member
 
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
Default

I'm only interested in the minimum for the last 100 days or so, but it works as it is, simply not a beautiful solution. But I guess creating a constant line gets too complicated for me anyways. Thanks for your reply.
Precisely is offline  
Reply With Quote
Old 12-04-2009, 11:21 AM   #11
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

You're welcome, then use just DrawLine() in the indicator and no unique tagID > thus you always modify the one plotted line in value and thus might look cleaner for your current evaluation.

http://www.ninjatrader-support.com/H.../DrawLine.html
NinjaTrader_Bertrand 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
draw horizontal line on High/Low on previous day's specific time period MoreYummy Charting 10 10-02-2010 04:44 AM
macd bb line bugman4/u Suggestions And Feedback 1 03-02-2009 05:54 PM
drawing a line above or below a period with the conditions met MoreYummy Automated Trading 3 08-23-2008 03:02 PM
Accessing 5 min indicator on close of 1 min bar altrader Strategy Development 3 04-17-2008 01:47 PM
How do I adapt the constant line indicator? winJR Indicator Development 6 02-03-2008 12:27 PM


All times are GMT -6. The time now is 02:21 AM.