Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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 NinjaTrader.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];
// 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");
The easiest way to figure how NT "sees" other indicators is to use the strategy wizard and add it to a simple strategy and then unlock the code to see and copy what it did.
Thanks.
I seemed to me from looking at the code that a new indicator could use output from an different indicator without including the code of that second indicator. So for example, if I (for some bazaar reason) wrote indicator that simply adds up the value of stochastic, RSI, MACD and ATR, and then averages them that indicator would not have to include the formula or code for those indicators. I would simply point to (or call) those indicators and do the adding and dividing in my new indicator. I was not sure if that was correct. It seems to be.
I am beginning to realize that I am going to need to read a book on C# or find some ninjascript tutorial to get what I want out of this application. There are many things I want it to do that it can, but not out of the box.