I am using a 5min chart and would like to extract the OHLC data from each bar. I have used a template code from clickAlgo, and modified it. It works somewhat, but for some reason misses groups of 5min bars. I initially had a similar code in the onbar section, but thought that moving it to the ontick section would allow more time for each prior 5min bar data to get logged - but it still seems to miss data. Can anyone provide guidance on how to fix this problem? (If someone is trying this code, it won't work unless you download the free clickalgo.data.logger from ClickAlgo)
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using ClickAlgo.Data.Logger;
namespace cAlgo
{
/// <summary>
/// Your algo will need full access to create the log files.
[Robot(TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.FullAccess)]
public class DataLoggerExtract : Robot
{
[Parameter("Show Log File", DefaultValue = true)]
public bool ShowLogFile { get; set; }
//Used to get current price data for viewing position of stoploss, box etc
[Parameter("Source")]
public DataSeries Source { get; set; }
public DataSeries OpenPrices { get; set; }
private DateTime _closeDateTime;
string TIM;
string checkTIME;
string VOL;
string O;
string H;
string L;
string C;
string OHLC;
#region indicator declarations
#endregion
///This method is called when cTrader first starts
protected override void OnStart()
{
// path will be created if it does not exist
TradeLogger.SetLogDir("c:\\\\ClickAlgo\\logs\\");
//if you do not have excel installed, this will create a text file instead
TradeLogger.Extension = "csv";
}
protected override void OnTick()
{
// shows how we can log to file when account balance is low
if (Account.Equity < 100)
{
TradeLogger.Warning("Account balance low");
TradeLogger.StopLogging();
}
//Checks for when a new bar has formed through use of bar opentime
if (checkTIME != Convert.ToString(Bars.OpenTimes.Last(1)))
{
TIM = Convert.ToString(Bars.OpenTimes.Last(1));
O = Convert.ToString(Bars.OpenPrices.Last(1));
H = Convert.ToString(Bars.HighPrices.Last(1));
L = Convert.ToString(Bars.LowPrices.Last(1));
C = Convert.ToString(Bars.ClosePrices.Last(1));
VOL = Convert.ToString(Bars.TickVolumes.Last(1));
OHLC = TIM + "," + O + "," + H + "," + L + "," + C + "," + VOL + ",0";
TradeLogger.Info(OHLC);
checkTIME = TIM; //when printing to file, reset checkTIME
}
}
protected override void OnBar()
{
}
protected override void OnStop()
{
// We automatically show the log file using excel, notepad or any other application; this depends on the extension you have set
if (ShowLogFile)
{
TradeLogger.ShowLogFile();
}
}
}
}