Hello, I would like to do a backtesting, but it doesnt work. The code calculates the difference between the highest and lowest values of the previous hour.
`public DataSeries series { get; set; }
[Parameter(DefaultValue = 16, MinValue = 0)]
public int OpenHour { get; set; }
[Parameter(DefaultValue = 0, MinValue = 0)]
public int OpenMinute { get; set; }
[Parameter(DefaultValue = 17, MinValue = 0)]
public int CloseHour { get; set; }
[Parameter(DefaultValue = 0, MinValue = 0)]
public int CloseMinute { get; set; }
private const string Label = "Robot";
private DateTime _startDateTime;
private DateTime _closeDateTime;
protected override void OnStart()
{
DateTime TimeNow = TradingDateTime();
_startDateTime = new DateTime(TimeNow.Year, TimeNow.Month, TimeNow.Day, OpenHour, OpenMinute, 0);
_closeDateTime = new DateTime(TimeNow.Year, TimeNow.Month, TimeNow.Day, CloseHour, CloseMinute, 0);
Timer.Start(60);
}
protected override void OnTimer()
{
var sell = Symbol.Bid;
var buy = Symbol.Ask;
var high = MarketSeries.High.Maximum(60);
var low = MarketSeries.Low.Minimum(60);
var diff = Math.Abs((high - low) / Symbol.PipSize);
if (diff > 5)
{
if (TradingDateTime() == _startDateTime)
{
PlaceStopOrder(TradeType.Sell, Symbol, 1000, sell, Label, 5, 10);
PlaceStopOrder(TradeType.Buy, Symbol, 1000, buy, Label, 5, 10);
}
}
if (TradingDateTime() == _closeDateTime)
{
foreach (var position in Positions.FindAll(Label))
{
ClosePosition(position);
}
}
}
public DateTime TradingDateTime()
{
if (this.IsBacktesting)
{
return Server.Time;
}
else
{
return TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local);
}
}`