NinjaTrader Support Forum implement a function on NT

 Indicator Development Support for the development of custom indicators using NinjaScript.

 08-06-2008, 09:21 AM #1 kuroro13 Senior Member   Join Date: May 2008 Posts: 111 Thanks: 0 Thanked 0 times in 0 posts implement a function on NT 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 ?
 08-06-2008, 09:30 AM #2 kuroro13 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));
 08-06-2008, 09:49 AM #3 NinjaTrader_Ray 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 Use Kinetick, NinjaTrader’s preferred market data service - Learn More Free online training events - View Schedule
 08-06-2008, 10:27 AM #4 kuroro13 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
 08-06-2008, 10:32 AM #5 NinjaTrader_Ray 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 Use Kinetick, NinjaTrader’s preferred market data service - Learn More Free online training events - View Schedule
 08-06-2008, 03:18 PM #6 kuroro13 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.
 08-06-2008, 03:45 PM #7 NinjaTrader_Ray 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 Use Kinetick, NinjaTrader’s preferred market data service - Learn More Free online training events - View Schedule
 08-06-2008, 04:05 PM #8 kuroro13 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 ?
 08-06-2008, 05:31 PM #9 NinjaTrader_Ray 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 Use Kinetick, NinjaTrader’s preferred market data service - Learn More Free online training events - View Schedule

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News and Announcements     News and Announcements Application Technical Support     ATM Strategies (Discretionary Trading)     Automated Trading     Charting     Connecting     Installation and Licensing     Market Analyzer     Miscellaneous Support         Historical Version 7 Beta Threads             Critical Information - Please review             Version 7 Beta General Questions & Bug Reports         Historical NinjaTrader 6.5 Archive             Historical NinjaTrader 6.5 Beta Threads     Strategy Analyzer     SuperDOM and other Order Entry Windows NinjaScript Development Support     General Programming     Indicator Development     Strategy Development NinjaScript Educational Resources     Reference Samples     Tips NinjaScript File Sharing     NinjaScript File Sharing Discussion     Version 7 Indicators     Version 7 Strategies     Version 7 Miscellaneous Suggestions and Feedback     Suggestions And Feedback

 Similar Threads Thread Thread Starter Forum Replies Last Post MicroAl General Programming 4 05-07-2008 12:50 PM HelloHello Automated Trading 1 09-13-2007 03:24 AM jrswindle Suggestions And Feedback 1 05-11-2007 11:07 PM smiths Connecting 6 01-31-2007 09:21 AM jc3 Suggestions And Feedback 4 04-06-2005 11:35 AM

All times are GMT -6. The time now is 01:51 PM.

 -- Fixed Width ---- Fluid Width NinjaTrader Support Forum - Archive - Top