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 > Indicator Development

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

Reply
 
Thread Tools Display Modes
Old 07-24-2009, 11:35 AM   #1
germano
Member
 
Join Date: Mar 2009
Posts: 56
Thanks: 0
Thanked 0 times in 0 posts
Default Three moving averages

Hi,

Who can help me?
I would like an indicator with three exponential moving averages. What is wrong in your code? (I see only one!)

This is the code:

[Description()]
publicclass EMAs3 : Indicator
{
#region Variables

privateint fast = 7; // Default setting for Fast
privateint average = 14; // Default setting for Average
privateint slow = 21; // Default setting for Slow

#endregion

protectedoverridevoid Initialize()
{
Add(new Plot(Color.Red, "EMA Fast"));
Add(new Plot(Color.DarkViolet, "EMA Average"));
Add(new Plot(Color.Blue, "EMA Slow"));

Overlay = true;
PriceTypeSupported = true;
}

protectedoverridevoid OnBarUpdate()
{
Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Fast)) + (1 - (2.0 / (1 + Fast))) * Value[1]);

Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Average)) + (1 - (2.0 / (1 + Average))) * Value[1]);

Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Slow)) + (1 - (2.0 / (1 + Slow))) * Value[1]);
}

Thank you for your help

germano
germano is offline  
Reply With Quote
Old 07-24-2009, 11:44 AM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

germano,

You cannot do Value.Set for all of them. Value.Set is only used when the indicator has one plot. If your indicator has multiple plots you need to call the appropriate plot names.

Please see the MACD indicator for an example. Please note how the plots are named in the Properties region of the code.
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-24-2009, 12:39 PM   #3
germano
Member
 
Join Date: Mar 2009
Posts: 56
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Josh for suggestion; I am going to study the code of the MACD indicator.

Hello
germano 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
Displaced moving averages ggloor Charting 6 10-11-2009 02:11 AM
Price Data and Moving Averages mainstream Strategy Development 3 02-02-2009 07:27 AM
Displaced moving averages T2020 Charting 2 01-20-2009 09:13 AM
how to chart envelopes on moving averages saltcafe Charting 1 09-01-2008 12:10 PM
Nested moving averages? Burga1 Indicator Development 2 11-16-2007 08:51 AM


All times are GMT -6. The time now is 07:03 PM.