NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 05-17-2007, 01:07 PM   #1
Januson
Junior Member
 
Join Date: May 2007
Posts: 13
Thanks: 0
Thanked 0 times in 0 posts
Default Just downloaded NT, translating from TS

Hello...

To get myself at the right track from the beginning, I've a couple of questions.

I'm trying to translate an .ELD file from Tradestation, this .ELD uses a function called XAverageOrig, take a look here:
inputs:
Price(numericseries),
Length(numericsimple);{ this input assumed to be a constant >= 1 }
variables:
SmoothingFactor(1/Length);
ifCurrentBar=1then
XAverageOrig=Price
else
XAverageOrig=XAverageOrig[1]+SmoothingFactor*(Price-XAverageOrig[1]);


I'm a little confused, should I code it as an indicator ie. like SMA or should it be a custom method? I did try to program it as a method:
publicdouble XAverageOrig(IDataSeries price, int length)
{

double smoothingFactor = 1/length;

if (CurrentBar == 1)
return price[0];
else
return XAverageOrig(price, length) + smoothingFactor * (price[0] - XAverageOrig(price, length));



}

But as I feared it behaved like a recursion and killed my CPU

Any help?

Kind regards
Januson

Januson is offline  
Reply With Quote
Old 05-17-2007, 01:20 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

I would code it as an indicator, that way you can code it once and have it available for anything that can use an indicator.

What I would do is create an indicator via the wizard and lets name the plot XAvg in the wizard.

In OnBarUpdate()

Code:
double smoothingFactor = 1 / length;

if (CurrentBar == 1)
    XAvg.Set(Input[0]);
else
  XAvg.Set(XAvg[1] + smoothingFactor * (Input[0] - XAvg[1]));
Note: I use Input[0] which refers to the default value passed into this indicator such as High or Close or Low price, or another indicator for that matter.
NinjaTrader_Ray is offline  
Reply With Quote
Old 05-17-2007, 01:23 PM   #3
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

I should have added that you need to code this as an indicator since you have to maintain an array of calculated values by where a method does not do that for you.

I am referring to accessing the value of XAvg of 1 bar ago.
NinjaTrader_Ray is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

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 Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Downloaded NT but cannot get it to load on computer bobdec Installation and Licensing 9 12-18-2005 06:51 PM


All times are GMT -6. The time now is 12:09 PM.