Go Back   NinjaTrader Support Forum > NinjaTrader 7 > 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: 22
Thanks: 3
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: 26,202
Thanks: 487
Thanked 1,840 times in 1,781 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: 22
Thanks: 3
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 94 times in 83 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: 22
Thanks: 3
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 Development 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 Development 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 09:57 PM.

Futures, foreign currency and options 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.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.