Topics
Replies
hichem
21 Nov 2013, 12:40
RE:
Hi!
I'm not sure what are you trying to achieve but deriving from a Base robot will not create two robots. The derived robot will inherit from the parent robot and you will have only one instance of a robot running. I made the comments because you mentioned passing events between robots. Which is not the case here. Calling base.isFirstBar(); is nothing else but calling a method in the EventRobot instance.
jhtrader said:
I have built an example that passes an event to a parent robot..
I would like to get some feedback.
using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot()] public class ParentPortfolioRobot : Robot { protected string symbolCode; public int Volu { get; set; } protected string SymbolCode { get { return Symbol.Code; } set { symbolCode = value; } } protected override void OnStart() { var symbol = MarketData.GetSymbol(SymbolCode); Trade.CreateBuyMarketOrder(symbol, Volu); } protected override void OnTick() { foreach (var pos in Account.Positions) Print("{0}", pos.Id); } public void isFirstBar() { Print("Its 10am"); } } } //************************************************************************************************* //#reference: ParentRobot.algo //The Event robot sends events to the Parent robot using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.API.Requests; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC)] public class EventRobot : ParentPortfolioRobot { protected override void OnStart() { //Initialise the variables of the portfolio class Volu = 1000; SymbolCode = Symbol.Code; base.OnStart(); } protected override void OnBar() { int index = MarketSeries.OpenTime.Count - 1; DateTime currentTime = MarketSeries.OpenTime[index]; DateTime previousTime = MarketSeries.OpenTime[index - 1]; //if first bar of the week if (currentTime.DayOfWeek == DayOfWeek.Monday && previousTime.DayOfWeek != DayOfWeek.Monday) sendEvent(); base.OnTick(); } public void sendEvent() { base.isFirstBar(); } } }
@hichem
hichem
20 Nov 2013, 12:54
RE: Stats
I think one should compare the upper part of the wick, the lower part of the wick and the body of the candle to calculate the ratio.
jeex said:
Over the past years, on the H1 timeframe (over 17,000 candles), the average candle length was 0.00221. The average body length was 0.00107 = 44% of the candle, with a standard deviation of 0.00114 (candle) to 0.00084 (body) = 22%. So simply measured a candle where the body is less then 44% - 22% = 22% of the candle can be considered as an abnormal body-candle ratio = a doji.
Or am i missing something here? Maybe also consider the length of the candle in comparison whith the rest? Use the ATR in this?
@hichem
hichem
20 Nov 2013, 12:35
RE:
I think the most direct way to determine that is to calculate the ratio between the wick and the body of the candle. To be more precise one should take into consideration the current TimeFrame.
jeex said:
Does anyone have an algorithm for determining a doji, i.e. a long wick with practicaly no body?
@hichem
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
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
hichem
18 Nov 2013, 11:31
( Updated at: 21 Dec 2023, 09:20 )
RE: RE: RE:
The .algo file is not a .dll file. It is a zip file that contains one or more dll files. So to make this work you should put the .dll file compiled with VS in a zip file and rename the zip file to .algo.
Abdallah_Hacid said:
bfis108137 said:
don't work :
admin said:Have you actually tried this? When I create create a class library, it puts a whole bunch of files in the Robots folder and it doesn't compile to algo file. This is of course because a class library is a dll file. The only way I have found is to code the robot in vs, and then copy the code to cAlgo editor and compile there. I think probably a better soltion would be to implement a few features in the cAlgo editor and I think most people would be happy. Features like hotkeys for things like build and run, code blocking so after you write a function or region you can colapse it so it doesn't get in the way, search, and comment out block of text with hotkey. If these were implemented I think most people wouldn't even care about visual studio. Obviously if there was a way in force visual studio to use the cAlgo comiler then this might be easier but I don't know too much about that.You can create a class library in c#. Make sure you add a reference to the cAlgo.API and that you are using .NET framework 4. You can build the project in visual studio and set the project output path to the folder where the indicators/robots are saved. This will create the algo file and then you will need to create an empty text (cs) file with the same name so that you can find it in the indicators/robots list and execute it there. Alternatively you may just copy paste the code into the cAlgo editor and just build it there.
Let us know if you require additional help.
@hichem
hichem
08 Nov 2013, 15:23
RE: RE: RE:
I don't think updating the displayed values of parameters in left panel is possible.
anders said:
hichem said:
You can Serialize/Deserialize the parameters of your robot in a file.
anders said:
Somebody has a ready solution for the preset/save robot's settings to a file?
I made the save / restore settings to a file in the events onstop / onstart, everything is fine saving. But when set from file in event onstart, parameters set in new values, but not displayed in the panel robot. How to update the parameters of the robot in left panel from the code?
@hichem
hichem
30 Oct 2013, 17:41
RE: Arrays works fine but...
That will not work like that. The Parameter attribute will set the Periods variable after the creation of the _Cumm2 variable.
You should initialize the _Cumm2 variable in the Start() method of the robot is you want to use a value set by a parameter attribute.
jhtrader said:
Hi,
I cannot pass in the parameter Periods when initialising the array
[Parameter("Periods", DefaultValue = 10)]
public int Periods { get; set; }private const int blah = 10;
private readonly double[] _Cumm2 = new double[blah];Any idea why??? I tried to set blah to Periods and I tried to put Periods directly but the compiler saw through my wicked scheme and didnt allow it.. .
Can I make the list non resisable and the values on the next bar just overrite the previous and still use lists.. ?? Currently if I want to use lists I have to clear the list at the beginning of the next bar. I cant see any real perf diff in arrays and lists.. have you had any experience with the performance diff?
@hichem
hichem
24 Oct 2013, 23:01
RE:
The Symbol object is a property of the Robot class. It is undefined inside your stdFun class
Hyperloop said:
using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.API.Requests; namespace PBLibrary { public class stdFun { // Generate Label function // string InstanceID = GenerateLabel("123", "1"); private string GenerateLabel(string argStrategyID, string argVersionID) { string FinalLabel = argStrategyID + "-" + argVersionID + "-" + Symbol.Code + "-" + TimeFrame.ToString(); return FinalLabel; } } }Error 1 An object reference is required for the non-static field, method, or property 'cAlgo.API.Internals.Symbol.Code.get' C:\Users\Clark\Documents\Visual Studio 2010\Projects\PBLibrary\PBLibrary\Class1.cs 15 76 PBLibrary
Error 2 An object reference is required for the non-static field, method, or property 'object.ToString()' C:\Users\Clark\Documents\Visual Studio 2010\Projects\PBLibrary\PBLibrary\Class1.cs 15 96 PBLibraryI'm currently getting this error when I am trying to build this library. When simply copied and pasted this method into a Robot it would run fine. I'm a little new to C# so any help would be appreciate.
@hichem
hichem
24 Oct 2013, 09:26
RE:
To develop a .dll in visual studio import the cAlgo.API.dll in your project.
After compiling the .dll with Visual Studio you can import it in cAlgo by clicking add Reference, and select the .dll you created.
Hyperloop said:
HI,
I'm wondering if anyone has examples/resources about writing custom DLLs for cAlgo.
I would like to compile a library of commonly used methods so I can develop robots/indicators faster.
Thanks!
@hichem
hichem
17 Oct 2013, 08:12
RE:
I think it would be a good idea if you backtest on the value of our real account balance. Do you intend to go live with 10000 $ ?
wisek said:
SL: 150 pips, TP: 100 pips but protection was put just in case. Robot closes and opens positions by signals of modified Bollinger Bands indicator. It trades for 0.5 lot per time and keeps only one position opened.
I don't think that posting profitable robot to a public resource is a good idea.
@hichem
hichem
25 Sep 2013, 09:32
RE:
Have you actually tries to compile this ?
this line will throw an error:
_robot.PrintToLog(message)
PrintToLog is not defined in cAlgo.API.Robot
Kate said:
You can declare public method in robot:
public class MyRobot : Robot { public void PrintToLog(string message) { Print(message); } }
And then call it from another class:
public class CustomClass { private cAlgo.API.Robot _robot; public CustomClass(cAlgo.API.Robot robot) { _robot = robot; } public void Print(string message) { _robot.PrintToLog(message) } }
@hichem
hichem
24 Sep 2013, 18:19
RE:
You can use reflection. Pass the current Robot or indicator as an argument to your class and use reflection to get to the Print Method. Affect it to a delegate, then call that delegate
bhoja said:
Hi there,
I've multiple custom classes which I need to test and check for errors. The Print Command (cAlgo.API.Internals.Algo.Print) is protected, so I cannot Print to the Log. Is there a way around this?
I wanted to keep the custom classes separate from the Robot inherited Class.
Many Thanks,
@hichem
hichem
22 Sep 2013, 22:53
RE:
herophan said:
While the chart is drawing a new bar, I want to get the close prices of the bar in front of newbar and of the bar in front of the bar in front of newbar.
Could you help me ?
Thanks,
int index = MarketSeries.Close.Count - 2; double price_bar_front_of_newbar = MarketSeries.Close[index]; double price_bar_front_of_front_of_newbar = MarketSeries.Close[index-1];
@hichem
hichem
21 Sep 2013, 17:30
RE: RE: RE:
That's mean the last value for my 1h moving average at 16h15 will be its value of 16h right ? and we there is no solution to find if the 1h moving average is raising or failling à 16h15, not before 17h ?
No, at each moment if you inspect the value of MovingAverage.LastValue it gives you the last value at the last tick.
@hichem
hichem
21 Sep 2013, 13:11
RE:
Hello and welcome to ctdn.
I use a time frame of 5min and a simple average of 1h and need to check the value of my simple average in the caltulate method on every tick.
Actually the Calculate() methode gets fires on each tick. you can get the last value of your simple moving average by calling the .LastValue property on you moving average object.
it's possible ? and which value it will return if we suppose we are at 16h15 ?
The value returned will depend on the price at that hour. It is not fixed.
@hichem
hichem
22 Nov 2013, 13:25
RE: Howto link one bot to another
If you want to develop a library then it doesn't need to be implemented in a Robot. You develop a .dll with VS and import in your robot. A robot is not designed to act as a library of functions
jeex said:
@hichem