
Topics
Replies
jhtrader
13 Nov 2013, 19:06
Will you please share this..
I am building an architecture that I am happy to share with you if you can help me make it a reality.
Please communicate with me on ultimaterobotteam@gmail.com
jhtrader
13 Nov 2013, 18:09
I figured this one out!!
fzlogic said:
It looks like you're putting the code in the wrong place. Can you provide more code?
The problem was the way I was referencing the class.. I did not declare it as a Robot so it could not use the things like Symbols..
This fixed it..
[Robot()]
public class Portfolio : Robot
{
}
jhtrader
13 Nov 2013, 00:08
Lets use Pipes!! ... please dont reference syware
How does robot 1 tell robot 2 to execute a particular instruction only robot 2 can do.
So Robot 1 checks a condition say the time is 10am on Tuesday.
If condition is true it sends a message to Robot 2 to execute a particular instruction for a particular symbol.
Robot 2 will check if the SMA is rising for that particular pair and then will either Buy the pair or ignore Robot 1.
So we are looking to pass the variables and requests between robots... without 3rd party software!!!
jhtrader
12 Nov 2013, 19:27
I understand what you mean... but.
Changing the class by adding
using System;
using cAlgo.API;
namespace TestClass
{
[Robot()]
public class Portfolio : Robot
{ //...
}
}
Will compile but this doesnt make sense why do I need to make the class a robot? What is the implications of declaring it a Robot?
jhtrader said:
Yes, if I add the cAlgo.API reference I get the unable to load assembly message..
Here is the code, please let me know if you can get this to run.
Here is the ROBOT
//#reference: TestClass.algo
// -------------------------------------------------------------------------------------------------
//
// This robot illustrates an example of calling an external class
//
//
// -------------------------------------------------------------------------------------------------
using System;
using System.Linq;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.API.Requests;
using cAlgo.Indicators;
using TestClass;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.CentralStandardTime)]
public class BasicBuyRobot : Robot
{
[Parameter(DefaultValue = "myRobot")]
public string LabelName { get; set; }
[Parameter("Source")]
// CLOSE, HIGH, LOW...
public DataSeries Source { get; set; }
//Initialising Robot the first time
protected override void OnStart()
{
//Create portfolio
Portfolio p = new Portfolio("AUD", true, 10000);
p.printPortfolio();
}
//*************************
//called on each onBar() or onTick()
//*************************
protected override void OnTick()
{
//--------------------------
//Do nothing if system is busy
//--------------------------
if (Trade.IsExecuting)
return;
//close portfolio
}
//end Robot
}
// end Robot namespace
}
//**********************************************************************HERE IS THE CLASS
using System;
using cAlgo.API;
namespace TestClass
{
public class Portfolio
{
public string portfolioName;
public bool isLong;
public double volume;
public DateTime OpenDate;
public DateTime lastUpdated;
//Constructor with portfolio type
public Portfolio(string pname, bool tradeDir, double vol)
{
portfolioName = pname;
isLong = tradeDir;
volume = vol;
OpenDate = System.DateTime.Now;
lastUpdated = OpenDate;
}
public void printPortfolio()
{
int OrdCount = 1;
Console.WriteLine("************************************************");
Console.WriteLine("Portfolio {0} was open on {1} with volume = {2}", portfolioName, OpenDate, volume);
Console.WriteLine("**************||||||||||||||||*****************");
}
//end Portfolio class above
}
//end namespace
}
jhtrader
12 Nov 2013, 19:18
umm... I dont know what you mean
Yes, if I add the cAlgo.API reference I get the unable to load assembly message..
Here is the code, please let me know if you can get this to run.
Here is the ROBOT
//#reference: TestClass.algo
// -------------------------------------------------------------------------------------------------
//
// This robot illustrates an example of calling an external class
//
//
// -------------------------------------------------------------------------------------------------
using System;
using System.Linq;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.API.Requests;
using cAlgo.Indicators;
using TestClass;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.CentralStandardTime)]
public class BasicBuyRobot : Robot
{
[Parameter(DefaultValue = "myRobot")]
public string LabelName { get; set; }
[Parameter("Source")]
// CLOSE, HIGH, LOW...
public DataSeries Source { get; set; }
//Initialising Robot the first time
protected override void OnStart()
{
//Create portfolio
Portfolio p = new Portfolio("AUD", true, 10000);
p.printPortfolio();
}
//*************************
//called on each onBar() or onTick()
//*************************
protected override void OnTick()
{
//--------------------------
//Do nothing if system is busy
//--------------------------
if (Trade.IsExecuting)
return;
//close portfolio
}
//end Robot
}
// end Robot namespace
}
//**********************************************************************
HERE IS THE CLASS
using System;
using cAlgo.API;
namespace TestClass
{
public class Portfolio
{
public string portfolioName;
public bool isLong;
public double volume;
public DateTime OpenDate;
public DateTime lastUpdated;
//Constructor with portfolio type
public Portfolio(string pname, bool tradeDir, double vol)
{
portfolioName = pname;
isLong = tradeDir;
volume = vol;
OpenDate = System.DateTime.Now;
lastUpdated = OpenDate;
}
public void printPortfolio()
{
int OrdCount = 1;
Console.WriteLine("************************************************");
Console.WriteLine("Portfolio {0} was open on {1} with volume = {2}", portfolioName, OpenDate, volume);
Console.WriteLine("**************||||||||||||||||*****************");
}
//end Portfolio class above
}
//end namespace
}
jhtrader
11 Nov 2013, 19:49
Not sure that is what I want
I am trying to build a generic reference class not a robot.
The example above given does not include the [Robot()] attribute to fxPortfolioClass, this would defeat the purpose.
jhtrader
08 Nov 2013, 21:54
This generates the following errors...
I put the class into its own cAlgo class.. the class compiles when inside the robot.
However when I followed your instructions and put the class into a separate file and referenced it
I get the following error when compiling the fxPortfolioClass..
1. The type or namespace name Position cannot be found. If I remove the reference to the Position I get the error "Unable to load Assembly - Assembly must contain a single type"
2. I get the error the type or namespace fxPortfolioClass cannot be found in the robot.
The file is in the C:\Users\user\Documents\cAlgo\Sources\Robots
I checked to ensure spelling... what
***** Robot
//#reference: fxPortfolioClass.algo
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using System.Collections.Generic;
using cAlgo.API.Internals;
using cAlgo.API.Requests;
using cAlgo.Indicators;
using System.IO;
using fxPortfolioClass;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC)]
public class ScoutRobot : Robot
{ ...}
}
**** fxPortfolioClass
using System;
using System.Linq;
using System.Collections.Generic;
namespace fxPortfolioClass
{
public class Portfolio
{
public string portfolioName;
public bool isLong;
public double volume;
public List<Position> _myPositions = new List<Position>();
}
}
jhtrader
06 Nov 2013, 18:37
Can you suggest a method to get the second last bar of the week?
jhtrader said:
Hi,
I want to open a bunch of positions one hour after the market opens. I also want to close all positions on the market close.
I am using UTC- 5
DateTime currentTime = MarketSeries.OpenTime[MarketSeries.OpenTime.Count - 1]
DateTime previousTime = MarketSeries.OpenTime[MarketSeries.OpenTime.Count - 2]
if (currentTime.DayOfWeek == DayOfWeek.Sunday && previousTime.DayOfWeek != DayOfWeek.Sunday && TokyoMarketOpen)
{
//first bar of the week
}
** "TokyoMarketOpen" is calculated elsewhere and is true when the Tokyo session is active.
jhtrader
06 Nov 2013, 18:31
RE:Time
Hi,
If we wanted to use this in a robot you cant use calculate method...
Is this equivalent to
index = MarketSeries.OpenTime[MarketSeries.OpenTime.Count - 1];
Also what UTC timeframe does the code assume.. if I use UTC - 5 do I have to change it to Sunday?
cAlgo_Fanatic said:
Hello,
Try this code:
public override void Calculate(int index) { if (index == 0) return; DateTime currentTime = MarketSeries.OpenTime[index]; DateTime previousTime = MarketSeries.OpenTime[index-1]; if(currentTime.Month != previousTime.Month) { // first bar of the month } if(currentTime.DayOfWeek == DayOfWeek.Monday && previousTime.DayOfWeek != DayOfWeek.Monday) { // first bar of the week } if(currentTime.Date != previousTime.Date) { // first bar of the day } //...
jhtrader
31 Oct 2013, 04:24
Please provide an example
Hi,
Can you send things like arrays or variable integers, doubles etc this way between robots?
Can you please add an example of a robot sending information such as a array or if thats not possible perhaps just text or integer to another robot.
Also at the moment I want to communicate with a SQL database would I use pipes for communicating between the SQL server and the Robot?
jhtrader
30 Oct 2013, 19:51
RE: RE:
Sorry there was a typo.. I changed the code to 1 and 2 min timeframes to speed up testing...
The code uses the correct naming the comments may be a little confusing but just substitute the timeframes... 5min changed to 1min and 15min changed to 2min.
In relation to the confusion on the list I provided the example at the top
I would like to compare the current range to the cumulative range of the last 10 bars.
While
current range x > Range(x-1)
current range x > Range(x-1) + Range (x-2)
current range x > Range(x-1) + Range (x-2) + Range (x-3)
so the list is a list of ranges the first element has the current range the next the sum of the 1st and 2nd and the third is the sum of 1st 2nd and 3rd and so on..
Its ok.. I have solved this now.
for (int i = 0; i < arraySize; i++)
{
double H = series2m.High[min2Count - i];
double L = series2m.Low[min2Count - i];
double range = Math.Round((H - L) / Symbol.PipSize, 2);
// Print("High = {0} Low = {1} and Rng: {2}", H, L, range);
// _Cumm2.Add(range + _Cumm2.LastOrDefault()); The list option works fine too
_Cumm2[i] = _Cumm2[i] + series2m.High[min2Count - i] - series2m.Low[min2Count - i];
}
jhtrader said:
Thanks for the answer.. I am sure that this will be alot of help to newbie programmers like myself.
Is this the correct and most efficient way to write this function
The following function
- gets the last 5 min range
double Rng1 = Math.Round((series1m.High[index1 - 1] - series1m.Low[index1 - 1]) / Symbol.PipSize, 2);
You mean series1m is the min 5 market series? I suggest you use better naming.
- creates a 15 min range list with cummulative values from the last bar to the 10th most recent bar (i dont use this list this is just to learn how to add and retrieve)
That is also confusing. You mean the sum of ranges of the 15 min market series? Give example with numbers.
To learn how to use lists you can see some tutorials e.g. http://www.dotnetperls.com/list
jhtrader
30 Oct 2013, 17:22
Arrays works fine but...
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?
jhtrader
29 Oct 2013, 22:31
RE:
Kate said:
Since you try to save last 11 values you can use array instead of list. I guess something like this:
private const int BarsCount = 11; private readonly double[] _Cumm5 = new double[BarsCount]; ... var index = min5.High.Count - 1; for (int i = 0; i < BarsCount; i++) { _Cumm5[i] = _Cumm5[i] + min5.High[index - i] - min5.Low[index - i]; }
Thanks.. I guess the benefit is that it is less resource intensive right? I will switch it over..since I dont need to dynamically resize the array. I used lists to get more familiar with them..
jhtrader
29 Oct 2013, 22:24
Thanks for the answer.. I am sure that this will be alot of help to newbie programmers like myself.
Is this the correct and most efficient way to write this function
The following function
- gets the last 5 min range
- creates a 15 min range list with cummulative values from the last bar to the 10th most recent bar (i dont use this list this is just to learn how to add and retrieve)
- compare the last 5min range to the list created -> and return the index (number of bars that the current range is larger than)
public int check2minBar()
{
int result = 0;
var lastIndex = MarketSeries.Close.Count - 1;
var index1 = GetIndexByDate(series1m, MarketSeries.OpenTime[lastIndex]);
var index2 = GetIndexByDate(series2m, MarketSeries.OpenTime[lastIndex]);
//The current unformed bar of the larger timeframe is no included as it incudes the formed bar of the lower timeframe
double Rng1 = Math.Round((series1m.High[index1 - 1] - series1m.Low[index1 - 1]) / Symbol.PipSize, 2);
Print("The Current 1min bar has H:{0}, L:{1} and Rng = {2}", series1m.High[index1 - 1], series1m.Low[index1 - 1], Rng1);
double cummRng2min = 0;
int min2Count = series2m.High.Count - 1;
Print("The curr 2 min count = {0}", min2Count);
for (int i = 1; i < Periods + 1; i++)
{
double H = series2m.High[min2Count - i];
double L = series2m.Low[min2Count - i];
double range = Math.Round((H - L) / Symbol.PipSize, 2);
cummRng2min += range;
Print("H: {0}", H);
Print("L: {0}", L);
Print("Rng: {0}", range);
Print("CR: {0}", cummRng2min);
//Put in CummRange List
// _Cumm2.Add(range + _Cumm2.LastOrDefault());
//print list value
// Print("Value added to list {0}", _Cumm2[i].ToString());
//check if the current 5 min Rng
if (Rng1 <= cummRng2min)
{
Print("min2Count {0}", min2Count);
Print("(min2Count - i) = {0}, i {1}, range {2}, cumRange {3}", min2Count - i, i, range, cummRng2min);
result = min2Count - (min2Count - i);
break;
}
}
return result;
}
QUESTION 2 - Using A List Option where I store the values to a list and then comparing the values
List<double> cummulativeHighs = new List<double>();
//...
cummulativeHighs.Add(min5.High.LastValue + cummulativeHighs.LastOrDefault()); <-- this crashed on the first itteration
Please show me how I could have modified the function above to add the ranges to a list that is cummulative and then to loop through the list and compare the value to the Curr1minrange and return the index
int index = 0;
for(int i =0; i<_cummulativeHighs.Count; i++)
{
if(Rng5 < _cummulativeHighs[i])
index = i;
break;
}
Many thanks..
jhtrader
29 Oct 2013, 01:18
RE:
Question 1.
Access the last 10 highs - no matter what I do I cant seem to get the real highs and lows as on the chart..
for (int i = MarketSeries.High.Count - 1; i > MarketSeries.High.Count - 11; i--)
{
Print("Val H {0}", min5.High[i]);
}
I also just tried to get the last high.. in the following way.. and it too didnt work.
Print("Val H {0}", min5.High[min5.High.Count - 1]);
Print("Val H {0}", min5.High[MarketSeries.Close.Count - 2]
Print("Val H {0}", min5.High[MarketSeries.High.Count - 2]
Question 2.
How to put these values into a list. so that the values are cumulative
Question 3.
loop through and compare until currRange < cummulative range and return the index.
jhtrader said:
Hi,
I am looking for some help on a problem.
I would like to compare the current range to the cumulative range of the last 10 bars.
While
current range x > Range(x-1)
current range x > Range(x-1) + Range (x-2)
current range x > Range(x-1) + Range (x-2) + Range (x-3)
....
when the condition is false it returns the last index. so if the current range is greater than the cumulative range of the last 4 bars it returns 5.
Issues
The Highs that are reported are not the same as on the screen
private readonly List<double> _Cumm5 = new List<double>(10);
min5 = MarketData.GetSeries(Symbol.Code, TimeFrame.Minute5);
for (int i = 1; i < 11; i++)
{
// _Cumm5[i - 1] = min5.High[min5.High.Count - i] - min5.Low[min5.Low.Count - i] + _Cumm5[i];
//Print("Val H {0}", min5.High[min5.High.Count - i]);
Print("{0}", _Cumm5.Count);
double H = min5.High[min5.High.Count - i];
double L = min5.Low[min5.Low.Count - i];
double Ct = min5.High.Sum(i);
// Print("Val L{0}", min5.Low[min5.Low.Count - i]);
// _Cumm5.Add(H - L);
//Print("Cumm: {0}", _Cumm5[i].ToString());
Print("H {0}", H);
Print("L {0}", L);
Print("Rng {0}", H - L);
}I cannot seem to get the list working it loops infinitely
jhtrader
25 Oct 2013, 22:18
You guys really do good work.. keep it up!!
I am very impressed by the level of support and help you offer and the prompt action you take to fix issues... it makes me want to keep using the platform and invest the time to learn more..well done.
jhtrader
25 Oct 2013, 21:55
Was there a solution to the problem?
I would be very interested in how you put data into a database from a robot... did you guys ever get this working. Please share an example that would be great. and very helpful.
jhtrader
22 Oct 2013, 17:16
RE:
Spotware said:
This has been fixed and will be available in the next release. You can currently confirm this by testing your code using Spotware cAlgo.
Try CentralStandardTime for UTC - 5.
Unfortunately this does not work.. please let me know when the issue is fixed.. when is the next release due?
jhtrader
16 Nov 2013, 04:32
Using the Pipe - please help admin!!
// I want an example where a principal robot creates a named pipe that communicates a string at the end of 10 min bar "Server says hello"
//Another robot "the second robot" will connect to the pipe and listen when the string is sent the second robot will print the message from the string
//Another robot "the third robot" will connect to the pipe and listen when the string is sent the third robot will print the message "the server said what?"
// I want to use named pipe so that any robot that is running on the local machine not connected to the principal robot can listen.. as I understand it unnamed pipes can only be used between parent and child robots. This means that if I have distinct robots all wanting to get the string it might not work.
When I run the code as you have it.. I get the following error:
15/11/2013 21:17:05.385 | Robot’s "Pipes" initialization process has begun.
15/11/2013 21:17:05.744 | Crashed in OnStart with Win32Exception: The system cannot find the file specified
15/11/2013 21:17:05.760 | Robot "Pipes" was stopped for NZDUSD, h1.
I tried to create a file pipeClient.exe in several locations but crashed..
Please provide the code for this simple example above and I can then extend it!!
many thanks..