Category Other  Published on 10/06/2014

Dump trendbars data to CSV

Description

This cBots dumps trendbars data to CSV file. Instructions:

  • create an instance
  • open backtesting tab
  • choose max available date range
  • backtest cBot

CSV format: time, open, high, low, close, volume

In OnStop method cBot will flush all market series data to the CSV file on your Desktop.


using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class DumpToCSV : Robot
    {
        protected override void OnStop()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var folderPath = Path.Combine(desktopFolder, "trendbars");
            Directory.CreateDirectory(folderPath);
            var filePath = Path.Combine(folderPath, Symbol.Code + " " + TimeFrame + ".csv");
            using (var writer = File.CreateText(filePath))
            {
                for (var i = 0; i < MarketSeries.Close.Count; i++)
                {
                    writer.WriteLine(ConcatWithComma(MarketSeries.OpenTime[i], MarketSeries.Open[i], MarketSeries.High[i], MarketSeries.Low[i], MarketSeries.Close[i], MarketSeries.TickVolume[i]));
                }
            }
        }

        private string ConcatWithComma(params object[] parameters)
        {
            return string.Join(",", parameters.Select(p => p.ToString()));
        }
    }
}


modarkat's avatar
modarkat

Joined on 25.12.2013

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: DumpToCSV.algo
  • Rating: 5
  • Installs: 3562
Comments
Log in to add a comment.
GoldnOil750's avatar
GoldnOil750 · 8 years ago

Hi,

I need a simple cBOT. Can you please check the link with the description Payment will be made through SKRILL.

http://ctrader.com/jobs/252

 

thank you

Saleem Khan

JO
joeatbayes · 9 years ago

See: /algos/cbots/show/588  and /algos/cbots/show/591

breakermind's avatar
breakermind · 9 years ago

Hi @modarkat

may y have a version of saving a few currencys and a few intervals in one cbot ?

like

each min

m1(gbpjpy,gbpaud...) file gbpjpy_m1.csv ...

each 5min

m5(gbpjpy,gbpaud...) file gbpjpy_m5.csv ...

each 15min

...

it would be nice :]

Regards