Vor einiger Zeit bin ich von TradeSignalOnline Terminal auf NinjaTrader umgestiegen und da ich das Programmieren von Handelssystemen (bzw. Programmieren allgemein) nicht gelernt habe, sondern auf diesem Gebiet autodidaktisch unterwegs bin, werde ich von C# jetzt natürlich fast erschlagen im Vergleich zu Equilla. Daher bitte ich um Nachsicht, sollte ich Pippifax-Lösungen, die ich irgendwie gefunden habe, hier als großen Durchbruch präsentieren . C# Newbies (so wie ich) können sich hier Ideen holen und ich bitte die Checker darum: Sollte es bessere/kürzere/elegantere Wege geben, verbessert mich ruhig!!!
Ich vermisse natürlich einige Möglichkeiten bzw. Tools, die bei TST selbstverständlich waren. Das Anzeigen von Plots in Strategien ist so ein Fall und damit fange ich gleich mal an:
In NT kann eine Strategie keine Plots zeichnen; DrawDot() oder Ähnliches schafft hier mMn. nur unzureichend Abhilfe.
Im NT-SupportForum wird dafür Abhilfe angeboten: Per Indikator StrategyPlot. Hier der Code:
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
namespace NinjaTrader.Indicator
{
public class StrategyPlot : Indicator
{
#region Variables
// Parameters:
private int id = 0; // Default setting for Id
#endregion
protected override void Initialize()
{
// New Plot (Default):
Add(new Plot(Color.Orange, PlotStyle.Line, Convert.ToString(id)));
CalculateOnBarClose = false;
Overlay = false;
PriceTypeSupported = false;
}
protected override void OnBarUpdate()
{
// Do Nothing
}
#region Properties
[browsable(false)]
[XmlIgnore()]
public DataSeries Plot
{
get { return Values[0]; }
}
[Description("")]
[Category("Parameters")]
public int Id
{
get { return id; }
set { id = Math.Max(0, value); }
}
#endregion
}
}
#region NinjaScript generated code
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private StrategyPlot[] cacheStrategyPlot = null;
private static StrategyPlot checkStrategyPlot = new StrategyPlot();
public StrategyPlot StrategyPlot(int id)
{
return StrategyPlot(Input, id);
}
public StrategyPlot StrategyPlot(Data.IDataSeries input, int id)
{
if (cacheStrategyPlot != null)
for (int idx = 0; idx < cacheStrategyPlot.Length; idx++)
if (cacheStrategyPlot[idx].Id == id && cacheStrategyPlot[idx].EqualsInput(input))
return cacheStrategyPlot[idx];
lock (checkStrategyPlot)
{
checkStrategyPlot.Id = id;
id = checkStrategyPlot.Id;
if (cacheStrategyPlot != null)
for (int idx = 0; idx < cacheStrategyPlot.Length; idx++)
if (cacheStrategyPlot[idx].Id == id && cacheStrategyPlot[idx].EqualsInput(input))
return cacheStrategyPlot[idx];
StrategyPlot indicator = new StrategyPlot();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Id = id;
Indicators.Add(indicator);
indicator.SetUp();
StrategyPlot[] tmp = new StrategyPlot[cacheStrategyPlot == null ? 1 : cacheStrategyPlot.Length + 1];
if (cacheStrategyPlot != null)
cacheStrategyPlot.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheStrategyPlot = tmp;
return indicator;
}
}
}
}
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
[Gui.Design.WizardCondition("Indicator")]
public Indicator.StrategyPlot StrategyPlot(int id)
{
return _indicator.StrategyPlot(Input, id);
}
public Indicator.StrategyPlot StrategyPlot(Data.IDataSeries input, int id)
{
return _indicator.StrategyPlot(input, id);
}
}
}
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
[Gui.Design.WizardCondition("Indicator")]
public Indicator.StrategyPlot StrategyPlot(int id)
{
return _indicator.StrategyPlot(Input, id);
}
public Indicator.StrategyPlot StrategyPlot(Data.IDataSeries input, int id)
{
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.StrategyPlot(input, id);
}
}
}
#endregion
Ist dieser Indikator vorhanden, kann man durch ihn aus einer Strategie heraus plotten:
#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.Indicator;
using NinjaTrader.Strategy;
#endregion
namespace NinjaTrader.Strategy
{
public class SampleStrategyPlot : Strategy
{
#region Variables
#endregion
protected override void Initialize()
{
CalculateOnBarClose = false;
// Create a multi-time frame strategy
Add(PeriodType.Minute, 3);
/* Add our blank placeholder indicators. The parameter we pass in is used to distinguish the two
indicators from each other. */
Add(StrategyPlot(0));
Add(StrategyPlot(1));
// Set the color for the indicator plots
StrategyPlot(0).Plots[0].Pen.Color = Color.Blue;
StrategyPlot(1).Plots[0].Pen.Color = Color.YellowGreen;
// Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc.
StrategyPlot(0).PanelUI = 1;
StrategyPlot(1).PanelUI = 1;
}
protected override void OnBarUpdate()
{
/* Set the values of our indicators. One of them is set to the High of the primary bar series while the
other is set to the High of the secondary bar series. This effectively creates a multi-time frame plot. */
StrategyPlot(0).Value.Set(High[0]);
StrategyPlot(1).Value.Set(Highs[1][0]);
}
#region Properties
#endregion
}
}
Vor einiger Zeit bin ich von TradeSignalOnline Terminal auf NinjaTrader umgestiegen und da ich das Programmieren von Handelssystemen (bzw. Programmieren allgemein) nicht gelernt habe, sondern auf diesem Gebiet autodidaktisch unterwegs bin, werde ich von C# jetzt natürlich fast erschlagen im Vergleich zu Equilla. Daher bitte ich um Nachsicht, sollte ich Pippifax-Lösungen, die ich irgendwie gefunden habe, hier als großen Durchbruch präsentieren
. C# Newbies (so wie ich) können sich hier Ideen holen und ich bitte die Checker darum: Sollte es bessere/kürzere/elegantere Wege geben, verbessert mich ruhig!!!
Ich vermisse natürlich einige Möglichkeiten bzw. Tools, die bei TST selbstverständlich waren. Das Anzeigen von Plots in Strategien ist so ein Fall und damit fange ich gleich mal an:
In NT kann eine Strategie keine Plots zeichnen; DrawDot() oder Ähnliches schafft hier mMn. nur unzureichend Abhilfe.
Im NT-SupportForum wird dafür Abhilfe angeboten: Per Indikator StrategyPlot. Hier der Code:
#region Using declarations using System; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.ComponentModel; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; #endregion namespace NinjaTrader.Indicator { public class StrategyPlot : Indicator { #region Variables // Parameters: private int id = 0; // Default setting for Id #endregion protected override void Initialize() { // New Plot (Default): Add(new Plot(Color.Orange, PlotStyle.Line, Convert.ToString(id))); CalculateOnBarClose = false; Overlay = false; PriceTypeSupported = false; } protected override void OnBarUpdate() { // Do Nothing } #region Properties [browsable(false)] [XmlIgnore()] public DataSeries Plot { get { return Values[0]; } } [Description("")] [Category("Parameters")] public int Id { get { return id; } set { id = Math.Max(0, value); } } #endregion } } #region NinjaScript generated code namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private StrategyPlot[] cacheStrategyPlot = null; private static StrategyPlot checkStrategyPlot = new StrategyPlot(); public StrategyPlot StrategyPlot(int id) { return StrategyPlot(Input, id); } public StrategyPlot StrategyPlot(Data.IDataSeries input, int id) { if (cacheStrategyPlot != null) for (int idx = 0; idx < cacheStrategyPlot.Length; idx++) if (cacheStrategyPlot[idx].Id == id && cacheStrategyPlot[idx].EqualsInput(input)) return cacheStrategyPlot[idx]; lock (checkStrategyPlot) { checkStrategyPlot.Id = id; id = checkStrategyPlot.Id; if (cacheStrategyPlot != null) for (int idx = 0; idx < cacheStrategyPlot.Length; idx++) if (cacheStrategyPlot[idx].Id == id && cacheStrategyPlot[idx].EqualsInput(input)) return cacheStrategyPlot[idx]; StrategyPlot indicator = new StrategyPlot(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.Id = id; Indicators.Add(indicator); indicator.SetUp(); StrategyPlot[] tmp = new StrategyPlot[cacheStrategyPlot == null ? 1 : cacheStrategyPlot.Length + 1]; if (cacheStrategyPlot != null) cacheStrategyPlot.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheStrategyPlot = tmp; return indicator; } } } } namespace NinjaTrader.MarketAnalyzer { public partial class Column : ColumnBase { [Gui.Design.WizardCondition("Indicator")] public Indicator.StrategyPlot StrategyPlot(int id) { return _indicator.StrategyPlot(Input, id); } public Indicator.StrategyPlot StrategyPlot(Data.IDataSeries input, int id) { return _indicator.StrategyPlot(input, id); } } } namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { [Gui.Design.WizardCondition("Indicator")] public Indicator.StrategyPlot StrategyPlot(int id) { return _indicator.StrategyPlot(Input, id); } public Indicator.StrategyPlot StrategyPlot(Data.IDataSeries input, int id) { 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.StrategyPlot(input, id); } } } #endregionIst dieser Indikator vorhanden, kann man durch ihn aus einer Strategie heraus plotten:
#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.Indicator; using NinjaTrader.Strategy; #endregion namespace NinjaTrader.Strategy { public class SampleStrategyPlot : Strategy { #region Variables #endregion protected override void Initialize() { CalculateOnBarClose = false; // Create a multi-time frame strategy Add(PeriodType.Minute, 3); /* Add our blank placeholder indicators. The parameter we pass in is used to distinguish the two indicators from each other. */ Add(StrategyPlot(0)); Add(StrategyPlot(1)); // Set the color for the indicator plots StrategyPlot(0).Plots[0].Pen.Color = Color.Blue; StrategyPlot(1).Plots[0].Pen.Color = Color.YellowGreen; // Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc. StrategyPlot(0).PanelUI = 1; StrategyPlot(1).PanelUI = 1; } protected override void OnBarUpdate() { /* Set the values of our indicators. One of them is set to the High of the primary bar series while the other is set to the High of the secondary bar series. This effectively creates a multi-time frame plot. */ StrategyPlot(0).Value.Set(High[0]); StrategyPlot(1).Value.Set(Highs[1][0]); } #region Properties #endregion } }