I am just starting to use NT and am obviously making a few errors creating a strategy using the wizard.
I want to program the following donchian trend breakout strategy:
- Enter long trade at 20 day high (but only if 25 day EMA is above 350 day EMA)
- Enter short trade at 20 day low (but only if 25 day EMA is below 350 day EMA)
- Exit long trade at 10 day low
- Exit short trade and 10 day high
I've clearly got something wrong, as when I backtest there are no results. Here is the code that the wizard produced for me, it would be great if you could tell me where I'm going wrong!:
Description("Enter the description of your strategy here")]
public class DONCHIAN : Strategy
{
#region Variables
// Wizard generated variables
private int dAY20HIGH = 20; // Default setting for DAY20HIGH
private int dAY20LOW = 20; // Default setting for DAY20LOW
private int dAY10LOW = 10; // Default setting for DAY10LOW
private int dAY10HIGH = 10; // Default setting for DAY10HIGH
private int eMA25 = 25; // Default setting for EMA25
private int eMA350 = 350; // Default setting for EMA350
// 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(DonchianChannel(20));
Add(DonchianChannel(20));
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (EMA25 > EMA350
&& DAY20HIGH > DonchianChannel(20).Upper[0]
&& EMA25 == EMA(25)[0]
&& EMA350 == EMA(350)[0])
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (EMA25 < EMA350
&& DAY20LOW < DonchianChannel(20).Lower[0]
&& EMA25 == EMA(25)[0]
&& EMA350 == EMA(350)[0])
{
EnterShort(DefaultQuantity, "");
}
// Condition set 3
if (DAY10LOW == LowestBar(DefaultInput, 10)
&& Position.MarketPosition == MarketPosition.Long)
{
ExitLong("", "");
}
// Condition set 4
if (DAY10HIGH == HighestBar(DefaultInput, 10)
&& Position.MarketPosition == MarketPosition.Short)
{
ExitShort("", "");

Any other ideas as to what can be wrong would be appreciated!
Comment