outsource functions to a reference file

Created at 27 Mar 2014, 18:39
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!
Paulo_Lira's avatar

Paulo_Lira

Joined 12.02.2014

outsource functions to a reference file
27 Mar 2014, 18:39


i have the problem that code in my robot is to long, so i tried to outsource some functions to a reference file .algo. i have been guided by some codes in forums, but i can´t do it... loss class or something like this.

to externalize a a simple funtion like:

 

private string generateLabel()
{
       string robotLabel = "MAyATR - "+(string)Symbol.Code+", "+ MarketSeries.TimeFrame;
       return robotLabel;
}

 

i do this in an external file:

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

namespace extFunctions
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class extFunctions: Robot
    {
    
        /// Generate Label
        
        public string generateLabel()
        {
            string robotLabel = "MAyATR - "+(string)Symbol.Code+", "+ MarketSeries.TimeFrame;
            return robotLabel;
        }
       
    }
}

 

call from robot: 

//#reference: extFunctions.algo
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using extFunctions;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Robot : Robot
    {
        protected override void OnStart()
        {
            Print ( "Label: " + extFunctions.generateLabel() );
        }
    }
}

 

thanks for help!!!


@Paulo_Lira
Replies

Spotware
28 Mar 2014, 09:57

If you want to extract some code from cBot it is better to create a class library in Visual Studio and then reference it in cBot with "Add Reference" button.


@Spotware