Basically I copy + pasted the SMA crossover strategy. To which I added the part inside the [red] tags.
/// </summary>
[Description("Simple moving average cross over strategy.")]
public class SampleMACrossOver : Strategy
{
#region Variables
private int fast = 10;
private int slow = 25;
#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()
{
IncludeCommission = true;
SMA(Fast).Plots[0].Pen.Color = Color.Orange;
SMA(Slow).Plots[0].Pen.Color = Color.Green;
Add(SMA(Fast));
Add(SMA(Slow));
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick).
/// </summary>
[red] protected override void OnBarUpdate()
{
double Account = ;//account size reset manually at the beginning of each trade session
double PnL = GetAtmStrategyRealizedProfitLoss;
double CurrentAccount = Account + PnL;
double UsableAccount = CurrentAccount * .66; //leaving a small buffer
int ContractMargin = //commodity being traded;
int MaxContracts = UsableAccount / ContractMargin;
if MaxContracts > 40;
MaxContracts = 40;
if (CrossAbove(SMA(Fast), SMA(Slow), 1))
EnterLong(MaxContracts);
else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
EnterShort(MaxContracts);
}
[/red]
#region Properties
/// <summary>
/// </summary>
[Description("Period for fast MA")]
[Category("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
/// <summary>
/// </summary>
[Description("Period for slow MA")]
[Category("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(1, value); }
}
#endregion
}
}

I need to read the instruction manual.
Comment