How write history positions in csv file
How write history positions in csv file
06 May 2014, 12:07
Hi,
Is somewhere an example how to write positions history to csv file?
Thanks
Replies
cAlgoFx
06 May 2014, 13:05
RE: RE:
cAlgoFx said:
breakermind said:
Hi,
Is somewhere an example how to write positions history to csv file?
Thanks
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;
using System.IO;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class NewcBot : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
private StreamWriter _Writer;
protected override void OnStart()
{
// Put your initialization logic here
var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
var filePath = Path.Combine(desktopFolder, "MyPositions.csv");
_Writer = File.AppendText(filePath);
_Writer.AutoFlush = true;
foreach (HistoricalTrade trade in History)
{
_Writer.WriteLine(trade.PositionId);
}
}
protected override void OnTick()
{
// Put your core logic here
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
You can write all position attributes to a row with:
_Writer.WriteLine(trade.PositionId + "," + trade.EntryTime + "," + trade.EntryPrice);
@cAlgoFx
cAlgoFx
06 May 2014, 12:51
RE:
breakermind said:
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;
using System.IO;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class NewcBot : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
private StreamWriter _Writer;
protected override void OnStart()
{
// Put your initialization logic here
var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
var filePath = Path.Combine(desktopFolder, "MyPositions.csv");
_Writer = File.AppendText(filePath);
_Writer.AutoFlush = true;
foreach (HistoricalTrade trade in History)
{
_Writer.WriteLine(trade.PositionId);
}
}
protected override void OnTick()
{
// Put your core logic here
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
@cAlgoFx