Accokeek, USA
Experience: Intermediate
Platform: NT & TOS
Trading: ES RUT
Posts: 92 since Mar 2011
Thanks Given: 17
Thanks Received: 24
|
Good day,
I was searching for two simple edits to two indicators in the Elite area.
Can someone take a look and see if what I am seeking is easy to accomplish?
And a side question, does anyone know who can take the TOS code and convert to Ninja?
Your assistance is greatly appreciated!
Regards, Ky
(1)Add color up/down to this double stochastic. It's different than the anaDSS.
(2)Add color up/down to all MACD lines and add the option to change MAType to EMA,HMA,SMA,WMA
Here is the code for each:
######################################################################
##################### DOUBLE STOCHASTIC ##################################
######################################################################
//
// Copyright (C) 2008, NinjaTrader LLC <www.ninjatrader.com>.
// 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>
/// Double stochastics
/// </summary>
[Description("Double stochastics")]
[Gui.Design.DisplayName("DoubleStochastics")]
public class DoubleStochastics : Indicator
{
#region Variables
private int period = 10;
private DataSeries p1;
private DataSeries p2;
private DataSeries p3;
#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.Line, "K"));
Add(new Line(Color.Blue, 90, "Upper"));
Add(new Line(Color.Blue, 10, "Lower"));
Lines[0].Pen.DashStyle = DashStyle.Dash;
Lines[1].Pen.DashStyle = DashStyle.Dash;
p1 = new DataSeries(this);
p2 = new DataSeries(this);
p3 = new DataSeries(this);
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
double r = MAX(High, Period)[0] - MIN(Low, Period)[0];
r = r.Compare(0, 0.000000000001) == 0 ? 0 : r;
if (r == 0)
p1.Set(CurrentBar == 0 ? 50 : p1[1]);
else
p1.Set(Math.Min(100, Math.Max(0, 100 * (Close[0] - MIN(Low, Period)[0]) / r)));
p2.Set(EMA(p1, 3)[0]);
double s = MAX(p2, Period)[0] - MIN(p2, Period)[0];
s = s.Compare(0, 0.000000000001) == 0 ? 0 : s;
if (s == 0)
p3.Set(CurrentBar == 0 ? 50 : p3[1]);
else
p3.Set(Math.Min(100, Math.Max(0, 100 * (p2[0] - MIN(p2, Period)[0]) / s)));
K.Set(EMA(p3, 3)[0]);
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries K
{
get { return Values[0]; }
}
[Description("")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, 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 DoubleStochastics[] cacheDoubleStochastics = null;
private static DoubleStochastics checkDoubleStochastics = new DoubleStochastics();
/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
public DoubleStochastics DoubleStochastics(int period)
{
return DoubleStochastics(Input, period);
}
/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
public DoubleStochastics DoubleStochastics(Data.IDataSeries input, int period)
{
if (cacheDoubleStochastics != null)
for (int idx = 0; idx < cacheDoubleStochastics.Length; idx++)
if (cacheDoubleStochastics[idx].Period == period && cacheDoubleStochastics[idx].EqualsInput(input))
return cacheDoubleStochastics[idx];
lock (checkDoubleStochastics)
{
checkDoubleStochastics.Period = period;
period = checkDoubleStochastics.Period;
if (cacheDoubleStochastics != null)
for (int idx = 0; idx < cacheDoubleStochastics.Length; idx++)
if (cacheDoubleStochastics[idx].Period == period && cacheDoubleStochastics[idx].EqualsInput(input))
return cacheDoubleStochastics[idx];
DoubleStochastics indicator = new DoubleStochastics();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Period = period;
Indicators.Add(indicator);
indicator.SetUp();
DoubleStochastics[] tmp = new DoubleStochastics[cacheDoubleStochastics == null ? 1 : cacheDoubleStochastics.Length + 1];
if (cacheDoubleStochastics != null)
cacheDoubleStochastics.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheDoubleStochastics = tmp;
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
{
/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.DoubleStochastics DoubleStochastics(int period)
{
return _indicator.DoubleStochastics(Input, period);
}
/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
public Indicator.DoubleStochastics DoubleStochastics(Data.IDataSeries input, int period)
{
return _indicator.DoubleStochastics(input, period);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.DoubleStochastics DoubleStochastics(int period)
{
return _indicator.DoubleStochastics(Input, period);
}
/// <summary>
/// Double stochastics
/// </summary>
/// <returns></returns>
public Indicator.DoubleStochastics DoubleStochastics(Data.IDataSeries input, int period)
{
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.DoubleStochastics(input, period);
}
}
}
#endregion
######################################################################
###################### MACD ##########################################
#####################################################################
//
// Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
// 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>
/// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
[Description("The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.")]
public class MACD : Indicator
{
#region Variables
private int fast = 12;
private int slow = 26;
private int smooth = 9;
private DataSeries fastEma;
private DataSeries slowEma;
#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, "Macd"));
Add(new Plot(Color.DarkViolet, "Avg"));
Add(new Plot(new Pen(Color.Navy, 2), PlotStyle.Bar, "Diff"));
Add(new Line(Color.DarkGray, 0, "Zero line"));
fastEma = new DataSeries(this);
slowEma = new DataSeries(this);
}
/// <summary>
/// Calculates the indicator value(s) at the current index.
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
{
fastEma.Set(Input[0]);
slowEma.Set(Input[0]);
Value.Set(0);
Avg.Set(0);
Diff.Set(0);
}
else
{
fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);
double macd = fastEma[0] - slowEma[0];
double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1];
Value.Set(macd);
Avg.Set(macdAvg);
Diff.Set(macd - macdAvg);
}
}
#region Properties
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Avg
{
get { return Values[1]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Default
{
get { return Values[0]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Diff
{
get { return Values[2]; }
}
/// <summary>
/// </summary>
[Description("Number of bars for fast EMA")]
[GridCategory("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
/// <summary>
/// </summary>
[Description("Number of bars for slow EMA")]
[GridCategory("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(1, value); }
}
/// <summary>
/// </summary>
[Description("Number of bars for smoothing")]
[GridCategory("Parameters")]
public int Smooth
{
get { return smooth; }
set { smooth = Math.Max(1, 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 MACD[] cacheMACD = null;
private static MACD checkMACD = new MACD();
/// <summary>
/// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public MACD MACD(int fast, int slow, int smooth)
{
return MACD(Input, fast, slow, smooth);
}
/// <summary>
/// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public MACD MACD(Data.IDataSeries input, int fast, int slow, int smooth)
{
if (cacheMACD != null)
for (int idx = 0; idx < cacheMACD.Length; idx++)
if (cacheMACD[idx].Fast == fast && cacheMACD[idx].Slow == slow && cacheMACD[idx].Smooth == smooth && cacheMACD[idx].EqualsInput(input))
return cacheMACD[idx];
lock (checkMACD)
{
checkMACD.Fast = fast;
fast = checkMACD.Fast;
checkMACD.Slow = slow;
slow = checkMACD.Slow;
checkMACD.Smooth = smooth;
smooth = checkMACD.Smooth;
if (cacheMACD != null)
for (int idx = 0; idx < cacheMACD.Length; idx++)
if (cacheMACD[idx].Fast == fast && cacheMACD[idx].Slow == slow && cacheMACD[idx].Smooth == smooth && cacheMACD[idx].EqualsInput(input))
return cacheMACD[idx];
MACD indicator = new MACD();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Fast = fast;
indicator.Slow = slow;
indicator.Smooth = smooth;
Indicators.Add(indicator);
indicator.SetUp();
MACD[] tmp = new MACD[cacheMACD == null ? 1 : cacheMACD.Length + 1];
if (cacheMACD != null)
cacheMACD.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheMACD = tmp;
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
{
/// <summary>
/// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.MACD MACD(int fast, int slow, int smooth)
{
return _indicator.MACD(Input, fast, slow, smooth);
}
/// <summary>
/// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public Indicator.MACD MACD(Data.IDataSeries input, int fast, int slow, int smooth)
{
return _indicator.MACD(input, fast, slow, smooth);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.MACD MACD(int fast, int slow, int smooth)
{
return _indicator.MACD(Input, fast, slow, smooth);
}
/// <summary>
/// The MACD (Moving Average Convergence/Divergence) is a trend following momentum indicator that shows the relationship between two moving averages of prices.
/// </summary>
/// <returns></returns>
public Indicator.MACD MACD(Data.IDataSeries input, int fast, int slow, int smooth)
{
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.MACD(input, fast, slow, smooth);
}
}
}
#endregion
|