Replies

mpistorius
19 May 2021, 18:06

RE:

amusleh said:

Hi,

We were able to replicate the issue and it will be fixed in future releases, thanks for reporting.

Hi Amusleh,

I just got the 4.0.13 update, but this bug is still present in the latest release...

Regards,
Morné


@mpistorius

mpistorius
30 Mar 2021, 18:47

Hi Panagiotis,

This bug can be reproduced with the simplest of bots, and is still present in cTrader 4.0.


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Bug : Robot
    {

        protected override void OnStart()
        {
            var bars = MarketData.GetBars(TimeFrame.Hour4, "GBPUSD");
            bars.BarOpened += Bars_BarOpened;
        }

        private void Bars_BarOpened(BarOpenedEventArgs obj)
        {
            Print("BarOpened called at {0}", Server.Time);
        }
    }
}

The code above should only produce output on every 4 hour bar, but is executed on every tick instead.  This is the log output:

30/03/2021 23:34:22.614 | cBot "Bug" was stopped for GBPUSD, h4.
30/03/2021 23:34:20.583 | BarOpened called at 30/03/2021 3:34:20 PM
30/03/2021 23:34:19.802 | BarOpened called at 30/03/2021 3:34:19 PM
30/03/2021 23:34:19.552 | BarOpened called at 30/03/2021 3:34:19 PM
30/03/2021 23:34:18.708 | BarOpened called at 30/03/2021 3:34:18 PM
30/03/2021 23:34:18.520 | BarOpened called at 30/03/2021 3:34:18 PM
30/03/2021 23:34:18.427 | BarOpened called at 30/03/2021 3:34:18 PM
30/03/2021 23:34:13.880 | BarOpened called at 30/03/2021 3:34:13 PM
30/03/2021 23:34:12.380 | BarOpened called at 30/03/2021 3:34:12 PM
30/03/2021 23:34:12.161 | BarOpened called at 30/03/2021 3:34:12 PM
30/03/2021 23:34:11.786 | BarOpened called at 30/03/2021 3:34:11 PM
30/03/2021 23:34:11.599 | BarOpened called at 30/03/2021 3:34:11 PM
30/03/2021 23:33:57.864 | cBot "Bug" was started successfully for GBPUSD, h4.
 

This doesn't happen in backtesting, only on a cbot running live.  That fact makes it a particularly nasty surprise, which has already cost me real money.

Regards,
Morné


@mpistorius

mpistorius
17 Oct 2020, 19:15

RE: RE:

firemyst said:

Spotware said:

You can specify label and comment in ExecuteMarketOrder, PlaceLimitOrder and PlaceStopOrder methods. If you would like to modify label and comment after that please post your idea to vote.spotware.com.

Hi there:

Are "comments" displayed anywhere? They don't appear in our "History" or "Events" tabs when backtesting.

Can you confirm if they are only displayed in the "Log" tab when we do the following:

Position p = Positions.Find(myLabel);
Print(p.Comment);

??? Or somewhere else?

Thank you

Also searched for this, but the info in this thread seems to suggest this feature is not available.  Actually, if you right-click on the headers in the History tab, you can select additional columns, including one to show comments.


@mpistorius

mpistorius
12 Mar 2020, 17:52

RE: Backtesting crashes for H4 server data

PanagiotisCharalampous said:

Hi mpistorius,

We will check this and come back to you.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis,

Any news on this? Were you able to reproduce the problem? Is there a workaround, other than running on m1 server data? That makes optimization impossibly slow.

Thanks


@mpistorius

mpistorius
08 Jan 2020, 16:17

RE: RE:

Some more info on the issue above.  I can get around the crash if I use other timeframes, like h3 or h6, but it consistently crashes on h4, even after clearing the cache.  Unfortunately, my strategy is developed for h4.  After downloading some different timeframe data, the test progresses slightly further on h4 before crashing, but it looks to break in the same spot every time.

 ¯\_(ツ)_/¯

 

 


@mpistorius

mpistorius
08 Jan 2020, 13:33

RE:

PanagiotisCharalampous said:

Hi mpistorius,

This should have been fixed in the latest update of Spotware cTrader Beta.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

Unfortunately, it looks like we're not out of the woods yet.  It appears to be fixed for small tests cases (like backtesting 2 symbols over a month works fine), but not for larger bots.  My bot now crashes with a message

cBot crashed: Cache file `` is damaged and has been removed. It will be updated on next run. If the error persists, try clearing target symbol cache manually.

if I try to run it on more symbols, for longer ranges. (The file name is empty, I didn't modify the error message). As an example, I modified the simple minimal multi-symbol bot I posted earlier to run over the 28 major pairs and backtested it over 1 year (06/01/2019-06/01/2020) on h4 open prices.  I also tried deleting the contents of my AppData/Roaming/demo-cTrader/BacktestingChache folder and re-ran it, but I consistently get the above crash while the bot is downloading symbol data.

Please let me know if you can reproduce the issue.  Below is the modified bot that crashes on the latest 3.7 update

using System;
using System.Linq;
using System.Collections.Generic;

using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        string[] symbols = 
        {
            "AUDCAD",
            "AUDCHF",
            "AUDJPY",
            "AUDNZD",
            "AUDUSD",
            "CADCHF",
            "CADJPY",
            "CHFJPY",
            "EURAUD",
            "EURCAD",
            "EURCHF",
            "EURGBP",
            "EURJPY",
            "EURNZD",
            "EURUSD",
            "GBPAUD",
            "GBPCAD",
            "GBPCHF",
            "GBPJPY",
            "GBPNZD",
            "GBPUSD",
            "NZDCAD",
            "NZDCHF",
            "USDJPY",
            "NZDJPY",
            "NZDUSD",
            "USDCHF",
            "USDCAD"
        };
        
        List< Strategy > strategies = new List< Strategy >();
        
        protected override void OnStart()
        {
            foreach ( var sym in symbols )
            {
                var s = new Strategy();
                s.init( this, sym );
                strategies.Add( s );
            }
        }

    
    }
    
    public class Strategy 
    {
        RelativeStrengthIndex rsi;
        Robot bot;
        string symbol;
        
        public void init( Robot bot, string symbol )
        {
            this.symbol = symbol;
            this.bot = bot;
            
            Bars bars = bot.MarketData.GetBars( bot.TimeFrame, symbol );
            rsi = bot.Indicators.RelativeStrengthIndex( bars.ClosePrices, 14 );
            
            bars.BarOpened += OnBarOpened;
        }
        
        void OnBarOpened(BarOpenedEventArgs obj)
        {
            if ( rsi.Result.Last(1) > 70 && rsi.Result.Last(2) <= 70 )
            {
                bot.ExecuteMarketOrder( TradeType.Sell, symbol, 10000, symbol, 10.0, 10.0 );
            }
        }
    }
}

 


@mpistorius

mpistorius
07 Jan 2020, 10:48

RE: RE: RE:

mpistorius said:

mpistorius said:

PanagiotisCharalampous said:

Hi mpistorius,

 I can't use the old syntax (MarketData.GetSeries()) to replicate behavior from 3.6

This is not true. We haven't removed any functionality. The below line of code should work fine in 3.7.

 adx = Indicators.DirectionalMovementSystem(MarketData.GetSeries(TimeFrame.Daily), 14);

 Best Regards,

Panagiotis 

Join us on Telegram

But that is my point.  The above line of code doesn't work in 3.7 if the backtest data setting is set to anything higher than m1, while the same code does work in 3.6.  If you follow the STR I set out earlier and run it in 3.7, you'll see the error.  No error in 3.6

To make it clear, if I change the line to what you suggest (just replace GetBars with GetSeries), I still get the same crash if I run the cBot in 3.7.  The only difference is that the code compiles with a warning that GetSeries is obsolete.  But I expect GetSeries was implemented as a wrapper around GetBars in the new build

 

Hi Panagiotis,

Have you guys managed to reproduce this issue?  I get the feeling that we've been talking around each other in this thread, but I can assure you there is a bug here.  It boils down to 

MarketData.GetSeries( Timeframe.Daily );

crashing in 3.7 when used on backtesting data for bars above m1 open prices.


@mpistorius

mpistorius
07 Jan 2020, 10:35

RE:

PanagiotisCharalampous said:

Hi mpistorius,

I just tried this and I get identical results

 

Ugh, you're right, I tested the same thing again and also now get identical results.  I wouldn't have debugged this and tried to come up with a minimal example to post just for fun, but I have no idea what changed between last week and now.  If I run into the issue again I'll try and find more reliable steps to reproduce.  Thanks for looking anyway!


@mpistorius

mpistorius
30 Dec 2019, 12:11

RE: RE:

mpistorius said:

PanagiotisCharalampous said:

Hi mpistorius,

 I can't use the old syntax (MarketData.GetSeries()) to replicate behavior from 3.6

This is not true. We haven't removed any functionality. The below line of code should work fine in 3.7.

 adx = Indicators.DirectionalMovementSystem(MarketData.GetSeries(TimeFrame.Daily), 14);

 Best Regards,

Panagiotis 

Join us on Telegram

But that is my point.  The above line of code doesn't work in 3.7 if the backtest data setting is set to anything higher than m1, while the same code does work in 3.6.  If you follow the STR I set out earlier and run it in 3.7, you'll see the error.  No error in 3.6

To make it clear, if I change the line to what you suggest (just replace GetBars with GetSeries), I still get the same crash if I run the cBot in 3.7.  The only difference is that the code compiles with a warning that GetSeries is obsolete.  But I expect GetSeries was implemented as a wrapper around GetBars in the new build


@mpistorius

mpistorius
30 Dec 2019, 12:04

RE:

PanagiotisCharalampous said:

Hi mpistorius,

 I can't use the old syntax (MarketData.GetSeries()) to replicate behavior from 3.6

This is not true. We haven't removed any functionality. The below line of code should work fine in 3.7.

 adx = Indicators.DirectionalMovementSystem(MarketData.GetSeries(TimeFrame.Daily), 14);

 Best Regards,

Panagiotis 

Join us on Telegram

But that is my point.  The above line of code doesn't work in 3.7 if the backtest data setting is set to anything higher than m1, while the same code does work in 3.6.  If you follow the STR I set out earlier and run it in 3.7, you'll see the error.  No error in 3.6


@mpistorius

mpistorius
30 Dec 2019, 11:26

RE:

PanagiotisCharalampous said:

Hi mpistorius,

Thanks. The message you get explains what happens

GetBars is supported with data sources: "Tick data from Server" and "m1 data from Server"    

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

I understood the message, but this is in my view a bug and certainly a regression from 3.6.  I am unable to backtest/optimise my bots in any reasonable amount of time in 3.7 if I'm forced to use only m1 data and had to revert back to 3.6 to continue working.  I can't use the old syntax (MarketData.GetSeries()) to replicate behavior from 3.6.  Are you saying the above is intended behavior, and you have removed the possibility to backtest on any open prices other than m1? That is a critical feature IMHO.


@mpistorius

mpistorius
30 Dec 2019, 03:54

RE:

cysecsbin.01 said:

I recently had this error:

24/12/2019 10:53:50.951 | cBot crashed: Error #16302763

What kind of error is this? is it possible to have a description?

Are you using the Ichimoku system?  I think I saw the same kind of non-descript error when I was debugging in 3.7.  See 

 


@mpistorius

mpistorius
30 Dec 2019, 03:26

RE:

PanagiotisCharalampous said:

Hi mpistorius,

Can you please share the complete cBot code so that we can reproduce the issue?

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi Panagiotis,

This happens on the simplest of cBots, here is a broken example:

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        DirectionalMovementSystem adx;
        
        protected override void OnStart()
        {
            adx = Indicators.DirectionalMovementSystem( MarketData.GetBars( TimeFrame.Daily ), 14 );    
        }

        protected override void OnTick()
        {
            Print( adx.ADX.LastValue );
        }
    }
}

Steps to reproduce:

  1. Build the above cBot
  2. Add an instance to a chart, using any timeframe other than m1 (say h4)
  3. On the Backtesting tab, in the Backtesting Settings, change the Data field to 'h4 bars from Server (open prices)' from its default m1 bars setting
  4. Run the backtest

Result: Nothing happens, error in Log window:    
Crashed in OnStart with NotSupportedException: Failed to load Daily bars for symbol EURUSD. GetBars is supported with data sources: "Tick data from Server" and "m1 data from Server"    


@mpistorius

mpistorius
26 Dec 2019, 06:51

From my experience, you can't use any C# 7 features.  cTrader only supports compilation of features in .NET 4.5.2 and C# 5 - I've asked for the compiler to be upgraded as well, but this doesn't seem to be a priority, so we're stuck with old C#.


@mpistorius

mpistorius
31 May 2019, 18:14

Really?! Awesome. Gotta love these undocumented 'features' :)

As these objects were algorithmically generated and I didn't want them to be modified, I intentionally made them non-interactive.  Never thought it would have such side effects. I'm just so happy there is a workaround, I don't care how hacky it is.

For others in my situation, a workaround to the workaround is to only set them as interactive during backtesting, but fixed during real-time trading:

line.interactive = IsBacktesting ? true : false;

 

Thanks, guys, keep up the good work, cTrader is becoming a better Metatrader replacement with every update!


@mpistorius

mpistorius
29 May 2019, 18:36

Hi Paul,

Again, thank you so much for your willingness to lend a hand.  I'll send you a very basic VS project that uses the two C# 6 features I mentioned above, and for the sake of others reading this thread, I'll post sample code here.  The two features I tested were using static directive (https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-static) and expression-bodied members (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/expression-bodied-members), both were introduced in C# 6.  Here is a simple example (this builds fine in VS 2019 if built as a standard C# dll, but won't build with the cBot extension into an .algo file.  Neither will it build straight from the cTrader Automate tab.

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

using static cAlgo.Robots.MyStatic;  // <-- Doesn't compile in cTrader

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TestCS6 : Robot
    {

        private int counter = 0;
        public int TickCount => counter++; // <-- Doesn't compile in cTrader
        
        protected override void OnStart()
        {
            Print( AddOne( 10 ) );
        }

        protected override void OnTick()
        {
            Print( TickCount );
        }

    }
    
    public static class MyStatic
    {
        public static int AddOne( int n )
        {
            return n + 1;
        }
    }
}

 

Thanks again,

Morné


@mpistorius

mpistorius
29 May 2019, 10:57

Hi Paul,

Thanks for the reply.  I tried setting the application target framework in my VS cBot project to .NET 4.6 and in the advanced build settings, I set the language version to C# 6.  But in doing that I am still not able to compile valid C# 6 code.  For example, trying to compile something like

using static cAlgo.Utils;

results in an error when building the .algo file:

error: Identifier expected; 'static' is a keyword
error: Expected class, delegate, enum, interface, or struct

Similarly, I can't use expression body declarations like

public void Invalidate() => invalidated = true;

error: ; expected
error: Invalid token '=' in class, struct, or interface member declaration

That's why I assumed C# 6 is not supported and I'm stuck with C# 4

Not sure if it is related, but I'm using a workaround to run the cBot extension in Visual Studio 2019.  Perhaps that breaks something as VS 2017 is officially supported, but Spotware provided a workaround recently in the forums.

Can you tell me what I need to do to use C# 6 when building my cBots, please?  Sorry if this is a noob question, I come from a C++ background and only just started converting Metatrader EAs to C#

Thanks

 


@mpistorius

mpistorius
27 May 2019, 06:10

RE: Fixed!

andrewfblake said:

I had this problem too and did not want to change anything in cAlgo.... but managed to fix it simply by editing the Bot in Visual Studio and updating that to the new framework 4.6.2.... It then calls my Class Library in 4.6.2 and works like a dream... no need for Spotware to do any updates :-) 

Would you care to elaborate on this, please?  Is there some workaround to use new language features from, say C#7?  When I try to build my project in Visual Studio, I still get errors from the cAlgo extension trying to build a .algo file.  And I cannot disable the extension, then the project won't load.

 


@mpistorius