I wanted to take a Long position when the MACD fast line crossed the slow line in the Primary timeframe but only when the 15 min MACD fast line is also above the slow line..ie the Primary dataseries (eg 5min) and 15 are both up and the 5 has just crossed.
I have enclosed my coding below.BarsArray[1] refers to the 15min dataseries.The program checker won't let me save the strategy as it sees errors at the end of this line:
"if (MACD(BarsArray[1],12, 26, 9)) > (MACD(BarsArray[1],12,26,9).Avg, 1))"
Any help would be appreciated,
Thank you,
John
--------------------------
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// long enrty & exit ONLY
/// </summary>
[Description("long enrty & exit ONLY")]
public class JHMACDXoverLONG : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
// 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(PeriodType.Minute, 15);
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (MACD(BarsArray[1],12, 26, 9)) > (MACD(BarsArray[1],12,26,9).Avg, 1))
// Condition set 1
if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
{
ExitLong("", "");
}
}
#region Properties
[Description("")]
[Category("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
#endregion
}
}
Comment