How write history positions in csv file

Created at 06 May 2014, 12:07
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
breakermind's avatar

breakermind

Joined 17.07.2013

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

 


@breakermind
Replies

cAlgoFx
06 May 2014, 12:51

RE:

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
        }
    }
}


@cAlgoFx

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

breakermind
06 May 2014, 13:44

Thanks

Thanks a lot


@breakermind