Topics
14 Aug 2022, 23:16
 3
 1200
 3
10 Jan 2021, 16:48
 5
 1033
 1
21 Nov 2020, 14:25
 8
 1543
 9
Replies

heinrich.munz
03 Aug 2023, 11:59

RE: run a BackTest via CLI

ncel01 said: 

I think the most important at this stage is to be able to run cBots via CLI, in real time, effectively and without any limitations.

This is already implemented and available. See latest changes

 


@heinrich.munz

heinrich.munz
28 Jul 2023, 17:40

Not only BackTest, but also much - MORE IMPORTANT - Optimization. This is necessary to implement own walk forward optimization strategies!


@heinrich.munz

heinrich.munz
17 Jul 2023, 11:59

RE:

Spotware said:

Dear trader,

Can you please let us know the broker as well?

Best regards,

cTrader Team

Good Question!
After your question I tried Pepperstone International, Pepperstone Europe and IC Markets.
The bug occurs ONLY on the Pepperstone accounts!

 


@heinrich.munz

heinrich.munz
17 Jul 2023, 11:31

RE:

Spotware said:

Dear trader,

Thank you for reporting this issue. Can you please share the code you used to reproduce this problem?

Best regards,

cTrader Team

using cAlgo.API;
using cAlgo.API.Internals;
using System;
using System.Diagnostics;
using System.Linq;

namespace cAlgo.Robots
{
   [Robot(AccessRights = AccessRights.FullAccess)]
   public class Empty : Robot
   {
      DateTime mStartDt;

      protected override void OnStart()
      {
         //Debugger.Launch();
         mStartDt = Time;
      }

      protected override void OnTick()
      {
         if (0 == Positions.Count)
         {
            var investMoney = 10000;
            var lotSize = Symbol.VolumeInUnitsToQuantity(investMoney * Symbol.TickSize / Symbol.TickValue / Symbol.Bid);
            var volume = Symbol.NormalizeVolumeInUnits(Symbol.QuantityToVolumeInUnits(lotSize));
            ExecuteMarketOrder(TradeType.Buy, SymbolName, volume);
         }
         else if (Time - Positions.Last().EntryTime > TimeSpan.FromDays(20))
            Positions.Last().Close();
      }

      protected override void OnStop()
      {
         Print("Symbol: "+ Symbol.Name + " started on " + mStartDt.ToString());
         Print("SwapLong: " + Symbol.SwapLong.ToString());
         Print("SwapShort: " + Symbol.SwapShort.ToString());

         foreach (var hist in History)
         {
            Print("Trade# " + hist.PositionId + ", Swap sum: " + hist.Swap.ToString());
         }
      }
   }
}

Output for EURUSD which is ok:
14/07/2023 22:54:00.000 | CBot instance [Empty, EURUSD, h1] stopped.
14/07/2023 22:54:00.000 | Trade# 5, Swap sum: -13,65
14/07/2023 22:54:00.000 | Trade# 4, Swap sum: -13,65
14/07/2023 22:54:00.000 | Trade# 3, Swap sum: -13,65
14/07/2023 22:54:00.000 | Trade# 2, Swap sum: -13,65
14/07/2023 22:54:00.000 | Trade# 1, Swap sum: -13,65
14/07/2023 22:54:00.000 | SwapShort: 0,29
14/07/2023 22:54:00.000 | SwapLong: -0,73
14/07/2023 22:54:00.000 | Symbol: EURUSD started on 13.03.2023 00:00:00
13/03/2023 02:00:00.000 | CBot instance [Empty, EURUSD, h1] started.

Output for US500 which is NOT ok:
14/07/2023 22:54:00.000 | CBot instance [Empty, US500, h1] stopped.
14/07/2023 22:54:00.000 | Trade# 5, Swap sum: 0
14/07/2023 22:54:00.000 | Trade# 4, Swap sum: 0
14/07/2023 22:54:00.000 | Trade# 3, Swap sum: 0
14/07/2023 22:54:00.000 | Trade# 2, Swap sum: 0
14/07/2023 22:54:00.000 | Trade# 1, Swap sum: 0
14/07/2023 22:54:00.000 | SwapShort: 2,55
14/07/2023 22:54:00.000 | SwapLong: -7,55
14/07/2023 22:54:00.000 | Symbol: US500 started on 13.03.2023 00:00:00
13/03/2023 02:00:00.000 | CBot instance [Empty, US500, h1] started.
 


@heinrich.munz

heinrich.munz
16 Jul 2023, 15:26

Walk forward optimization

Instead of implementing (Walk) Forward Optimization into cTrader, I suggest to release a CLI version of 

a) Automate Back tester and

b) Automate Optimizer

instead.

Reason: People understand completely different things under Walk Forward or just Forward Optimization and there are myriads of ways how to implement those features (see MT5, NinjaTrader, Multicharts64, etc. - all are crab :-(. I am pretty sure that - if Spotware implements (W)FO - for many users it will be disappointing and useless. The only way to make all users happy is to offer an API to use Backtesting and Optimization programmatically just as we use it today manually. Then everybody can implement the (W)FO strategies they'd like to have.

The good news for Spotware is, that there is a very simple way to realize this: Just release the optimizer and the backtester as a CLI implementation as you have done in cTrader V4.8 for the real-time trader. Of course the optimizer and the backtester API must have all the setting parameters possibilities as we have it today in the IDE version. This CLI programs then can be called by self written (W)FO strategies and no one can complain about the bad implementation of WFO. 

 


@heinrich.munz

heinrich.munz
12 May 2023, 11:29

RE:

ncel01 said:

This was a Spotware demonstration of the console, I see.

Apparently it was intended to be released with cTrader 4.2 (Nov 2021), one year and a half ago, but hasn't been released yet. 

I wonder what priority has been given to this..

I'll maybe be able to convert all my cBot code to MT4/5 sooner than this is made available..

60MB: seems to be a lot of memory usage for a simple console. More than the memory used by MT4/5.

Also being limited to the cBot default parameters makes the console useless, from my point of view. Moreover, this doesn't make much sense to me, reason:

Cbot parameters when defined in cTrader remain there even when closing and launching the application again, meaning that these are stored somewhere in the server. So, why not an option to use these values (defined in cTrader user interface) when running the cBots through the console?

Last but not least:

As expected, this video shows that not only with me cTrader gets unresponsive.

>"meaning that these are stored somewhere in the server"
No, they are not stored in the server but on the client PC in the environment of the cTrader application.
However, it was said in the demo video that the final release will have the ability to pass the parameters in a file...

What is bothering me much more is the fact that the cTrader console can be used for live trading ONLY - as I understand it.
What I urgently need is the feature to use backtesting via the console ()or even better via an API) and even more urgent to use the genetic optimization programmatically so that it is possible to implement remote controlled high sophisticated optimization strategies in C# like Walk Forward Optimization etc.
 


@heinrich.munz

heinrich.munz
10 May 2023, 07:41 ( Updated at: 10 May 2023, 07:42 )

RE:

ncel01 said:

Dear cTrader team,

Will this be a standalone app or, can it only be launched with cTrader?

Thanks.

Yes it will be stand alone. 
See this demo video of cTrader Console starting at around 29Min, 47 Secs

 

 


@heinrich.munz

heinrich.munz
18 Mar 2023, 21:15 ( Updated at: 21 Dec 2023, 09:23 )

Details on a 16 Cores/32 Thread Computer

I made some tests on a 16 Cores/32 Thread Computer. It seems that ctrader Optimization can only make use of the 16 cores. The treads seem to be useless ?!

1st test: Using 50% of the CPU resources (the the speedometer on 50%) 

==> Duration ca. 2 Min, 30 Secs

The CPU resource measurement (8 Gadgets) shows correctly ca. 50%:

 

2nd test: 

Using 100% of the CPU resources (the speedometer on 100%)  

==> RESULT: Duration is the same as if using 50% ca. 2 Min, 30 Secs

==> It doesn't matter if selecting 50% or 100% of CPU resources

 Strange: The CPU resource measurement shows correctly ca. 100%:

 

3rd Test:

Using 2 cTrader instances, each with 50% Speedometer setting

==> Result: Nearly doubled duration

==> Another prove taht cTrader does not make use of the CPU threads but uses only the cores!

 

 


@heinrich.munz

heinrich.munz
16 Mar 2023, 09:25

Stand Alone cBots without cTrader environment just with cAlgo.API.dll

PanagiotisChar said:

heinrich.munz said:

(How) Is it possible to use the cAlgo.API.dll completely stand alone for automated cBots without the whole cTrader graphical environment?

For very sophisticated backtesting and optimizations strategies like walk forward optimization etc. this would be very helpful. 

It would take just a piece of code (i.e. a command line app) which initializes all necessary parts of the cAlgo.API.dll, gets access to the backtest data cache (ticks, bars, etc.) and then calling the cBots Methods...

 

 

Hi there,

It is not possible at the moment. But there is a project called cTrader Console that should reach the market soon and will do exactly that.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 

This are very good news.

However, wouldn't it be a good idea to involve interested parts of the community in a preview of the planned project? Work flow, API, etc.

Or would it even be possible to collaborate in this project? I am an experienced C# programmer with > 10 years experience in programming all kind of trading platforms, last years focusing on cTrader.

 

In lack of a stand alone cTrader version, many years ago, I started to develop a cTrader emulator which lets me run cTrader bots in a standalone environment, including back testing and optimization. However, this is a lot of work for one person, and I am wondering, if anybody would be interested to collaborate with me to bring this stuff further. Maybe in an open-source Git Hub project?


@heinrich.munz

heinrich.munz
08 Mar 2023, 11:59

RE: RE:

ctid1980098 said:

Hi Dennis, 

I have never used "Open API" and can only speak to "FIX API". 

I currently have connections to 16 broker accounts via FIX api and the execution is pretty much seamless across all. I am able to buy and sell across all brokers pretty much at the same time. I have never experienced an issue where I have vastly different execution times across brokers, provided you have a vps.... to reduce latency. 

FIX took me a while to code up and get into the hang of things, but once up and running the system works flawlessly. My client was happy to copy trades across multiple platforms with FIX platform we designed. 

 

 

Can you give us the names of these 16 Brokers. 
I'm curios who they are, supporting FIX

 

Thx

 


@heinrich.munz

heinrich.munz
02 Mar 2023, 10:09

RE: RE:

DelFonseca said:

dthetten said:

Hello

(...)

Thanks

Yes, search for "web scraping"

Web scraping cTrader strategies might not work, especially on fast working scalping algorithms.
Reason: The update frequency of the web sites might be to slow to copy each trade successfully. I.e. the web site say that ROI is updated only every 15 Minutes (for strategy provides, others 1 day), Net and Gross Profit is updated with a 1 minute delay. However there is no information about the delay of new or closed orders in the Positions/History/Transactions Windows...


@heinrich.munz

heinrich.munz
01 Mar 2023, 09:22

RE: Programmatically see copy trading activity

dthetten said:

Hello

I'd like to know if it's possible to programmatically track the copy trading activity of a master account when I subscribe as a follower ?

 

Thanks

IMHO this will not be possible. If it would, anyone could copy the trades themselves and the master trader would not get its fees...


@heinrich.munz

heinrich.munz
14 Feb 2023, 19:26

RE: Quote and Base currencies missing in API

marktbs said:

cAlgo API is missing quote and base instruments information, like Name for example.

For example to get the quote currency (for volume conversion), we need to do funny methods that split Symbol.Name into 2 parts etc.. this is not professional nor universal and does not work with all instruments.

For indexes (US30, F40..) - there is no way at all to get the quote currency, so the only way is to hard-code it.

 

p.s. Additionally would be great to have methods that help with volume conversion from account asset - into quoted asset, or to base units even better.

In the meantime, Spotware have added Base and Quote Information to SymbolInfo. In Asset there is the name and Digits


      //
      // Summary:
      //     Gets the symbol base asset.
      Asset BaseAsset { get; }

      //
      // Summary:
      //     Gets the symbol quote asset.
      Asset QuoteAsset { get; }
 


@heinrich.munz

heinrich.munz
11 Feb 2023, 17:31

Serious bug in backtest grafic mode

PS: Same thing happens if one uses h1 data from server and h1 bars on chart.
The bug does NOT occur, if one uses a data rate which's period time is faster then the bars timeframe.
So it does NOT occur using Tick Data from Server on M1, etc bars and it does also NOT occur using M1 data from server on M2 or more timeframe Bars...


@heinrich.munz

heinrich.munz
03 Feb 2022, 10:36

RE:

amusleh said:

Hi,

In version 4.2 if you call Server.Time inside an indicator that is being used on back tester it will give you the back test time not current time.

When will version 4.2 be available from the brokers? Pepperstone and IC Markets still are on 4.1

 


@heinrich.munz

heinrich.munz
19 Jan 2022, 12:34

amusleh said:

heinrich.munz said:

amusleh said:

Hi,

Sorry, I misunderstood you, I thought you want to get the current back test time on a cBot.

The close time of a bar is the open time of next bar, so there is no need for an extra data collection.

For indicators, the calculate method is called once for each historical bar, and then it's called for each tick.

So for indicators if you call the Server.Time during historical bars it should return the current time not the time of that bar, and that's the correct behavior not a bug.

>>>"The close time of a bar is the open time of next bar" 
Yes, this is true for historical bars, but not for the Last Bar (when IsLastBar == true). If I have set a time frame of lets say 1 hour, there is a time delay of max. 1 hour until I get the current time.  

>>>and then it's called for each tick.
Exactly! And I just need the accurate time of this "each tick". 

So again my question:
How do I get the accurate current back test time on an indicator for each tick after IsLastBar == true which is Corresponding to Bars.ClosePrices[index]???

 

Hi,

This issue will be resolved in cTrader 4.2.

Hi
I recognized that cTrader 4.2 is released now.
How is the current backtest time in an indicator realized?
Does "Time" contain the current backtest time? Or is there Bars.CloseTime[index]? Or both?

 


@heinrich.munz

heinrich.munz
10 Jan 2022, 15:02 ( Updated at: 10 Jan 2022, 15:12 )

RE:

amusleh said:

Hi,

Sorry, I misunderstood you, I thought you want to get the current back test time on a cBot.

The close time of a bar is the open time of next bar, so there is no need for an extra data collection.

For indicators, the calculate method is called once for each historical bar, and then it's called for each tick.

So for indicators if you call the Server.Time during historical bars it should return the current time not the time of that bar, and that's the correct behavior not a bug.

>>>"The close time of a bar is the open time of next bar" 
Yes, this is true for historical bars, but not for the Last Bar (when IsLastBar == true). If I have set a time frame of lets say 1 hour, there is a time delay of max. 1 hour until I get the current time.  

>>>and then it's called for each tick.
Exactly! And I just need the accurate time of this "each tick". 

So again my question:
How do I get the accurate current back test time on an indicator for each tick after IsLastBar == true which is Corresponding to Bars.ClosePrices[index]???

 


@heinrich.munz

heinrich.munz
10 Jan 2022, 14:10 ( Updated at: 21 Dec 2023, 09:22 )

amusleh said:

Hi,

You can always get the current time by using Server.Time: cAlgo API Reference - IServer Interface (ctrader.com)

 

Sorry, no, this does not work either! As you can see from the appended screen shot "Time", Server.Time and Server.TimeInUtc all return the current PC's time in UTC (10.01.2022...)
However, back testing Datetime is something after 08.12.2021 00:00:00 which is the current bar's open time.
So this seems to be a bug! How do I report bugs?

Btw: The easiest way to fix this problem would be to add Bars.CloseTimes[index]. When index points to the last bar (IsLastBar == true), Bars.CloseTimes[index] would hold the current back test time as it also holds the corresponding Bars.ClosePrices[index]


@heinrich.munz

heinrich.munz
15 Mar 2021, 18:13 ( Updated at: 15 Mar 2021, 18:17 )

How can I get London market hours?

By changing the cBots meta data, the cBots time base (property "Time") can be changed to any time zone you like, including time zones doing daylight saving time correction automatically. So you could change the cBots time zone to London time like this:

namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.GMTStandardTime, ...

 

Please note that all time zone names with the word "Standard" in it will lead to a daylight saving time correction.

 

And btw, cTrader does have a way to find out market session times. However, I experienced that they are not correct in the same way as they are not correct in the Trade Window of ctrader.

Example:

         for (int i = 0; i < Symbol.MarketHours.Sessions.Count; i++)
         {
            startDay[i] = Symbol.MarketHours.Sessions[i].StartDay;
            startTime[i] = Symbol.MarketHours.Sessions[i].StartTime;
            endDay[i] = Symbol.MarketHours.Sessions[i].EndDay;
            endTime[i] = Symbol.MarketHours.Sessions[i].EndTime;
         }

 

Hope this helps


@heinrich.munz

heinrich.munz
19 Jan 2021, 18:17

In Backtesting, Ticks are just backward SIMULATED from Minute Date in cTrader and MT4

 

Please note that on cTrader as well as on MT4 in in Backtesting/Simulation the single Ticks you download did not really happen this way. To save download bandwidth, the smallest timeframe which you get for backtest download data from the cTrader and MT4 servers are minute bars with its four values of OHLC (open, high, low and close). From this minute bars, the ticks are backward simulated to build the correct minute bar. This is the reason why you never should trust backtests with the “Tick data from server (accurate)” mode for cBots which are sensitive to small tick changes (i.e. scalper).

This is the reason why there are 3rd party products out there for MT4 like https://eareview.net/tick-data-suite

For cTrader I am not aware of a product to buy, so I created my own solution: Getting REAL tick data from reliable sources (i.e. Dukascopy or Birt’s TDS) and converting them to the backtesting cache format of cTrader. The cache files for cTrader can be found under: C:\Users\USERNAME\AppData\Roaming\BROKER\BacktestingCache\ACCOUNT\SYMBOL\Ticks and they have the filename format of 2021.01.18.tdbc34, one for each day.

 


@heinrich.munz