![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
I'd like to implement a function as it is possible to do so on TS.
Here is the code : FONCTION T3.AVERAGE.SERIES Inputs: Price(NumericSeries), Periods(NumericSimple); Variables: b(0), b2(0), b3(0), e1(Price), e2(Price), e3(Price), e4(Price), e5(Price), e6(Price), c1(0), c2(0), c3(0), c4(0), f1(0), f2(0), Hot(0.7); if Periods + 1 <> 0 then begin if CurrentBar <= 1 then begin b = Hot; b2 = b * b; b3 = b * b * b; c1 = -b3; c2 = 3 * b2 + 3 * b3; c3 = -6 * b2 - 3 * b - 3 * b3; c4 = 1 + 3 * b + b3 + 3 * b2; f1 = 2 / (Periods + 1); f2 = 1 - f1; end else begin e1 = f1 * Price + f2 * e1[1]; e2 = f1 * e1 + f2 * e2[1]; e3 = f1 * e2 + f2 * e3[1]; e4 = f1 * e3 + f2 * e4[1]; e5 = f1 * e4 + f2 * e5[1]; e6 = f1 * e5 + f2 * e6[1]; end; T3Average.series = c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3; end; the thing is I want to use this "function" in another ninjascript but as you can see "price" is a parameter. I don't know how to proceed. Can anyone help ? |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
I forgot to mention that my "price" formula would be set on my other Ninjascript as follow :
price.Set ((High[0]+Low[0]+Close[0])/3); Value1.Set( 2 * t3average.series(price, p1)); Value2.Set( t3average.series(price, p2)); Value3 = (t3average.series((Value1 - Value2), p3)); |
|
|
|
|
|
#3 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
You need to create this as an indicator in NinjaTrader. Then you can use it as you would an indicator and pass in any input series you wish.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
but how can I code this line :
e1 = f1 * Price + f2 * e1[1]; if I don't declare this variable, I cannot compile my code |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Instead of using "Price" use our Typical series which is what you are looking for.
More information - http://www.ninjatrader-support.com/H...6/Typical.html
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
this won't work because of this line :
Value3 = (t3average.series((Value1 - Value2), p3)); here price = Value1-Value2 so "price" must stay a parameter on the first ninjascript in order to return the correct calculation I don't know if you understand. |
|
|
|
|
|
#7 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Sure I understand.
Then you have to create a DataSeries object to store the calculation of value1 - value2. See this reference sample - http://www.ninjatrader-support.com/v...ead.php?t=7299 Here is some pseudo code based on what you provided: Value1.Set( 2 * t3average.series(Typical, p1)); Value2.Set( t3average.series(Typical, p2)); price.Set(Value1[0] - Value2[0]); Value3 = (t3average.series(price, p3));
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: May 2008
Posts: 111
Thanks: 0
Thanked 0 times in 0 posts
|
Well, I think you misunderstood me.
Let me be clear. I want to create an indicator that use this T3.average.series function I described below. Suppose that I do as you told me to : when NT make the calculation and follow the script, then it will go to the T3.average.series script and will come to this line of the code : e1 = f1 * Price + f2 * e1[1]; on this first Ninjascript, Price is a parameter and not defined. If I defined it on the second Ninjascript, will it replace it by the typical price or anything else alone ? How should I deal with it on the first script ? just declare it as a dataseries and set no value ? am I clear ? |
|
|
|
|
|
#9 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Yes you are clear.
Create an indicator for this function. By default, you will use the property "Input" which refers to the data series passed into the indicator method. The indicator method will look something like: myIndicator(DataSeries input, int Periods) then in your second script you would call: myIndicator(Typical, PeriodsValue) Take a look at the SMA indicator source to get an idea of how Input is used.
Ray
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Use of Log function | MicroAl | General Programming | 4 | 05-07-2008 12:50 PM |
| a function that does this | HelloHello | Automated Trading | 1 | 09-13-2007 03:24 AM |
| Replay function | jrswindle | Suggestions And Feedback | 1 | 05-11-2007 11:07 PM |
| function in com or dll | smiths | Connecting | 6 | 01-31-2007 09:21 AM |
| playback function | jc3 | Suggestions And Feedback | 4 | 04-06-2005 11:35 AM |