help with new time settings
help with new time settings
24 Jul 2013, 03:52
Hi,
I'm using the following (below) to backtest so I get the eastern standard time (NYC) session start to finish
but it doesn't work for live forward testing... it doesn't start the robot till I make activeTime = startTime.AddHours(0);
does this have to do with the new time settings?
Is there and easier way to do what I'm trying to do?
currently my broker shows UTC+3 and my local gui offset is set to UTC-4
here's my code:
private DateTime startTime;
private DateTime activeTime;
private DateTime stopTime;
protected override void OnStart()
{
startTime = Server.Time.Date;
activeTime = startTime.AddHours(21);
stopTime = startTime.AddHours(45);
protected override void OnTick()
{
if (Server.Time < activeTime)
return;
Replies
gorin
24 Jul 2013, 12:44
Hi Balena,
Run this code and change TimZones settings to see the output of server time each time:
namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC)] public class NewRobot : Robot { private DateTime startTime; private DateTime activeTime; private DateTime stopTime; protected override void OnStart() { startTime = Server.Time.Date; activeTime = startTime.AddHours(9); stopTime = startTime.AddHours(45); Print(startTime); Print(activeTime); Print(stopTime); } protected override void OnTick() { if (Server.Time < activeTime) return; Print(Server.Time); } } }
I hope the above helps.
@gorin
gorin
24 Jul 2013, 12:46
Sorry use this one instead:
// ------------------------------------------------------------------------------- // // This is a Template used as a guideline to build your own Robot. // Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API. // // ------------------------------------------------------------------------------- using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Requests; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.EasternStandardTime)] public class NewRobot : Robot { private DateTime startTime; private DateTime activeTime; private DateTime stopTime; protected override void OnStart() { startTime = Server.Time.Date; activeTime = startTime.AddHours(9); stopTime = startTime.AddHours(45); Print("Server.Time = {0}", Server.Time); Print("startTime = {0}", startTime); Print("activeTime = {0}", activeTime); Print("stopTime = {0}", stopTime); } protected override void OnTick() { if (Server.Time < activeTime) return; Print("Robot started at Server.Time = {0}", Server.Time); } } }
@gorin
Balena
24 Jul 2013, 16:55
RE:
Sorry use this one instead:
// ------------------------------------------------------------------------------- // // This is a Template used as a guideline to build your own Robot. // Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API. // // ------------------------------------------------------------------------------- using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Requests; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.EasternStandardTime)] public class NewRobot : Robot { private DateTime startTime; private DateTime activeTime; private DateTime stopTime; protected override void OnStart() { startTime = Server.Time.Date; activeTime = startTime.AddHours(9); stopTime = startTime.AddHours(45); Print("Server.Time = {0}", Server.Time); Print("startTime = {0}", startTime); Print("activeTime = {0}", activeTime); Print("stopTime = {0}", stopTime); } protected override void OnTick() { if (Server.Time < activeTime) return; Print("Robot started at Server.Time = {0}", Server.Time); } } }
Thanks for your help!
Just so I understand... does this allow me to run 17:00:00 NYC day 1 to 17:00:00 day 2 (ie the full 24 hr session), or is this only the NYC session? I need the full 24
@Balena
Balena
24 Jul 2013, 17:05
RE: RE:
gorin said:Sorry use this one instead:
// ------------------------------------------------------------------------------- // // This is a Template used as a guideline to build your own Robot. // Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API. // // ------------------------------------------------------------------------------- using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Requests; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.EasternStandardTime)] public class NewRobot : Robot { private DateTime startTime; private DateTime activeTime; private DateTime stopTime; protected override void OnStart() { startTime = Server.Time.Date; activeTime = startTime.AddHours(9); stopTime = startTime.AddHours(45); Print("Server.Time = {0}", Server.Time); Print("startTime = {0}", startTime); Print("activeTime = {0}", activeTime); Print("stopTime = {0}", stopTime); } protected override void OnTick() { if (Server.Time < activeTime) return; Print("Robot started at Server.Time = {0}", Server.Time); } } }
Thanks for your help!
Just so I understand... does this allow me to run 17:00:00 NYC day 1 to 17:00:00 day 2 (ie the full 24 hr session), or is this only the NYC session? I need the full 24
nevermind... I think I have it now... thanks again!
@Balena
Balena
24 Jul 2013, 04:19
RE:
Also...
I'm using...
protected override void OnPositionOpened(Position openedPosition)
{
lastExecutedTime = Server.Time;
with this....
if ( Server.Time > lastExecutedTime.AddSeconds(xSeconds)
this also might be where it's holding up my robot from trading live forward...
what should I do?
@Balena