Is there any way to add code to cAlgo.API?
Is there any way to add code to cAlgo.API?
10 Feb 2017, 17:11
Hi guys, I'm new at this, I don't have too much experience, so forgive me if I make a disaster..
Well, I've been programming, and my custom methods, properties, etc... are making a mess of a code, having more than 1k of custom code.
So, the main question is: Can I add any Property to the, let's say cAlgo.API.dll? So when I start coding I already have my "things" included? Or..
I can create another DLL, and include it, but I have problems like..
Error 1 An object reference is required for the non-static field, method, or property 'cAlgo.API.Internals.Symbol.Ask.get'
Let's say that I have this code..
public class SpreadClass { public double Price { get { return Symbol.Ask - Symbol.Bid; } } public double Pips { get { return Price / Symbol.PipSize; } } }
So the previous error comes out.. even if I make It static..
Some people says "just pass the reference".. and I end with a code like this.. which... after a couple of houndred of lines.. It becomes a nightmare...... (the entire post is about avoiding this kind of code, one way or another)
public class SpreadClass { private Symbol BS; public SpreadClass(Robot robot) { BS = robot.Symbol; } public double Price { get { return BS.Ask - BS.Bid; } } public double Pips { get { return Price / BS.PipSize; } } }
If what I want is possible, is there any tutorial or post so I can learn how to avoid this "need of passing the reference"?
Modifying the cAlgo.API.dll would be awesome, for example I have to create the property "Entries".. because "Positions" can't be modified. If I can't change the default dll.. how can I do this with a custom DLL?
Ty for your patience and time.
Greetings.
Replies
fermjy
10 Feb 2017, 22:22
RE:
mindbreaker said:
Hi,
look at this /api/guides/trading_api
use functions
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 NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnTick() { SayHello("JIMBO"); if(SayHello("JIN") == "Baraki"){ Print("Booooooo"); } } /// !!!!!!!!!!!!!!!!!!!!!!!!!!!! YOUR CODE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! public string SayHello(string Name = "AlojzyBombel") { // Print to log Print("HELLO " + Name); // return value, string ... return "Baraki"; } } }
Or try decompile DLL for example with https://www.jetbrains.com/decompiler/
and see how they do it ;)
It C# search in google how to create dll library in visual studio on youtube and ....
Bye.
I already have my code... thats what I'm saying... and I have almost 1k of lines... I don't want to put them in every cBot that I make... I prefer to do It loading a DLL... but I have that problem with reference for example... (I know hot to make a dll.. thank you for the google search)
If there is no way to change the cAlgo.API.dll... I will have to use my own DLL... but sooner or later... DLL or not... I have to pass the reference.. at least for what I know...
So If someone knows how to avoid this.. please help
@fermjy
mindbreaker
10 Feb 2017, 23:04
cAlgo create dll file
It's simple :D
DLL class in visual studio (Boo.dll):
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // cAlgo.Api References // using cAlgo.API.Collections; // using cAlgo.API.Indicators; // using cAlgo.API.Internals; // using cAlgo.API.Requests; namespace Boo { public static class Class1 { public static double Price(double p1 = 100, double p2 = 200) { return p1 - p2; } public static double Pips(double Price = 0) { return Price; } } }
And code in cBot (cAlgo):
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; // My dll name using Boo; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class DLL : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { // Put your initialization logic here Print(Boo.Class1.Price(666, 333)); } } }
It work in my cAlgo :)
Bye.
@mindbreaker
mindbreaker
10 Feb 2017, 23:21
And here your first example with cAlgo Api dll (you need include calgo api dll to your ddl as reference)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // cAlgo.Api References using cAlgo.API.Collections; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.API.Requests; namespace Boo { public static class Class1 { public static double Price(Symbol my) { return my.Ask - my.Bid; } public static double PipSize(Symbol my) { return my.PipSize; } } }
And in cbot:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; using Boo; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class DLL : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { // Add Symbol Print(Boo.Class1.Price(Symbol)); } } }
And works fine. :)
@mindbreaker
fermjy
10 Feb 2017, 23:35
RE:
mindbreaker said:
And here your first example with cAlgo Api dll (you need include calgo api dll to your ddl as reference)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // cAlgo.Api References using cAlgo.API.Collections; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.API.Requests; namespace Boo { public static class Class1 { public static double Price(Symbol my) { return my.Ask - my.Bid; } public static double PipSize(Symbol my) { return my.PipSize; } } }And in cbot:
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; using Boo; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class DLL : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { // Add Symbol Print(Boo.Class1.Price(Symbol)); } } }And works fine. :)
Thanks mindbreaker, that's what I'm doing for now, but the code is passing something by reference. If It isn't Robot, is Symbol :(
I will figure it out eventually.
Thanks for your time and patience.
@fermjy
mindbreaker
10 Feb 2017, 22:11
Hi,
look at this /api/guides/trading_api
use functions
Or try decompile DLL for example with https://www.jetbrains.com/decompiler/
and see how they do it ;)
It C# search in google how to create dll library in visual studio on youtube and ....
Bye.
@mindbreaker