![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Hi all,
I am trying to implement the following from within the variables section and it is throwing an error. private double[] test = SMA(fast)[0]; private double testCurrentBar = test[1]; Then in my code I want to do something like: if (testCurrentBar > 0) ---Note--- I am not really interested in SMA, rather any indicator and getting the value of the indicator for the current bar, last bar, bars back, etc. I'm just tired and it's not clicking, if anyone could lend a hand it would be appreciated.
Last edited by r2kTrader; 05-27-2009 at 02:34 PM.
|
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
r2kTrader,
I really don't understand what you are trying to do. If you want the SMA's value of the current bar just go SMA(Fast)[0]. If you want the previous bar just go SMA(Fast)[1]. Not following your reason for needing double[].
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
Would I need a DataSeries for this? Easier to do if(testCurrentBar - testLastBar > 0) { //do something } Than if(SMA(Fast)[0] - SMA(Fast)[1] > 0) so this is what I am trying to do. I want my code cleaner and more readable. Thanks |
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Doing such an operation will be inefficient for the code. If you only want to compare current and last just create two double variables to store those values. Otherwise you would need to make a whole DataSeries which is essentially doubling the resources of just calling SMA directly.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Josh,
That is what I am asking how to do ![]() Can you spit me a snippet? |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Sep 2008
Posts: 356
Thanks: 1
Thanked 1 time in 1 post
|
i think what Josh is suggesting is
currentVal=SMA(Fast)[0]; prevValue=SMA(Fast)[1]; bool result =currentVal>prevValue?true:false; . not wanting to hijack this thread but to extend it. would calling the dataseries everytime make it recalculate the data for eg, SMA(Fast)[0] calculate the values for alteast <fast> periods and get the current value SMA(Fast)[1] calculate the values for alteast <fast> periods and get the prev value |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Junkone,
Thanks for jumping in. This is what I did: double poCurrentBar = Oscillator(PoFast, PoSlow, PoSmooth)[1]; //not zero because we calc on bar close for this osc - FirstTickOfBar double poOneBarsAgo = Oscillator(PoFast, PoSlow, PoSmooth)[2]; double poTwoBarsAgo= Oscillator(PoFast, PoSlow, PoSmooth)[3]; double poThreeBarsAgo= Oscillator(PoFast, PoSlow, PoSmooth)[4]; But is this efficient? Wouldn't it be better to call it once than 4 times? How come it won't accept double[] poCurrentBar = Oscillator(PoFast, PoSlow, PoSmooth)[1]; It says can't convert type double to type double[] I'm a student of C#, so any help would be appreciated. PS, I like the idea of the bool, would be more efficient.
Last edited by r2kTrader; 05-28-2009 at 06:19 AM.
|
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Josh,
Could you look at my code and let me know if I am calling the Oscillator more than is necessary? I wanted to call it once per bar update and then just load the array and reference the array, but it won't let me do a double[] from a double. |
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
junkone,
When called from within the same script there already is an instance of the indicator in memory so it doesn't recalculate twice. r2kTrader, double[] is an array while Oscillator(...)[1] is a double. That is why you get the cannot convert message. Try this untested code. Unfortunately I cannot provide more assistance than this. You can try searching google for examples. double[] someVar = new double[4]; someVar[1] = Oscillator(..)[1]; Calling Oscillator() four times in your code is no more or less efficient than calling it once since it is already in memory.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#10 | |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
Quote:
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Indicator in strategy? | igorvlassov | Strategy Development | 5 | 12-20-2008 03:19 PM |
| Indicator or strategy? | 5iver | Indicator Development | 3 | 11-12-2008 08:15 AM |
| Strategy into an indicator | paco99 | Indicator Development | 2 | 08-16-2008 11:06 AM |
| Strategy or an Indicator? | ShimonD | General Programming | 1 | 01-24-2008 07:13 AM |
| Using Strategy Wizard to develope Indicator on Indicator | mrlucky1x | Indicator Development | 3 | 08-25-2007 04:09 PM |