I am trying out multi-instument strategy and wrote the following code.
The strategy use MSFT 1 minute bar volume to decide when to long or short another stock,
but when I ran the Strategy analyzer, I noticed that all the entries are executed 1 bar later than expected. Can anyone help me out?
Thanks.
namespace NinjaTrader.Strategy
{
public class test1 : Strategy
{
protected override void Initialize()
{
CalculateOnBarClose = true;
Add("MSFT", PeriodType.Minute, 1);
}
protected override void OnBarUpdate()
{
if (BarsInProgress == 0)
{
// Condition set 1
if (Volumes[1][0] > 20000
)
{
EnterLongLimit(DefaultQuantity, Closes[0][0], "");
}
// Condition set 2
if (Volumes[1][0] < 4000
)
{
EnterShortLimit(DefaultQuantity, Closes[0][0] , "");
}
SetStopLoss("",CalculationMode.Ticks, 10, false);
SetProfitTarget("",CalculationMode.Ticks, 10);
}
}
#region Properties
[Description("")]
[Category("Parameters")]
public int V1
{
get { return v1; }
set { v1 = Math.Max(1, value); }
}
#endregion
}
}


Comment