|
New York NY USA
Experience: Intermediate
Platform: esignal, thinkorswim,
Trading: Stocks
Posts: 122 since Oct 2012
Thanks Given: 63
Thanks Received: 35
|
Hi. First baby steps in indicator creation.
There is an indicator called macd-cross. Which simply checks for crosses of the macd and average line.
I am trying to modify that script to use it with an other indicator. Specifically and indicator called "ergodic" Which basically appears to be a macd style indicator, but based on the TSI. It just seems to give slightly earlier signals than macd.
In any event, in the macd-cross script I do not see how the original MACD indcator is called. It has all the settings for the MACD, but not the code for it, or reference to another script. So I wonder if ninja just automatically executes some other indicator if it is referenced in a script.
I thought that since MACD and ergodic look similar on the the chart that modifying the macd-cross script would be a simple case of swapping variable and a few minor edits.
Can anyone explain how one ninja script calls another? Or I am I just driving down the wrong road.
Thank you.
----
here is the code for macd-cross for reference.
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using .Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Check to see if the MACD has crossed either above or below the Avg line and set the plot to 1.")]
public class MACDCrossCheck : Indicator
{
#region Variables
// Wizard generated variables
private int fast = 12; // Default setting for Fast
private int slow = 26; // Default setting for Slow
private int smooth = 9; // Default setting for Smooth
// User defined variables (add any user defined variables below)
#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.FromKnownColor(KnownColor.Transparent), PlotStyle.Line, "CrossedMarker"));
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
if (CrossAbove(MACD(Fast,Slow,Smooth).Default,MACD(Fast,Slow,Smooth).Avg,1) ||
CrossBelow(MACD(Fast,Slow,Smooth).Default,MACD(Fast,Slow,Smooth).Avg,1) )
CrossedMarker.Set(1);
else
CrossedMarker.Set(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 CrossedMarker
{
get { return Values[0]; }
}
[Description("")]
[GridCategory("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(1, value); }
}
[Description("")]
[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 MACDCrossCheck[] cacheMACDCrossCheck = null;
private static MACDCrossCheck checkMACDCrossCheck = new MACDCrossCheck();
/// <summary>
/// Check to see if the MACD has crossed either above or below the Avg line and set the plot to 1.
/// </summary>
/// <returns></returns>
public MACDCrossCheck MACDCrossCheck(int fast, int slow, int smooth)
{
return MACDCrossCheck(Input, fast, slow, smooth);
}
/// <summary>
/// Check to see if the MACD has crossed either above or below the Avg line and set the plot to 1.
/// </summary>
/// <returns></returns>
public MACDCrossCheck MACDCrossCheck(Data.IDataSeries input, int fast, int slow, int smooth)
{
if (cacheMACDCrossCheck != null)
for (int idx = 0; idx < cacheMACDCrossCheck.Length; idx++)
if (cacheMACDCrossCheck[idx].Fast == fast && cacheMACDCrossCheck[idx].Slow == slow && cacheMACDCrossCheck[idx].Smooth == smooth && cacheMACDCrossCheck[idx].EqualsInput(input))
return cacheMACDCrossCheck[idx];
lock (checkMACDCrossCheck)
{
checkMACDCrossCheck.Fast = fast;
fast = checkMACDCrossCheck.Fast;
checkMACDCrossCheck.Slow = slow;
slow = checkMACDCrossCheck.Slow;
checkMACDCrossCheck.Smooth = smooth;
smooth = checkMACDCrossCheck.Smooth;
if (cacheMACDCrossCheck != null)
for (int idx = 0; idx < cacheMACDCrossCheck.Length; idx++)
if (cacheMACDCrossCheck[idx].Fast == fast && cacheMACDCrossCheck[idx].Slow == slow && cacheMACDCrossCheck[idx].Smooth == smooth && cacheMACDCrossCheck[idx].EqualsInput(input))
return cacheMACDCrossCheck[idx];
MACDCrossCheck indicator = new MACDCrossCheck();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Fast = fast;
indicator.Slow = slow;
indicator.Smooth = smooth;
Indicators.Add(indicator);
indicator.SetUp();
MACDCrossCheck[] tmp = new MACDCrossCheck[cacheMACDCrossCheck == null ? 1 : cacheMACDCrossCheck.Length + 1];
if (cacheMACDCrossCheck != null)
cacheMACDCrossCheck.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheMACDCrossCheck = 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>
/// Check to see if the MACD has crossed either above or below the Avg line and set the plot to 1.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.MACDCrossCheck MACDCrossCheck(int fast, int slow, int smooth)
{
return _indicator.MACDCrossCheck(Input, fast, slow, smooth);
}
/// <summary>
/// Check to see if the MACD has crossed either above or below the Avg line and set the plot to 1.
/// </summary>
/// <returns></returns>
public Indicator.MACDCrossCheck MACDCrossCheck(Data.IDataSeries input, int fast, int slow, int smooth)
{
return _indicator.MACDCrossCheck(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>
/// Check to see if the MACD has crossed either above or below the Avg line and set the plot to 1.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.MACDCrossCheck MACDCrossCheck(int fast, int slow, int smooth)
{
return _indicator.MACDCrossCheck(Input, fast, slow, smooth);
}
/// <summary>
/// Check to see if the MACD has crossed either above or below the Avg line and set the plot to 1.
/// </summary>
/// <returns></returns>
public Indicator.MACDCrossCheck MACDCrossCheck(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.MACDCrossCheck(input, fast, slow, smooth);
}
}
}
#endregion
|