Debug cAlgo Robot in Visual Stuio

Created at 26 Apr 2013, 22:21
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
PP

pparpas

Joined 26.04.2013

Debug cAlgo Robot in Visual Stuio
26 Apr 2013, 22:21


I am in the process of finding the best possible automated platform that covers my needs. By using cAlgo, is there any way to debug robots by using Visual Studio? I have made many trials using Visual Studio and trying to attach the debugger to calgo process with no luck.

 


@pparpas
Replies

hichem
27 Apr 2013, 17:28

RE:
pparpas said:

I am in the process of finding the best possible automated platform that covers my needs. By using cAlgo, is there any way to debug robots by using Visual Studio? I have made many trials using Visual Studio and trying to attach the debugger to calgo process with no luck.

 

Debugging a robot in Visual Studio is possible. But you should compile the robot to a .dll file with Visual Studio. Then you should reference the generated .dll in cAlgo and after executing the robot in cAlgo you should attach VS debugger.


@hichem

aysos75
18 Nov 2013, 00:23

RE: RE:

hichem said:

Why you don't take a step by step ?  They don't work for me...

pparpas said:

I am in the process of finding the best possible automated platform that covers my needs. By using cAlgo, is there any way to debug robots by using Visual Studio? I have made many trials using Visual Studio and trying to attach the debugger to calgo process with no luck.

 

Debugging a robot in Visual Studio is possible. But you should compile the robot to a .dll file with Visual Studio. Then you should reference the generated .dll in cAlgo and after executing the robot in cAlgo you should attach VS debugger.

 


@aysos75

fzlogic
18 Nov 2013, 15:08

RE: RE:

hichem said:

pparpas said:

I am in the process of finding the best possible automated platform that covers my needs. By using cAlgo, is there any way to debug robots by using Visual Studio? I have made many trials using Visual Studio and trying to attach the debugger to calgo process with no luck.

 

Debugging a robot in Visual Studio is possible. But you should compile the robot to a .dll file with Visual Studio. Then you should reference the generated .dll in cAlgo and after executing the robot in cAlgo you should attach VS debugger.

Hi Hichem,

Thanks for the useful tip. I create a robot that is derived from the class of the referenced dll, I manage to debug by calling base.OnStart and base.OnTick but I am using indicators for the calculations and their values are always zero. 

More specifically, I am trying to debug Artificial Intelligence robot found here: /algos/robots/show/46

So this is the code of the robot that is referencing Artificial Intelligence:
 

//#reference: ..\..\..\Visual Studio 2010\Projects\AI\AI\bin\Debug\AI.dll

// -------------------------------------------------------------------------------
//
//    /algos/robots/show/46
//
// -------------------------------------------------------------------------------

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


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class AI : ArtificialIntelligence
    {
        private MacdHistogram macd;
        protected override void OnStart()
        {
            // Put your initialization logic here
            macd = Indicators.MacdHistogram(21, 20, 3);
            base.OnStart();
        }

        protected override void OnTick()
        {
            // Put your core logic here
            Print(macd.Histogram.LastValue);
            base.OnTick();

        }       
    }
}


 

 

 


@fzlogic

hichem
18 Nov 2013, 15:15

RE: RE: RE:

Hi, if you want to debug the MacdHistogram indicator you should add the .dll that contains the implementation of the MacdHistogram in your Visual Studio project.

I think that should be cAlgo.Api.Internals.dll or cAlgo.Api.Indicators found in your cAlgo installation folder.

Anyway, you should use ILSpy to inspect the .dll files in the cAlgo installation folder and find where the indicators are implemented.

 

fzlogic said:

hichem said:

pparpas said:

I am in the process of finding the best possible automated platform that covers my needs. By using cAlgo, is there any way to debug robots by using Visual Studio? I have made many trials using Visual Studio and trying to attach the debugger to calgo process with no luck.

 

Debugging a robot in Visual Studio is possible. But you should compile the robot to a .dll file with Visual Studio. Then you should reference the generated .dll in cAlgo and after executing the robot in cAlgo you should attach VS debugger.

Hi Hichem,

Thanks for the useful tip. I create a robot that is derived from the class of the referenced dll, I manage to debug by calling base.OnStart and base.OnTick but I am using indicators for the calculations and their values are always zero. 

More specifically, I am trying to debug Artificial Intelligence robot found here: /algos/robots/show/46

So this is the code of the robot that is referencing Artificial Intelligence:
 

//#reference: ..\..\..\Visual Studio 2010\Projects\AI\AI\bin\Debug\AI.dll

// -------------------------------------------------------------------------------
//
//    /algos/robots/show/46
//
// -------------------------------------------------------------------------------

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


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class AI : ArtificialIntelligence
    {
        private MacdHistogram macd;
        protected override void OnStart()
        {
            // Put your initialization logic here
            macd = Indicators.MacdHistogram(21, 20, 3);
            base.OnStart();
        }

        protected override void OnTick()
        {
            // Put your core logic here
            Print(macd.Histogram.LastValue);
            base.OnTick();

        }       
    }
}


 

 

 

 


@hichem

fzlogic
18 Nov 2013, 15:30

RE: RE: RE:

fzlogic said:

hichem said:

pparpas said:

I am in the process of finding the best possible automated platform that covers my needs. By using cAlgo, is there any way to debug robots by using Visual Studio? I have made many trials using Visual Studio and trying to attach the debugger to calgo process with no luck.

 

Debugging a robot in Visual Studio is possible. But you should compile the robot to a .dll file with Visual Studio. Then you should reference the generated .dll in cAlgo and after executing the robot in cAlgo you should attach VS debugger.

Hi Hichem,

Thanks for the useful tip. I create a robot that is derived from the class of the referenced dll, I manage to debug by calling base.OnStart and base.OnTick but I am using indicators for the calculations and their values are always zero. 

More specifically, I am trying to debug Artificial Intelligence robot found here: /algos/robots/show/46

So this is the code of the robot that is referencing Artificial Intelligence:
 

//#reference: ..\..\..\Visual Studio 2010\Projects\AI\AI\bin\Debug\AI.dll

// -------------------------------------------------------------------------------
//
//    /algos/robots/show/46
//
// -------------------------------------------------------------------------------

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


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class AI : ArtificialIntelligence
    {
        private MacdHistogram macd;
        protected override void OnStart()
        {
            // Put your initialization logic here
            macd = Indicators.MacdHistogram(21, 20, 3);
            base.OnStart();
        }

        protected override void OnTick()
        {
            // Put your core logic here
            Print(macd.Histogram.LastValue);
            base.OnTick();

        }       
    }
}

I made the macd public in the base class and initialized it in the derived class and now I have values for it. I don't know if this is a good way to do this.

    public class AI : ArtificialIntelligence
    {
        private MacdHistogram mcd;

        protected override void OnStart()
        {
            mcd = Indicators.MacdHistogram(21, 20, 3);
            base.macd = mcd;

        }

 


@fzlogic

hichem
18 Nov 2013, 15:34

RE: RE: RE: RE:

If the mcd object is declared in the base class then you should not redeclare it in the derived class. Remove this line

private MacdHistogram macd;

from the derived class.

fzlogic said:

fzlogic said:

hichem said:

pparpas said:

I am in the process of finding the best possible automated platform that covers my needs. By using cAlgo, is there any way to debug robots by using Visual Studio? I have made many trials using Visual Studio and trying to attach the debugger to calgo process with no luck.

 

Debugging a robot in Visual Studio is possible. But you should compile the robot to a .dll file with Visual Studio. Then you should reference the generated .dll in cAlgo and after executing the robot in cAlgo you should attach VS debugger.

Hi Hichem,

Thanks for the useful tip. I create a robot that is derived from the class of the referenced dll, I manage to debug by calling base.OnStart and base.OnTick but I am using indicators for the calculations and their values are always zero. 

More specifically, I am trying to debug Artificial Intelligence robot found here: /algos/robots/show/46

So this is the code of the robot that is referencing Artificial Intelligence:
 

//#reference: ..\..\..\Visual Studio 2010\Projects\AI\AI\bin\Debug\AI.dll

// -------------------------------------------------------------------------------
//
//    /algos/robots/show/46
//
// -------------------------------------------------------------------------------

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


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class AI : ArtificialIntelligence
    {
        private MacdHistogram macd;
        protected override void OnStart()
        {
            // Put your initialization logic here
            macd = Indicators.MacdHistogram(21, 20, 3);
            base.OnStart();
        }

        protected override void OnTick()
        {
            // Put your core logic here
            Print(macd.Histogram.LastValue);
            base.OnTick();

        }       
    }
}

I made the macd public in the base class and initialized it in the derived class and now I have values for it. I don't know if this is a good way to do this.

    public class AI : ArtificialIntelligence
    {
        private MacdHistogram mcd;

        protected override void OnStart()
        {
            mcd = Indicators.MacdHistogram(21, 20, 3);
            base.macd = mcd;

        }

 

 


@hichem

speculate555
20 Jan 2014, 05:34

Problem: Indicators such as EMA are returning null values even after initialization while debugging.

I have been working on getting the Visual Studio debugger to debug a sample BOT code I've written. I compiled the following code into a dll first using Visual Studio.


using System;

using cAlgo.API;

using cAlgo.API.Indicators;

using cAlgo.API.Internals;

using cAlgo.API.Requests;

using cAlgo.Indicators;

using System.Collections;

using System.Collections.Generic;

 

namespace Rsi.TradeLibrary

{

    [Robot(TimeZone = TimeZones.UTC)]

    public class SampleBot : Robot

    {

          //Global Variables

          [Parameter("MA Type")]

          public MovingAverageType MAType { get; set; }

         [Parameter("Source")]

         public DataSeries SourceSeries { get; set; }

         [Parameter("Slow Periods", DefaultValue = 20)]

         public int SlowPeriods { get; set; }

         [Parameter("Fast Periods", DefaultValue = 10)]

         public int FastPeriods { get; set; }

         public ExponentialMovingAverage slowMa;

         public ExponentialMovingAverage fastMa;
 

         protected override void OnStart()

         {

             Print("Debugging Started");

             FastPeriods = 10;
             SlowPeriods = 20;

             fastMa = Indicators.ExponentialMovingAverage(SourceSeries, FastPeriods);
             slowMa = Indicators.ExponentialMovingAverage(SourceSeries, SlowPeriods);
 

         }
    }
}


I then referenced the dll in cAlgo IDE and was able to build successfully. I was also able to attach the debugger to cAlgo.exe process. I've verified that the control goes to OnStart method and gets executed fine by placing a breakpoint. However, SourceSeries value does not get initialized. It just always stays Null.


//#reference:..\..\..\..\Rsi.TradeLibrary\Rsi.TradeLibrary\bin\Debug\Rsi.TradeLibrary.dll

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)]
     public class RsiTradeBot : Rsi.TradeLibrary.SampleBot
     {

         protected override void OnStart()
         {
             // Put your initialization logic here

  
             base.OnStart();
         }

         protected override void OnTick()
         {
             // Put your core logic here
             base.OnTick();
         }

         protected override void OnStop()
         {
             // Put your deinitialization logic here
             base.OnStop();
         }
     }
}


Am I missing something? Can somebody please help me figure this out so I can debug the code correctly?

Thanks.


@speculate555

deejbee
10 Apr 2014, 11:05

Hi, I came across the same issue after trying to debug.  The solution is quite simple.

In your bot wrapper, you need to set/copy each of the parameter values in the base class using values from the bot wrapper.

         protected override void OnStart()
         {
             // Put your initialization logic here

             base.MAType = this.MAType; //do the same for each parameter
             base.OnStart();
         }

 

Hope that helps.  


@deejbee

breakermind
10 Apr 2014, 12:39

However

This post has been removed by the moderator due to a violation of the EULA.


@breakermind

breakermind
10 Apr 2014, 12:49

RE: However

breakermind said:

This post has been removed by the moderator due to a violation of the EULA.

Hi hi hi the truth is sometimes painful ... hahhaha ... a lot of work in front of programmers from calgo.

Bye.


@breakermind