![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
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?
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
MIN(some parameters)[0]
The red index tells the code to use the latest min value as seen on the most current bar.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
Sweet. Yes they do. Thx!
|
|
|
|
|
|
#8 |
|
Member
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Member
Join Date: Oct 2009
Location: Sweden
Posts: 73
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
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
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |