Topics
Replies
romiko
30 Sep 2012, 10:36
Referencing Time
Is this ok to use, I use this condition to trade and specfic times. I tried to stay away from the index accessor.
protected override void OnBar()
{
if (MarketSeries.OpenTime.LastValue.Hour >= 21 || (MarketSeries.OpenTime.LastValue.Hour >= 0 && MarketSeries.OpenTime.LastValue.Hour <= 13))
Initialize();
}
@romiko
romiko
30 Sep 2012, 10:29
Automated BackTesting
Hi,
I use VIsual Studio and reference the Calgo API. The ultimate is writing unit tests and integration tests to run algorithms throught and bypass the program itself, this way we can have full testing in Visual Studio. I am keen to offer support if you are willing to add this. Just need an Interface that we can use to send FAKE data series data to. Then use something like NSubstitute or fake the concrete implementations.
e.g. IDataSeries.Returns = new FakeDataSeries ......
The we can instantiate our algorithm, with the FakeDataSeries. All we then need is an event trigger for the onTick event :)
What you reckon?
@romiko
romiko
06 Oct 2012, 13:36
Fixed
I have it working now :)
using System; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.Indicators; using System.IO; namespace cAlgo.Robots { [Robot] public class DataExtract : Robot { StreamWriter _fileWriter; protected override void OnStart() { var symbol = Symbol.Code; var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); var filePath = Path.Combine(desktopFolder, symbol + ".csv"); bool isExistingFile = File.Exists(filePath); _fileWriter = File.AppendText(filePath);//creating file if(!isExistingFile) _fileWriter.WriteLine("Date,Time,Open,High,Low,Close,Volume"); _fileWriter.AutoFlush = true;//file will be saved on each change } protected override void OnBar() { var openTime = MarketSeries.OpenTime[MarketSeries.OpenTime.Count-2]; Print("Time = {0} extracted", openTime); //Extract Date,Time,Open,High,Low,Close,Volume var date = MarketSeries.OpenTime[MarketSeries.OpenTime.Count-2].ToString("yyyy-MM-dd"); var time = MarketSeries.OpenTime[MarketSeries.OpenTime.Count-2].ToString("HHmmss"); double close = MarketSeries.Close[MarketSeries.Close.Count-2]; double high = MarketSeries.High[MarketSeries.High.Count-2]; double low = MarketSeries.Low[MarketSeries.Low.Count-2]; double open = MarketSeries.Open[MarketSeries.Open.Count-2]; var volume = 0; _fileWriter.WriteLine("{0},{1},{2},{3},{4},{5},{6}", date, time, open, high, low, close, volume); } protected override void OnStop() { _fileWriter.Close(); } } }@romiko