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 12-08-2011, 07:32 PM   #1
stevep3
Junior Member
 
Join Date: Jul 2010
Location: australia
Posts: 20
Thanks: 2
Thanked 0 times in 0 posts
Default EMA changes color according to slope

Do we have a code for EMA green when up andsteep, red for down and steep, black for neither of these?

I found this code which looks interesting, posted by a member and pasted it in but it shows error on the last line ' }expectation' I am clueless about coding, but I thought that I might be lucky if I just pasted it into a new indicator.

Can anyone help?



// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//

#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Exponential Moving Average. The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMACOLORS2 applies more weight to recent prices than the SMA.
/// </summary>
[Description("The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMACOLORS2 applies more weight to recent prices than the SMA.")]
public class EMACOLORS2 : Indicator
{
#region Variables
private int period = 14;
private int ema34slope = 0;
private double radToDegrees = 180/Math.PI; // to convert Radians to Degrees for slope calc
private int angle1 = 30;
private int angle2 = 60;
#endregion

/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.Green, "EMAup"));
Add(new Plot(Color.Maroon, "EMAdown"));
Add(new Plot(Color.Red, "EMAslopedown"));
Add(new Plot(Color.LimeGreen, "EMAslopeup"));
Add(new Plot(Color.Gray, "EMAflat"));
Plots[0].Pen.Width = 2;
Plots[1].Pen.Width = 2;
Plots[2].Pen.Width = 2;
Plots[3].Pen.Width = 2;
Plots[4].Pen.Width = 2;
Plots[0].Pen.DashStyle = DashStyle.Dash;
Plots[1].Pen.DashStyle = DashStyle.Dash;
Plots[2].Pen.DashStyle = DashStyle.Dash;
Plots[3].Pen.DashStyle = DashStyle.Dash;
Plots[4].Pen.DashStyle = DashStyle.Dash;
Overlay = true;
PriceTypeSupported = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(CurrentBar<Period) return;
ema34slope = (int)(radToDegrees*(Math.Atan((EMA(34)[0]-(EMA(34)[1]+EMA(34)[2])/2)/1.5/TickSize)));
if(Rising(EMA(Period)))
{
if(ema34slope>=angle2)
{
EMAslopeup.Set(1,EMA(Period)[1]);
EMAslopeup.Set(EMA(Period)[0]);
}
else
if (ema34slope>=angle1)
{
EMAup.Set(1,EMA(Period)[1]);
EMAup.Set(EMA(Period)[0]);
}
else
{ EMAflat.Set(1,EMA(Period)[1]);
EMAflat.Set(EMA(Period)[0]);
}
}
else
{ if(ema34slope<=-angle2)
{
EMAslopedown.Set(1,EMA(Period)[1]);
EMAslopedown.Set(EMA(Period)[0]);
}
else
if (ema34slope<=-angle1)
{
EMAdown.Set(1,EMA(Period)[1]);
EMAdown.Set(EMA(Period)[0]);
}
else
{ EMAflat.Set(1,EMA(Period)[1]);
EMAflat.Set(EMA(Period)[0]);
}
}
}
stevep3 is offline  
Reply With Quote
Old 12-09-2011, 04:13 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 25,780
Thanks: 432
Thanked 1,685 times in 1,643 posts
Default

I would suggest you check into the EMA Slope color script shared here - http://www.ninjatrader.com/support/f...1&pp=15&page=3

It should be close to what you seek.
NinjaTrader_Bertrand is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Bertrand for this post:
Old 12-09-2011, 10:40 PM   #3
stevep3
Junior Member
 
Join Date: Jul 2010
Location: australia
Posts: 20
Thanks: 2
Thanked 0 times in 0 posts
Default

Thanks Bertrand

That's very useful.

Also, if an indicator exists where the color changes once it has moved up a couple of points, or once it reaches a certain angle, that would be useful too.
stevep3 is offline  
Reply With Quote
Old 12-10-2011, 09:41 AM   #4
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 93 times in 82 posts
Default

stevep3, unfortunately we do not have such an example. I recall quite a few posts have been devoted to that subject, so you could search the forum for "angle" or "slope".
NinjaTrader_Austin is offline  
Reply With Quote
Old 12-10-2011, 03:02 PM   #5
stevep3
Junior Member
 
Join Date: Jul 2010
Location: australia
Posts: 20
Thanks: 2
Thanked 0 times in 0 posts
Default

NinjaTrader_Austin

Thanks for your reply.

I will follow your advice.
stevep3 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
Indicator slope color xaugh Indicator Development 1 03-29-2011 03:41 AM
Slope of EMA jimwolfe General Programming 1 06-01-2010 05:29 AM
EMA Slope Histogram - Help with Color Changes dwalls Indicator Development 10 10-01-2009 09:06 AM
Testing Slope of 21-Day EMA StarBright2009 General Programming 1 09-24-2009 06:42 AM
Slope of EMA Creamers Indicator Development 2 04-13-2007 07:03 AM


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

FULL RISK DISCLOSURE: Futures trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.