Can you point me to the error in my strategy?
#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 SMAcrossBreakeven2 : Strategy
{
#region Variables
// Wizard generated variables
private int fast = 1; // Default setting for Fast
private int slow = 1; // Default setting for Slow
private double trigger = 100; // Default setting for Trigger
// 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(Close, Fast));
Add(SMA(Close, Slow));
SetStopLoss(CalculationMode.Ticks, 100);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Beginning of Auto-Break-Even
// If a long position is open
if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price + Trigger * ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + trigger * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
}
// If a short position is open
if (Position.MarketPosition == MarketPosition.Short)
{
// Once the price is smaller than entry price - Trigger * ticks, set stop loss to breakeven
if (Close[0] < Position.AvgPrice - trigger * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
}
// Ende of Auto-Break-Even
// Condition set 1
if (CrossAbove(SMA(Close, Fast), SMA(Close, Slow), 1))
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (CrossBelow(SMA(Close, Fast), SMA(Close, Slow), 1))
{
EnterShort(DefaultQuantity, "");
}
}
#region Properties
[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 double Trigger
{
get { return trigger; }
set { trigger = Math.Max(0, value); }
}
#endregion
}
}

Comment