I have created a simple MSCrossOver strategy using the wizard. It has SetStopLoss, SetProfitTarget and SetTrailStop set but they do not seem to make any difference (in the strategy analyser backtests) when I set different target, stops, trailingstops values.
Thanks
The generated code is shown below:
#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.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class MFMAsCrossover : Strategy
{
#region Variables
// Wizard generated variables
private int slowMA = 4; // Default setting for SlowMA
private int fastMA = 2; // Default setting for FastMA
private double limitPercent = 3; // Default setting for LimitPercent
private double stopPercent = 3.000; // Default setting for StopPercent
private double trailingPercent = 0.500; // Default setting for TrailingPercent
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(SMA(FastMA));
Add(SMA(SlowMA));
Add(SMA(FastMA));
Add(SMA(SlowMA));
SetProfitTarget("Enter Long", CalculationMode.Percent, LimitPercent);
SetStopLoss("Enter Short", CalculationMode.Percent, StopPercent, false);
SetTrailStop("Enter Long", CalculationMode.Percent, TrailingPercent, false);
SetProfitTarget("Enter Short", CalculationMode.Percent, TrailingPercent);
SetStopLoss("Enter Long", CalculationMode.Percent, TrailingPercent, false);
SetTrailStop("Enter Short", CalculationMode.Percent, TrailingPercent, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(SMA(FastMA), SMA(SlowMA), 1))
{
EnterLong(DefaultQuantity, "Enter Long");
}
// Condition set 2
if (CrossBelow(SMA(FastMA), SMA(SlowMA), 1))
{
EnterShort(DefaultQuantity, "Enter Long");
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int SlowMA
{
get { return slowMA; }
set { slowMA = Math.Max(4, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int FastMA
{
get { return fastMA; }
set { fastMA = Math.Max(2, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double LimitPercent
{
get { return limitPercent; }
set { limitPercent = Math.Max(0.1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double StopPercent
{
get { return stopPercent; }
set { stopPercent = Math.Max(0.100, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double TrailingPercent
{
get { return trailingPercent; }
set { trailingPercent = Math.Max(0.500, value); }
}
#endregion
}
}
Comment