I am trying to write a strategy to take reading from an index, "^comp" to give me a value in Variable2, and a future what will store a value in Variable3. And then on the primary instruments, base on the reading and value in Variable0 and evaluate values in Variable2 and variable3, I will take either long or short.
Although, I am having trouble to have the script to run. Please help.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class MyCustomStrategy1 : Strategy
{
#region Variables
// Wizard generated variables
private int longValue = 1; // Default setting for MyInput0
private int shortValue = -1; // Default setting for ShortValue
private int stopValue = 0; // Default setting for StopValue
private double stoploss = 0.100; // Default setting for Stoploss
private int quit = 0; // Default setting for Quit
// 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(DEMA(2));
Add(TEMA(1));
Add(DEMA(2));
Add(TEMA(1));
Add(SMA(0));
Add(SMA(2));
Add(DEMA(2));
Add(DEMA(2));
Add(TEMA(1));
Add(DEMA(2));
Add(TEMA(1));
SetStopLoss("", CalculationMode.Percent, Stoploss, false);
Add("^comp", PeriodType.Minute, 5);
Add("CL 07-17", PeriodType.Minute, 5);
Add(SMA(0));
Add(SMA(2));
Add(SMA(0));
Add(SMA(2));
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(SMA(BarsArray[1],0), SMA(BarsArray[1],2), 1))
{
Variable2 = LongValue;
}
// Condition set 2
if (CrossBelow(SMA(BarsArray[1],0), SMA(BarsArray[1],2), 1))
{
Variable2 = ShortValue;
}
// Condition set 1
if (CrossAbove(SMA(BarsArray[2],0), SMA(BarsArray[2],2), 1))
{
Variable3 = LongValue;
}
// Condition set 2
if (CrossBelow(SMA(BarsArray[2],0), SMA(BarsArray[2],2), 1))
{
Variable3 = ShortValue;
}
if (CrossBelow(SMA(BarsArray[0],0), SMA(BarsArray[0],2), 1))
{
Variable0 = ShortValue;
}
if (CrossAbove(SMA(BarsArray[0],0), SMA(BarsArray[0],2), 1))
{
Variable0 = LongValue;
}
// Condition set 1
if (Variable2 == LongValue
&& Variable0 == LongValue)
{
EnterLongLimit(2000, Median[0], "");
}
// Condition set 2
if (Variable2 == ShortValue
&& Variable0 == ShortValue)
{
EnterShortLimit(2000, Median[0], "");
}
// Condition set 1
if (Variable3 == LongValue
&& Variable0 == LongValue)
{
EnterLongLimit(2000, Median[0], "");
}
// Condition set 2
if (Variable3 == ShortValue
&& Variable0 == ShortValue)
{
EnterShortLimit(2000, Median[0], "");
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int LongValue
{
get { return longValue; }
set { longValue = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int ShortValue
{
get { return shortValue; }
set { shortValue = Math.Max(-1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int StopValue
{
get { return stopValue; }
set { stopValue = Math.Max(0, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double Stoploss
{
get { return stoploss; }
set { stoploss = Math.Max(0.100, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int Quit
{
get { return quit; }
set { quit = Math.Max(0, value); }
}
#endregion
}
}
Comment