outsource functions to a reference file
Created at 27 Mar 2014, 18:39
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!!!
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