![]() |
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 240
Thanks: 1
Thanked 2 times in 2 posts
|
I’m trying to create an indicator that calculates a dynamic upper and lower band which should move with price.
I set an initial value of the UpperBand and LowerBand and do a check to see if that value is breached. The problem I’m having is that as soon as a bar is completed, the initial values for UpperBand and LowerBand go to zero. How do I make these values retain their previous value? The chart I’ve attached shows a 30 sec bar chart. The horizontal lines show the UpperBand and LowerBand. If you run the code, you'll see that the values go to zero. Anyone know how I can solve this? Thanks, Taddypole… |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hi Taddypole,
You may want to use double here instead of DataSeries for some of these values. DataSeries store a value for every bar, so are most useful when you want index past values or use as input for an indicator. You are not doing that here, so I replaced DataSeries with doubles and ran for a few minutes -- never saw Upperband and LowerBand hit value of zero with this attached version.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Mar 2007
Location: , ,
Posts: 240
Thanks: 1
Thanked 2 times in 2 posts
|
Thanks Ryan,
That did the trick. Can you explain why dataseries values are not persistent? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
It's a different structure -- you need to set it for every bar. A double value will keep the last value you assigned to it.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Dec 2011
Posts: 15
Thanks: 2
Thanked 2 times in 2 posts
|
TaddyPole - just to clarify further, if you are interested...
A DataSeries is a type of Array... this means it can store many values, *all of which remain persistent*, until they are deleted, modified, or the array reaches it's maximum size. Generally in c# .NET, an array has a maximum size of 2GB. An array stores it's values like this: [first value] [1] [2] [3] [4] [5] [6] [7] [next index]... [last value] You can reference any value in an array via it's index, like this: myArray[0] (this will access the first value) A NinjaTrader DataSeries is a 'First In First Out (FIFO)' array, meaning that the latest value will have the index [0] and the oldest value will have the index [size-1]... You can read more here: http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx If using more than one Bar Period, or Period Type for your charts / indicators, you need to be aware that NinjaTrader DataSeries can also be synchronized with specific members of BarsArray[], though this is beyone the scope of this post. Hopefully that's of some help. PS - simply put, to set the 'latest' value in the array, use: myArray.Set( myValue ); To retrieve the latest value, and assign it to a variable, use something along the lines of: myVariable = myArray[ 0 ]; J
Last edited by j2496i; 07-31-2012 at 09:38 AM.
|
|
|
|
|
The following user says thank you to j2496i for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Creating Persistent Indicator | Eubie | Indicator Development | 5 | 10-07-2011 09:12 AM |
| Persistent Forex position | astrolobe | Version 7 Beta General Questions & Bug Reports | 5 | 11-01-2010 05:57 AM |
| Is there a way to draw a persistent marker on a bar? | tradefaz | General Programming | 1 | 09-18-2008 08:17 AM |
| Is the Zen-fire Connection Persistent? | mgbloomfield | Connecting | 2 | 06-02-2008 11:50 AM |
| Persistent Orders That Do Not Require Renewal | whitmark | Suggestions And Feedback | 1 | 08-02-2007 06:17 AM |