I'm testing an strategy, but when I print the SMA value I get the SMA value of the previous day. Only one order per day
protected override void Initialize()
{
// Add a 1 Day Bars object to the strategy
Add(PeriodType.Day, 1);
// Note: Bars are added to the BarsArray and can be accessed via an index value
// E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above
// Add simple moving averages to the chart for display
// This only displays the SMA's for the primary Bars object on the chart
Add(SMA(10));
SetTrailStop(CalculationMode.Ticks, 20);
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
// We only want to process events on our primary Bars object (index = 0) which is set when adding
// the strategy to a chart
if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
return;
if (ToTime(Time[0]) >= ToTime(21, 15, 0) && Position.MarketPosition != MarketPosition.Flat)
{
if (Position.MarketPosition == MarketPosition.Long)
ExitLong();
if (Position.MarketPosition == MarketPosition.Short)
ExitShort();
}
if (Position.MarketPosition == MarketPosition.Flat && ToTime(Time[0]) >= ToTime(15, 31, 0)
&& (Time[0].Month != time.Month || Time[0].Day != time.Day))
{
if (SMA(BarsArray[1], 10)[0] < Input[0])
{
EnterLong(1, "Long");
Print("Time: " + Time[0].ToString("yyyy-MM-dd HH:mm:ss") + " SMA: " + SMA(BarsArray[1], 10)[0].ToString() + " Input: " + Input[0].ToString());
}
else if (SMA(BarsArray[1], 10)[0] > Input[0])
{
EnterShort(1, "Short");
Print("Time: " + Time[0].ToString("yyyy-MM-dd HH:mm:ss")+ " SMA: " + SMA(BarsArray[1], 10)[0].ToString() + " Input: " + Input[0].ToString());
}
time = Time[0];
}
}
Best Regards

Comment