I have strategy that is not executing. Since I am new the coding I am not sure where the problem is . Can someone check it and let me know why it does not place order etc...It is simple SMA crossover (10, 25) to place the order. I use stop loss and training stops also. Here is the code.
thanks in advance
Bill
#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>
/// Cross simple MA 10 and 25
/// </summary>
[Description("Cross simple MA 10 and 25")]
public class BillMACross : Strategy
{
#region Variables
// Wizard generated variables
private int pos1 = 2; // Default setting for Pos1
private int pos2 = 2; // Default setting for Pos2
private int fastMA = 10; // Default setting for FastMA
private int slowMA = 25; // Default setting for SlowMA
private int psize = 1; // Default setting for Psize
// 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()
{
SetStopLoss("LLong1", CalculationMode.Ticks, 4, false);
SetTrailStop("LLong2", CalculationMode.Ticks, 5, false);
SetStopLoss("Short1", CalculationMode.Ticks, 4, false);
SetTrailStop("Short2", CalculationMode.Ticks, 5, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(Close, SMA(10), 1)
&& CrossAbove(SMA(10), SMA(25), 1))
{
EnterLong(Pos1, "Long1");
EnterLong(Pos2, "Long2");
}
// Condition set 2
if (CrossBelow(Close, SMA(10), 1)
&& Position.Quantity > Psize)
{
ExitLong("", "");
}
// Condition set 3
if (CrossBelow(Close, SMA(10), 1)
&& CrossBelow(SMA(14), SMA(25), 1))
{
EnterLong(Pos1, "Short1");
EnterLong(Pos2, "Short2");
}
// Condition set 4
if (CrossAbove(Close, SMA(10), 1)
&& Position.Quantity > Psize)
{
ExitShort("", "");
}
}
Comment