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 01-01-2009, 07:41 PM   #1
playafh69
Senior Member
 
Join Date: Dec 2008
Posts: 193
Thanks: 0
Thanked 1 time in 1 post
Default ATR Indicator

I want to develop a simple indicator. I tried using the ninjascripts but I just can't figure it out. I stumbled upon a code called a ATR trailing which i downloaded off this website. What i want is very similar, just one thing thats different. The indicator takes an ATR and multplies it times 3 and plots it on the chart as a dot as a trailing method. What I want is to simply take that multiple (just the number and use the draw text fixed functions to simply write that number on the corner of the main chart. So if the ATR is 2, i want it to write on the corner on the first display panel ATR STOP:6
Here is the code i got for the original ATR trailing function.. Here is the link to the file http://www.ninjatrader-support2.com/...ks.php?catid=1

[Gui.Design.DisplayName("ATRTrailing")]
public class ATRTrailing : Indicator
{
#region Variables
private double ATRTimes = 4;
private int period = 10;
private int counter = 0;
private double ratched = 0.005;
private double ratchedval = 0;

private double SigClose = 0;
private bool shortval;
private bool longval;
private DataSeries Plotset;
private DataSeries Sideset; // Short == 0 Long ==1
#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.Red, PlotStyle.Dot, "ATR Trailing Dn"));
Add(new Plot(Color.Blue, PlotStyle.Dot, "ATR Trailing Up"));
CalculateOnBarClose = true; // Call 'OnBarUpdate' only as a bar closes
Overlay = true; // Plots the indicator on top of price
Plotset = new DataSeries(this);
Sideset = new DataSeries(this);
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < period)
return;

if (Low[0] < Low[1] )
{
Sideset.Set(0);
}
if (High[0] > High[1] )
{
Sideset.Set(1);
}
ratchedval=(1 - ( counter * ratched));
if (Sideset[1] == 0 )
{
SigClose = MIN(Low,(period))[0];
Plotset.Set(SigClose + Bars.Instrument.MasterInstrument.Round2TickSize((r atchedval*(ATRTimes*ATR(period)[0]))));
}
if (Sideset[1] == 1)
{
SigClose = MAX(High,(period))[0];
Plotset.Set(SigClose - Bars.Instrument.MasterInstrument.Round2TickSize((r atchedval*(ATRTimes*ATR(period)[0]))));
}
if(Sideset[1] == 1 && Low[1] <= Plotset[1])
{
Sideset.Set(0);
SigClose = High[1];
counter = 0;
Plotset.Set( SigClose + Bars.Instrument.MasterInstrument.Round2TickSize((r atchedval*(ATRTimes*ATR(period)[0]))));
Lower.Set(Plotset[0]);
}
if( Sideset[1] == 1 && Low[1] > Plotset[1])
{
Sideset.Set(1);
SigClose = MAX(High,(period))[0];
Plotset.Set(SigClose - Bars.Instrument.MasterInstrument.Round2TickSize((r atchedval*(ATRTimes*ATR(period)[0]))));
if (Plotset[1] > Plotset[0])
Plotset.Set(Plotset[1]);
Upper.Set(Plotset[0]);
}
if(Sideset[1] == 0 && High[1] >= Plotset[1])
{
Sideset.Set(1);
SigClose = High[1];
counter = 0;
Plotset.Set(SigClose - Bars.Instrument.MasterInstrument.Round2TickSize((r atchedval*(ATRTimes*ATR(period)[0]))));
Upper.Set(Plotset[0]);
}
if(Sideset[1] == 0 && High[1] < Plotset[1])
{
Sideset.Set(0);
SigClose = MIN(Low,(period))[0];
Plotset.Set( SigClose + Bars.Instrument.MasterInstrument.Round2TickSize((r atchedval*(ATRTimes*ATR(period)[0]))));
if (Plotset[1] < Plotset[0])
Plotset.Set(Plotset[1]);
Lower.Set(Plotset[0]);
}
counter++;
}
#region Properties
/// <summary>
/// The acceleration step factor
/// </summary>
[Description("Number of ATR Multipliers")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("Number of ATR (Ex. 3 Time ATR) ")]
public double ATRTIMES
{
get { return ATRTimes; }
set { ATRTimes = Math.Max(0, value); }
}
[Description("Period")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("Periods")]
public int Period
{
get { return period; }
set { period = Math.Max(0, value); }
}
/// <summary>
/// Gets the lower value.
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Lower
{
get { return Values[0]; }
}
/// <summary>
/// Get the Upper value.
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Upper
{
get { return Values[1]; }
}
[Description("Ratchet Percent")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("Ratchet Percent")]
public double Ratched
{
get { return ratched; }
set { ratched = Math.Max(0, value); }
}
#endregion
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private ATRTrailing[] cacheATRTrailing = null;

private static ATRTrailing checkATRTrailing = new ATRTrailing();

/// <returns></returns>
public ATRTrailing ATRTrailing(double aTRTIMES, int period, double ratched)
{
return ATRTrailing(Input, aTRTIMES, period, ratched);
}
/// <returns></returns>
public ATRTrailing ATRTrailing(Data.IDataSeries input, double aTRTIMES, int period, double ratched)
{
checkATRTrailing.ATRTIMES = aTRTIMES;
aTRTIMES = checkATRTrailing.ATRTIMES;
checkATRTrailing.Period = period;
period = checkATRTrailing.Period;
checkATRTrailing.Ratched = ratched;
ratched = checkATRTrailing.Ratched;

if (cacheATRTrailing != null)
for (int idx = 0; idx < cacheATRTrailing.Length; idx++)
if (Math.Abs(cacheATRTrailing[idx].ATRTIMES - aTRTIMES) <= double.Epsilon && cacheATRTrailing[idx].Period == period && Math.Abs(cacheATRTrailing[idx].Ratched - ratched) <= double.Epsilon && cacheATRTrailing[idx].EqualsInput(input))
return cacheATRTrailing[idx];

ATRTrailing indicator = new ATRTrailing();
indicator.SetUp();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.ATRTIMES = aTRTIMES;
indicator.Period = period;
indicator.Ratched = ratched;

ATRTrailing[] tmp = new ATRTrailing[cacheATRTrailing == null ? 1 : cacheATRTrailing.Length + 1];
if (cacheATRTrailing != null)
cacheATRTrailing.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheATRTrailing = tmp;
Indicators.Add(indicator);

return indicator;
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ATRTrailing ATRTrailing(double aTRTIMES, int period, double ratched)
{
return _indicator.ATRTrailing(Input, aTRTIMES, period, ratched);
}
/// <summary>
/// Wilder’s Volatility System, developed by and named after Welles
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.ATRTrailing ATRTrailing(double aTRTIMES, int period, double ratched)
{
return _indicator.ATRTrailing(Input, aTRTIMES, period, ratched);
}
/// </summary>
/// <returns></returns>
public Indicator.ATRTrailing ATRTrailing(Data.IDataSeries input, double aTRTIMES, int period, double ratched)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

return _indicator.ATRTrailing(input, aTRTIMES, period, ratched);
}
#endregion
playafh69 is offline  
Reply With Quote
Old 01-01-2009, 10:28 PM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Due to bandwidth constraints we can not assist in coding actual indicators/strategies. You would need to debug your indicator e.g. as per here: http://www.ninjatrader-support2.com/...ead.php?t=3418
NinjaTrader_Dierk 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
ATR plot cptrader Indicator Development 3 12-29-2008 09:28 AM
Simple ATR w/ EMA Indicator tmoose Indicator Development 1 10-15-2008 08:21 AM
ATR Stop ATI user Strategy Development 8 09-29-2008 10:12 AM
ATR Stoploss RSTLNE Strategy Development 3 09-01-2008 04:47 PM
SetProfitTarget with ATR stefy Strategy Development 2 07-01-2008 09:07 AM


All times are GMT -6. The time now is 01:24 PM.