Topics
Replies
ClickAlgo
20 Sep 2015, 20:47
Your 1st argument needs to be a DataSource type object and not a double, the DataSource is read only and you cannot modify it.
DataSource represents a read only list of values, typically used to represent market price series. The values are accessed with an array-like [] operator.
Sorry I cannot help more. :-)
@ClickAlgo
ClickAlgo
20 Sep 2015, 18:47
hello are you asking for a MovingAverage indicator with a custom MarketSeries Timeframe?
@ClickAlgo
ClickAlgo
19 Sep 2015, 20:59
So what you are doing is:
- For each OpenPosition
- For each PendingOrder
- IF OpenPosition = PendingOrder Where the Label and the Volume are the same
- CancelPendingOrder
- IF OpenPosition = PendingOrder Where the Label and the Volume are the same
- For each PendingOrder
The Pseudocode above shows that you will close all orders where a position exists with the same label name and the same volume amount.
You are missing a curly brace at the end of your code and you could have written your iterations like this:
foreach(var position in Positions) { foreach(var order in PendingOrders) { if(order.label == position.Label && order.Volume == position.Volume) { } } }
I am sure you can work the rest out. :-)
@ClickAlgo
ClickAlgo
19 Sep 2015, 15:27
RE:
Paul_Hayes said:
Microsoft came up with Entity Framework so that you no longer need to do the usual Data Access plumbing to connect to a database, now with Object Relational Mapping (ORM) you can get your data injected direct to a business object class which maps as per your database table structure and allows easy CRUD operations.
Why re-invent the wheel and duplicate code each time.
Just so you know with Visual Studio and the entity framework, you can use a wizard that will create all your (business objects) entity data models and do all the plumbing code for you to easily select, update, insert and delete into your tables with simple LINQ.
@ClickAlgo
ClickAlgo
19 Sep 2015, 15:03
Microsoft came up with Entity Framework so that you no longer need to do the usual Data Access plumbing to connect to a database, now with Object Relational Mapping (ORM) you can get your data injected direct to a business object class which maps as per your database table structure and allows easy CRUD operations.
Why re-invent the wheel and duplicate code each time.
@ClickAlgo
ClickAlgo
13 Sep 2015, 09:58
My wild guess is that the Spread from your broker is larger then your stop-loss.
@ClickAlgo
ClickAlgo
09 Sep 2015, 08:04
Hello,
I think you are confused about Object Oriented Programming with Inheritance and just creating a sub class, which is a big subject to study:-
https://msdn.microsoft.com/en-us/library/ms173149.aspx
https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)
What you are attempting to do is just create a sub class to be used from a parent class, if you wish to use any cAlgo objects in the new class then you will need to pass them in, here is a basic example of what you are attempting to do.
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } // declare private field for new class private Barrista barrista; protected override void OnStart() { // create an instance of the class barrista = new Barrista(); } protected override void OnTick() { // call method of class and pass it the MarketSeries data object, returns a double double result = barrista.baristaInst(MarketSeries); Print(result.ToString()); } } public class Barrista { // constructor public Barrista() { } // public method of class which receives the marketseries data object public double baristaInst(MarketSeries marketSeries) { double testvar = marketSeries.Close.Last(2); return testvar; } } }
@ClickAlgo
ClickAlgo
08 Sep 2015, 09:20
I am creating a WCF Service Application to run under IIS and you just add a service reference to your cAlgo project, you will not need any references to R.NET in cAlgo, all the logic will be in the service and you just expose your methods for calculations, , I will try and get it working on my web server and give you the service address.
You would use it like this:-
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] public class indicator : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("avg")] public IndicatorDataSeries avg { get; set; } rService.RServiceClient r; protected override void Initialize() { r = new rService.RServiceClient(); } public override void Calculate(int index) { // Calculate value at specified index // Result[index] = ... double open = MarketSeries.Open[index]; double high = MarketSeries.High[index]; double low = MarketSeries.Low[index]; double close = MarketSeries.Close[index]; if(r != null) { avg[index] = r.GetAvgPrice(open, high, low, close); Print(avg[index].ToString()); } } } }
Will give you a shout when I have it working.
@ClickAlgo
ClickAlgo
07 Sep 2015, 23:22
Hello,
I am pretty sure you can, but the UI will not update to reflect the new values.
@ClickAlgo
ClickAlgo
07 Sep 2015, 23:18
I think the problem is where cAlgo runs in a sandbox and your calling a In-Process COM object through Interop, the reference stays in memory even if you close the instance.
You may be able to get it to work, i don't know, but I will keep trying as I think it would be pretty cool to use the R.NET, but it may crash cAlgo if it is not coded correctly.
There is another way which is for your cBot to run in its little playhouse and it calls a standalone windows service with a generic protocol which will do the number crunching with R.NET and returns the values to the cBot.
@ClickAlgo
ClickAlgo
07 Sep 2015, 21:36
Well, I think its a common problem, I will investigate further:-
@ClickAlgo
ClickAlgo
07 Sep 2015, 18:55
Run this, tell me if it states in the log Initialized and then disposed or if it fails again.
protected override void Initialize() { RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\R-core\\R"); var envPath = Environment.GetEnvironmentVariable("PATH"); rBinPath = (string)registryKey.GetValue("InstallPath"); string rVersion = (string)registryKey.GetValue("Current Version"); rBinPath = System.Environment.Is64BitProcess ? rBinPath + "\\bin\\x64" : rBinPath + "\\bin\\i386"; Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath); REngine.SetEnvironmentVariables(rBinPath); r = REngine.GetInstance(); r.Initialize(); Print("Initialized..."); // close engine r.Dispose(); Print("Disposed..."); }
@ClickAlgo
ClickAlgo
07 Sep 2015, 18:39
Did you install the R.NET other than with NuGet?
How did you setup your registry values?
@ClickAlgo
ClickAlgo
07 Sep 2015, 17:24
RE:
Sorry, i meant to say that a method is called when an event is fired to close the cBot or indicator, this is where you want to release the handle on the R.NET engine, it may not be the answer, but its worth a try.
@ClickAlgo
ClickAlgo
07 Sep 2015, 17:22
No I have not used it before, but it looks useful, I am trying to get the basic example working with a cAlgo cBot, I have referenced from NuGet:-
Collaboration of .NET Framework with R statistical computing
You will not be able to debug an indicator over the weekend as you have no data feeds, you can back-test with a cBot to debug with visual studio.
If you have got it working and it only worked first time then it could be because the engine has not been shut down, have you tried:-
engine.Dispose();
I am not sure how cAlgo releases memory in an indicator, but in a cBot its OnStop, anyway try and destroy the engine and see if that helps.
Could you send me your initialization code and I may be able to debug deeper and find the issue for you.
@ClickAlgo
ClickAlgo
07 Sep 2015, 15:42
I would make sure you have a reference to the source code of R.Net in your project and not just the assembly, debug the code in Visual Studio and step into R.Net when it initializes, take a look at where goes and if an exception occurs, you could also create a basic test where all the code does is connect a new session with R.NET and that's all.
@ClickAlgo
ClickAlgo
07 Sep 2015, 15:26
ok, has it been working before and has it now suddenly stopped working or is this a new project?
Have you got it working with the cAlgo API before?
@ClickAlgo
ClickAlgo
20 Sep 2015, 20:50
Take a look at this:- http://rmmrobot.com/
@ClickAlgo