NexusFi: Find Your Edge


Home Menu

 





how does ninja see another indicator


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one mcteague with 2 posts (0 thanks)
    2. looks_two vegasfoster with 1 posts (1 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 MrYou with 1 posts (0 thanks)
    1. trending_up 3,604 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

how does ninja see another indicator

  #1 (permalink)
 mcteague 
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 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];

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 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();

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

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
Futures True Range Report
The Elite Circle
ZombieSqueeze
Platforms and Indicators
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
  #3 (permalink)
 
MrYou's Avatar
 MrYou 
NC, USA
 
Experience: None
Platform: None Yet
Trading: Guitar
Posts: 403 since Jun 2011
Thanks Given: 618
Thanks Received: 196


Its in the OnBarUpdate(). I've added some formatting to make it a little easier to read:

 
Code
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);
CrossAbove() and CrossBelow() are calling the MACD() indicator for the MACD().Default value and MACD().Avg value, 1 bar back.

See the manual for more info.

Reply With Quote
  #4 (permalink)
 vegasfoster 
las vegas
 
Experience: Intermediate
Platform: Sierra Chart
Broker: Velocity/IB
Trading: 6E
Posts: 1,145 since Feb 2010
Thanks Given: 304
Thanks Received: 844

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.

Reply With Quote
Thanked by:
  #5 (permalink)
 mcteague 
New York NY USA
 
Experience: Intermediate
Platform: esignal, thinkorswim,
Trading: Stocks
Posts: 122 since Oct 2012
Thanks Given: 63
Thanks Received: 35


MrYou View Post
Its in the OnBarUpdate(). I've added some formatting to make it a little easier to read:

 
Code
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);
CrossAbove() and CrossBelow() are calling the MACD() indicator for the MACD().Default value and MACD().Avg value, 1 bar back.

See the manual for more info.


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.

Thanks again

Started this thread Reply With Quote




Last Updated on July 15, 2013


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts