Hi, I would like to make a trade at the beginning of the hour and sell it at the end of the hour and then repeat it until I stop the bot. How could I do that? I have this:
using System;
using System.Linq;
using System.Text;
using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class Main1 : Robot
{
[Parameter("Open Hour", DefaultValue = 8, MinValue = 0, MaxValue = 23)]
public int OpenHour { get; set; }
[Parameter("Open Minute", DefaultValue = 1, MinValue = 0, MaxValue = 59)]
public int OpenMinute { get; set; }
[Parameter("Close Hour", DefaultValue = 9, MinValue = 0, MaxValue = 23)]
public int CloseHour { get; set; }
[Parameter("Close Minute", DefaultValue = 0, MinValue = 0, MaxValue = 59)]
public int CloseMinute { get; set; }
[Parameter("Take Profit", DefaultValue = 6)]
public int TakeProfit { get; set; }
[Parameter("Take Profit2", DefaultValue = 6)]
public int TakeProfit2 { get; set; }
[Parameter("Stop Loss", DefaultValue = 100)]
public int StopLoss { get; set; }
[Parameter("Stop Loss2", DefaultValue = 100)]
public int StopLoss2 { get; set; }
[Parameter("Volume", DefaultValue = 1000, MinValue = 1000)]
public int Volume { get; set; }
[Parameter("Volume2", DefaultValue = 1000, MinValue = 1000)]
public int Volume2 { get; set; }
[Parameter("Seconds Before", DefaultValue = 1, MinValue = 1)]
public int SecondsBefore { get; set; }
private DateTime _triggerTimeInServerTimeZone;
private DateTime _closeDateTime;
private const string Label = "Robot";
protected override void OnStart()
{
var triggerTimeInLocalTimeZone = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, OpenHour, OpenMinute, 0);
if (triggerTimeInLocalTimeZone < DateTime.Now)
triggerTimeInLocalTimeZone = triggerTimeInLocalTimeZone.AddDays(1);
_triggerTimeInServerTimeZone = TimeZoneInfo.ConvertTime(triggerTimeInLocalTimeZone, TimeZoneInfo.Local, TimeZone);
_closeDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, CloseHour, CloseMinute, 0);
}
protected override void OnTimer()
{
var buyOrderTargetPrice = Symbol.Ask;
ChartObjects.DrawHorizontalLine("buy target", buyOrderTargetPrice, Colors.Blue, 1, LineStyle.DotsVeryRare);
if (Server.Time <= _triggerTimeInServerTimeZone && (_triggerTimeInServerTimeZone - Server.Time).TotalSeconds <= 1)
{
PlaceStopOrder(TradeType.Buy, Symbol, 1000, buyOrderTargetPrice, Label, 100, 6);
}
}
protected override void OnTick()
{
if (DateTime.Now > _closeDateTime)
{
foreach (var position in Positions)
{
ClosePosition(position);
}
}
}
}
}