NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

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

Reply
 
Thread Tools Display Modes
Old 04-11-2011, 08:48 AM   #1
zeller4
Senior Member
 
Join Date: Sep 2008
Posts: 185
Thanks: 20
Thanked 2 times in 2 posts
Default Inputs[1]

Hello,

I've modified the SMAFromRangeBars file to an EMAFromMinuteBars file. I'm attempting to use more than one plot so I've added a second BarsInProgress series.

Please tell me if I'm using "Inputs[1]" and "Inputs[2]" and "init" correctly.

Code:

protectedoverridevoid OnStartUp()
{
average = EMA(Inputs[1],period);//private EMA
smoothedAverage = EMA(rawAverage,Smooth);//private EMA (DataSeries,int)
average2 = EMA(Inputs[2],period2);//private EMA
smoothedAverage2 = EMA(rawAverage2,Smooth);//private EMA (DataSeries,int)
init = false;
} 

Code:
if(BarsInProgress == 0)//base chart
{
if (!init)//from OnStartUp
{
rawAverage.Set(Input[0]);
}
else
{
rawAverage.Set(avgValue);
}
if (!init2)//from OnStartUp
{
rawAverage2.Set(Input[0]);
}
else
{
rawAverage2.Set(avgValue2);
}
Value.Set(smoothedAverage[0]); 
EMA2_from_timeBars.Set(smoothedAverage2[0]); 
}
if (BarsInProgress == 1)
{
init = true;
avgValue = average[0];


}
if (BarsInProgress == 2)
{
init2 = true;
avgValue2 = average2[0];


}
Thanks,
Kirk
Attached Files
File Type: zip EMAFromMinuteBars_v02.zip (4.9 KB, 3 views)
zeller4 is offline  
Reply With Quote
Old 04-11-2011, 09:03 AM   #2
zeller4
Senior Member
 
Join Date: Sep 2008
Posts: 185
Thanks: 20
Thanked 2 times in 2 posts
Default

I also added this to the code in OnBarUpdate when I noticed it didn't plot at the higher timeframe:
Code:

if (CurrentBar < 21)
return;
 
zeller4 is offline  
Reply With Quote
Old 04-11-2011, 09:06 AM   #3
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi Kirk,

Inputs is not supported NinjaScript. Indicators have only one input series selection. Using Inputs won't provide any convenience for changing the input series of a secondary series. It will compile and produce a value, but the best practice is using Closes[1], Closes[2] in its place.

http://www.ninjatrader.com/support/h...nstruments.htm
NinjaTrader_RyanM is offline  
Reply With Quote
Old 04-11-2011, 09:13 AM   #4
zeller4
Senior Member
 
Join Date: Sep 2008
Posts: 185
Thanks: 20
Thanked 2 times in 2 posts
Default

Thanks Ryan
zeller4 is offline  
Reply With Quote
Old 04-11-2011, 07:35 PM   #5
zeller4
Senior Member
 
Join Date: Sep 2008
Posts: 185
Thanks: 20
Thanked 2 times in 2 posts
Default Plotting in Tick Charts

Hello Ryan and others,

Can you please tell me how to plot this on tick charts? I've tested a couple things but no success yet.

Thanks,
Kirk
zeller4 is offline  
Reply With Quote
Old 04-12-2011, 08:30 AM   #6
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi Kirk,

For multiseries indicators, it's important to exclude processing until there are objects available. The following statement should help for this:

if (CurrentBar < 0 || CurrentBars[1] < 0) return;

If you are still running into issues, check the log tab of the control center for any error messages.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 07-21-2011, 09:38 AM   #7
zeller4
Senior Member
 
Join Date: Sep 2008
Posts: 185
Thanks: 20
Thanked 2 times in 2 posts
Default

Hi Ryan,

you said:

Quote:
if (CurrentBar < 0 || CurrentBars[1] < 0) return;
not sure if you meant

Code:
 if (CurrentBar < Period || CurrentBars[1] < Period) return;
?

Kirk
zeller4 is offline  
Reply With Quote
Old 07-21-2011, 10:29 AM   #8
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

No, not necessarily. Checking for all CurrentBars[x] < 0 may be the minimum you want to do, but the actual values used will depend how your script is coded - If you reference prior bar values, exact calculations, etc.

These lines are designed to prevent NT from accessing objects that don't exist. To find exactly what's right for your script, try - catch blocks should be used to debug and find when it runs into this type of exception.
http://www.ninjatrader.com/support/f...ead.php?t=9825
Last edited by NinjaTrader_RyanM; 07-21-2011 at 01:16 PM.
NinjaTrader_RyanM 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
Inputs[] MikeInMA General Programming 3 09-03-2010 09:02 AM
No Commissions calculated despite inputs tooearly Strategy Analyzer 3 07-04-2009 01:37 PM
User defined inputs TedLincoln ATM Strategies (Discretionary Trading) 1 03-04-2009 02:26 PM
Inputs sorted alphabetically? traderT General Programming 3 12-10-2008 09:17 AM
Too many inputs! eDanny Indicator Development 6 07-25-2008 09:25 AM


All times are GMT -6. The time now is 01:19 AM.