Topics
14 Aug 2016, 01:27
 2522
 9
27 Jul 2015, 05:15
 4211
 20
27 Jun 2015, 16:57
 2380
 2
21 May 2015, 02:50
 3119
 2
30 Nov 2014, 01:01
 2737
 5
13 Sep 2014, 18:30
 2938
 3
28 Aug 2014, 01:16
 2736
 1
10 Jul 2014, 05:17
 2688
 2
25 Mar 2014, 18:16
 3350
 4
12 Feb 2014, 20:15
 5185
 5
09 Jan 2014, 05:03
 3207
 5
18 Dec 2013, 02:27
 3437
 6
03 Dec 2013, 07:22
 3609
 10
30 Oct 2013, 16:55
 0
 3087
 3
Replies

Balena
26 Sep 2013, 23:10 ( Updated at: 23 Jan 2024, 13:16 )

RE:

Hi,

let's say I have 5 positions within same robot

the internet connection goes down and then comes back up

I must restart robot

I see you mention in several posts different ways to remember positions... 

but I need help with actual code...

ie...

1.

i look to trade every x number of minutes based on 

protected override void OnPositionOpened(Position openedPosition)
        {
            lastExecutedTime = Server.Time;

so how would I know what lastExecutedTime = ? (code please)

2.

if i have a max position size of 10 and I have 5 befor the disconnect how do I tell the robot this on restart? (code please)

 

thanks!

 

cAlgo_Fanatic said:

If you restart cAlgo or the Robot, it will not resume and remember any positions opened earlier. In order to modify specific positions created by one robot you may set the [label] property.
If you need additional help with the code let us know.

 


@Balena

Balena
25 Sep 2013, 21:16

I see the same behavior...

memory usage runs up during backtest... say from 200k at initial cAlgo launch up to 700k when running a 1 day test...

and when the test is over... memory usage stays the same at 700k and never goes back down until I shut down/relaunch cAlgo

 

 


@Balena

Balena
19 Sep 2013, 21:53

RE:

lec0456 said:

for now, If you leave everything in UTC.  Robot Time, Indicator time, User Time, and don't convert anything you should be ok.  The problem is that as Daylight savings is applied to different regions your calculation for starting a strategy at say 8am ny time or any specific session would have to be changed manually.

ok, everything in code is UTC... but in gui I use UTC-4 for now... so not considering Day Light Savings changes... I should be ok, right?


@Balena

Balena
19 Sep 2013, 07:37

RE:

Balena said:

so... if I start all my strategies at say 21:00:00 UTC currently...

 

after the bug is fixed

 

will I see different results?

more specifically...

I use the following to backtest...

[Robot(TimeZone = TimeZones.UTC)]

  startTime = Server.Time.Date;
            activeTime = startTime.AddHours(21);
            stopTime = startTime.AddHours(44.9);
            resetTime = startTime.AddHours(45);

 

so are my backtesting results not valid?


@Balena

Balena
19 Sep 2013, 07:35

so... if I start all my strategies at say 21:00:00 UTC currently...

 

after the bug is fixed

 

will I see different results?


@Balena

Balena
12 Sep 2013, 18:49

thanks... I found it...

foreach (var pendingOrder in Account.PendingOrders)
       
        {

        Trade.DeletePendingOrder(pendingOrder);

        }


@Balena

Balena
26 Aug 2013, 06:32

RE:

ok... I think I fixed it

 

I changed to this...

 

  [Robot(TimeZone = TimeZones.UTC)]

 

Balena said:

1. I have my gui set to UTC - 4

2. I want to trade Sunday open to 24 hrs later

3. I want to use US Eastern Time Zone

 

It seems my backtesting works correctly, but forward does not and my log show conflicting information it seems...

here's my code...

 

 

namespace cAlgo.Robots
{

    [Robot(TimeZone = TimeZones.EasternStandardTime)]
    public class v7 : Robot
    
    {
    

        private double startingEquity;

        private DateTime startTime;
        private DateTime activeTime;
        private DateTime stopTime;
        private DateTime resetTime;

  protected override void OnStart()
        {

            startTime = Server.Time.Date;
            activeTime = startTime.AddHours(21);
            stopTime = startTime.AddHours(44);
            resetTime = startTime.AddHours(45);
            
            Print("Server.Time = {0}", Server.Time);
            Print("startTime = {0}", startTime);
            Print("activeTime = {0}", activeTime);
            Print("stopTime = {0}", stopTime);            
            Print("resetTime = {0}", resetTime);

 

again... for backtesting it works as I think it should... starting at 17:00:00 local time (which displays in "Events" correctly)

but... 

my log printout shows this when backtesting:

            Server.Time = 8/22/2013 5:05:00  (this is correct)
           startTime =  8/22/2013 12:00:00     (this is not)
           activeTime =  8/22/2013 9:00:00     (this is not)
           stopTime =    8/23/2013 8:00:00   (this is not)
           resetTime =  8/23/2013 9:00:00    (this is not)

 

and when forward testing... 

it starts at 9:00:00..... vs 17:00:00 (5:00:00 Eastern) or 21:00:00 UTC as expected

 again... with my inputs above... backtesting works correct, but forward starts late

 

how can I fix this?

 


@Balena

Balena
06 Aug 2013, 02:02

RE:
Balena said:

does anyone have a list of all the different equity open times in UTC for say USD, EUR, GBP, JPY?

 

I have a robot I want to run that would re-start at each open...

 

I found what I need here http://en.wikipedia.org/wiki/List_of_stock_exchange_opening_times


@Balena

Balena
24 Jul 2013, 17:05

RE: RE:
Balena said:
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, 16:55

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


@Balena

Balena
24 Jul 2013, 04:19

RE:
Balena said:

       

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;

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

Balena
24 Jul 2013, 03:55

RE:
cAlgo_Development said:

Server time method returns UTC time now. Before that it was in your broker's server time zone. The simplest way is to add server time offset to the time you got from Server.Now. For example if my broker's server is located in UTC+3 time-zone I can do following:

	DateTime serverLocalTime = Server.Time.AddHours(3);
	
	startTime = serverLocalTime.Date;
	activeTime = startTime.AddHours(0);
	stopTime = startTime.AddHours(24);

But when you use activateTime and stopTime later you can compare them only with local (adjust) server time.

Another solution is to count activate and stop time in UTC, i.e. I can activate my your robot in 21:00 UTC instead of 00:00 local server time (if my broker's time offset was UTC+3).

 

Hi... I used my code above with 21:00 UTC for activate... this works fine for backtest... but when I click to live forward the robot doesn't start

help please...


@Balena

Balena
16 Jul 2013, 18:03

RE:
adaled said:

Why is the events tab preferable to the history? Just curious.

both should give same info... but in events you can see order in which things happened (esp important if you are scaling in and out of positions)


@Balena

Balena
16 Jul 2013, 06:02 ( Updated at: 19 Mar 2025, 08:57 )

RE:
cAlgo_Development said:

This is strange. It works properly on all PCs that we have tested.

 

Can you send us the example of your output file? Do output from cAlgo backtesting history tab and cTrader history tab have the same blank cells? We also need to now your Windows culture and version of Microsoft Office.

You can post everything here or send to support@ctrader.com

Hi,

I'm using cAlgo for backtesting...

you findings are correct about exporting to excel from the "History" tab... prices do show

but... try exporting from the "Events" tab; it doesn't show prices as I described...

thinking it's a bug

cheers ;-)


@Balena

Balena
15 Jul 2013, 17:12 ( Updated at: 19 Mar 2025, 08:57 )

RE: RE:Please reply my post#12.
fxMinnow said:
cAlgo_Fanatic said:

Thank you for the information provided. This helps the investigation. We still require some additional information, if you could send us an email to support@ctrader.com with the following:

Account Number
Location (Country)
Frozen currency pair (does that happen for all pairs or specific ones)
Date and Time of freezing( or other trading issue experienced)
Do freezes happen on the Web and Windows at the same moment?

Please reply my post #12 in this thread.

 

see here... http://www.spotware.com/pdf/Overview.pdf page 12-13 the allow broker mark-ups and changing of spreads on "the fly"


@Balena

Balena
18 Jun 2013, 02:43

RE:
cAlgo_Fanatic said:

The Position.NetProfit/Position.GrossProfit is available.

I'm using these per your example in the reference guide... but I can't get it to give a correct amount... is it in pips?

it's like it's only counting on trade in a position that has 10 trades (scaling in)

Also, I now have unique labels for each pair running the same strategy.. How can I get the net p/l of all trades with the same label?

 

Thanks!


@Balena

Balena
16 May 2013, 23:05

I agree... at least give us a toggle switch to include/not include in display gui...

but... easy enough, I coded it in


@Balena

Balena
16 May 2013, 18:31

thanks support...

but that's not what I'm seeing...

my profit target of 100 is reached (10,000 starting equity + 100) ; see equity column

but when the position is closed at 10,100...  I end up with only 10, 089

what is causing this difference from desired target to ending result?

notice all closing prices are the same...

does you equity calculation not include commissions maybe?

please see pic

 


@Balena

Balena
16 May 2013, 05:32

RE:
Lgon said:

Hello,

I need to get the high and low of a specific time frame (e.g. 8am EST and 10 am EST - defined by input) to build a breakout range robot.

Can someone please help me with the code?

Thanks

here's what I use... you can set the hours you want it to collect high & lows...

private DateTime startTime;
 private DateTime activeTime;
 private DateTime stopTime;

private double myEquityLow;

private double myEquityHigh;

private double myEquitySnapShot = 0;;

startTime = Server.Time.Date;

activeTime = startTime.AddHours(5);

stopTime = startTime.AddHours(7);

myEquityLow = myEquityLow;

myEquityHigh = myEquityHigh;

myEquitySnapShot myEquitySnapShot;

 

 

then use conditionals...

 

if(Server.Time > activeTime && Server.Time < stopTime && equitySnapShot =0)

  {        
        

myEquityLow = Account.Equity;

myEquityHigh = Account.Equity

equitySnapShot = 1
        } 

 

if(Server.Time > activeTime && Server.Time < stopTime && Account.Equity < myEquityLow)    

        {        
        myEquityLow = Account.Equity;
        } 

if(Server.Time > activeTime && Server.Time < stopTime && Account.Equity < myEquityHigh)    

        {        
        myEquityHigh = Account.Equity;
        } 


@Balena

Balena
19 Dec 2012, 21:44

thanks for inquiring...

I'm looking to do something like...

if( X < previous Bid)

do this...

or

if (X > previous Offer )

do this...

 

thanks for your help!


@Balena