I'm a NT newbie, so I'm learning to code.
I want to set up a very simple system (Tomasini&Jaeckle "Luxor": nice book, indeed!).
For long entries it is as simple as looking at 2 SMA crossover and placing a conditional stop buy order at the high of the candle where the crossover took place.
The order must remain active till it is filled, or a crossover of the SMA's in the opposite direction takes place.
Trades are closed just by an order of the opposite direction being filled (pure "stop and reverse").
This is my code:
public class LuxorTrial1 : Strategy
{
#region Variables
// Wizard generated variables
private int slowMAperiod = 30; // Default setting for SlowMAperiod
private int fastMAperiod = 3; // Default setting for FastMAperiod
private IOrder myLongOrder = null;
private IOrder myShortOrder = null;
// 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, FastMAperiod));
Add(SMA(Close, SlowMAperiod));
CalculateOnBarClose = true;
EntriesPerDirection = 1;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(SMA(Close, FastMAperiod), SMA(Close, SlowMAperiod), 1))
{
myLongOrder = EnterLongStop(0, true, 1, High[1], "MA bull crossover");
if(myShortOrder != null)
{
CancelOrder(myShortOrder);
myShortOrder = null;
}
}
// Condition set 2
if (CrossBelow(SMA(Close, FastMAperiod), SMA(Close, SlowMAperiod), 1))
{
myShortOrder = EnterShortStop(0, true, 1, Low[1], "MA bear crossover");
if(myLongOrder != null)
{
CancelOrder(myLongOrder);
myLongOrder = null;
}
}
}
Now, in backtesting I see the following:

Would any mighty guy be so kind to explaining me what's going wrong and why it doesn't work?
Thanks in advance!
fsprea

Comment