Work with more source (.cs) files
Work with more source (.cs) files
31 Jul 2019, 18:59
Dear Everybody,
I would like to use more than 1 source file when I 'm developing in cAlgo.
- 1st (main) is for the idea and
- 2nd is for the common functions (mylibrary.cs) where I collect the functions what I use at every cBot without modification.
for example here is the sample of mylibrary.cs - but this is not working (Positions and the cAlgo API functions are not available).
namespace My { public class Myclass { public int MyPos(string symbol, string label) { int ret= 0; for (i = 0; i < Positions.Count; i++) { if (Positions.Label == label && Positions[i].SymbolName == symbol) ret++; } return (ret); } } //endclass } //endmyspace
Can Anybody help me how to define the functions in mylibrary.cs and how to call them in the main.cs?
Thanks,
Benjamin
Replies
BenjaminR
01 Aug 2019, 12:53
Thanks Panagiotis,
Please clarify for me. I call MyPos from Main.cs like:
int mp = my.MyPos(SymbolName, Label, Positions);
Its Ok, but how to declare the Positions object in MyPos(string symbol, string label, ...) function?
Thanks,
Ben
@BenjaminR
PanagiotisCharalampous
01 Aug 2019, 16:01
Hi Be Rich,
See below
using System; using System.Collections.Generic; using System.Linq; using cAlgo.API; using System.Text; namespace cAlgo { public class Myclass { public int MyPos(string symbol, string label, Positions positions) { int ret = 0; for (int i = 0; i < positions.Count; i++) { if (positions[i].Label == label && positions[i].SymbolName == symbol) ret++; } return (ret); } } }
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
01 Aug 2019, 09:18
Hi Be Rich,
Thanks for posting in our forum. Positions is not a property of MyClass therefore you can not call it. You need to pass this object from Main.cd as a parameter to the function.
Best Regards,
Panagiotis
@PanagiotisCharalampous