NinjaTrader Support Forum  

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 07-26-2011, 06:05 AM   #1
jtfancher
Member
 
Join Date: Mar 2011
Posts: 44
Thanks: 0
Thanked 0 times in 0 posts
Default Converting Strategies to Indicators

Hi - I am not a Ninja coder but have figured out how to create strategies using the Wizard and then editing the script generated. But creating indicators is a different story as I am not as good when jumping into the code. My strategy basically draws arrows based on other indicators, inputs and variables.

Is there an easy way to copy the code for the strategy into an indicator editor and then remove or change lines of code and then save it as an indicator?

Thanks!
jtfancher is offline  
Reply With Quote
Old 07-26-2011, 06:39 AM   #2
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
Default

Hello,

Thanks for the forum post.

Glad to see you looking into working with these.

Yes you can do this. Simply copy everything in between OnBarUpdate() from the strategy into the indicator. Also the variables section as well at the top where you have to expand.

You will then want to delete everything that has to do with orders or strategies in the indicator file side. As an indicator does not have access to order methods and is for display only.

Please let me know if you run into problems.

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Old 07-26-2011, 08:17 AM   #3
jtfancher
Member
 
Join Date: Mar 2011
Posts: 44
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Brett - Here is the code I created. But it gives arrows both directions in most cases which means the conditions are not reacting as expected. What have I done wrong? Thx.


#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("Enter the description of your new custom indicator here")]
public class BullBearBarBreak : Indicator
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// 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.MediumSeaGree n), PlotStyle.TriangleUp, "UpTrigger"));
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.TriangleDown, "DownTrigger"));
Overlay = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{


// Condition set 1
// Finds a bar that closes at the high when the EMA and EMA of MACD are rising
if (High[0] == Close[0]
&& Rising(EMA(13)) == true
&& Rising(EMA(MACD(50, 300, 80).Diff, 1)) == true)
return;
{
UpTrigger.Set(Close[0]);
}

// Condition set 2
// Finds a bar that closes at the low when the EMA and EMA of MACD are falling
if (Low[0] == Close[0]
&& Falling(EMA(13)) == true
&& Falling(EMA(MACD(50, 300, 80).Diff, 1)) == true)
return;
{
DownTrigger.Set(Close[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 UpTrigger
{
get { return Values[0]; }
}

[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 DownTrigger
{
get { return Values[1]; }
}

[Description("")]
[GridCategory("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = 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 BullBearBarBreak[] cacheBullBearBarBreak = null;

private static BullBearBarBreak checkBullBearBarBreak = new BullBearBarBreak();

/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public BullBearBarBreak BullBearBarBreak(int myInput0)
{
return BullBearBarBreak(Input, myInput0);
}

/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public BullBearBarBreak BullBearBarBreak(Data.IDataSeries input, int myInput0)
{
if (cacheBullBearBarBreak != null)
for (int idx = 0; idx < cacheBullBearBarBreak.Length; idx++)
if (cacheBullBearBarBreak[idx].MyInput0 == myInput0 && cacheBullBearBarBreak[idx].EqualsInput(input))
return cacheBullBearBarBreak[idx];

lock (checkBullBearBarBreak)
{
checkBullBearBarBreak.MyInput0 = myInput0;
myInput0 = checkBullBearBarBreak.MyInput0;

if (cacheBullBearBarBreak != null)
for (int idx = 0; idx < cacheBullBearBarBreak.Length; idx++)
if (cacheBullBearBarBreak[idx].MyInput0 == myInput0 && cacheBullBearBarBreak[idx].EqualsInput(input))
return cacheBullBearBarBreak[idx];

BullBearBarBreak indicator = new BullBearBarBreak();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.MyInput0 = myInput0;
Indicators.Add(indicator);
indicator.SetUp();

BullBearBarBreak[] tmp = new BullBearBarBreak[cacheBullBearBarBreak == null ? 1 : cacheBullBearBarBreak.Length + 1];
if (cacheBullBearBarBreak != null)
cacheBullBearBarBreak.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheBullBearBarBreak = 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>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.BullBearBarBreak BullBearBarBreak(int myInput0)
{
return _indicator.BullBearBarBreak(Input, myInput0);
}

/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.BullBearBarBreak BullBearBarBreak(Data.IDataSeries input, int myInput0)
{
return _indicator.BullBearBarBreak(input, myInput0);
}
}
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.BullBearBarBreak BullBearBarBreak(int myInput0)
{
return _indicator.BullBearBarBreak(Input, myInput0);
}

/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.BullBearBarBreak BullBearBarBreak(Data.IDataSeries input, int myInput0)
{
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.BullBearBarBreak(input, myInput0);
}
}
}
#endregion
jtfancher is offline  
Reply With Quote
Old 07-26-2011, 08:41 AM   #4
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
Default

Hello,

I can assist if you have a compile error. However logic issues normally take looking more in depth into the code and do whats called debugging. Please follow this guide on how to do this.

http://www.ninjatrader.com/support/f...ead.php?t=3418

Let me know if I can be of further assistance.
NinjaTrader_Brett is offline  
Reply With Quote
Reply

Tags
converting, indicators, strategies

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
Converting indicators from 6.5 to Ninja 7 problems davis72 NinjaScript File Sharing Discussion 23 07-06-2011 11:37 AM
Removing Indicators and Strategies kenb2004 Strategy Development 1 09-30-2010 08:11 AM
Converting indicators from MT4 (mql4) to Ninjatrader (csv) ppplaci General Programming 3 11-03-2009 12:20 AM
Converting indicators from trade station falcon5 Indicator Development 3 10-17-2008 10:57 AM
NinjaScript Strategies vs Indicators whitmark General Programming 7 08-29-2007 02:55 PM


All times are GMT -6. The time now is 10:44 PM.