Charting Candles (received from Quik)
Dear Stock# community,
We tried to lunch Sample SMA example with some minor personalization.
The main problem we have is related to drawing candles received from quik real time.
The code reported below is able to draw correctly history data but not the current one received from quik.(we report only a peace of code related to candle drawing, in case you need more information please tell us about it),
Please might you suggest us where the error could be? (We have already set up permissions to administrator for both quik and C# project)
Thank you very much for your help.
Kind regards,
Code
// Trader creation
_trader = new QuikTrader(this.Path.Text);
// CONNECTION
_trader.Connected += () =>
{
_candleManager = new CandleManager(_trader);
//WHEN A NEW CANDLE IS RECEIVED
_candleManager.Processing += (series, candle) =>
{
if (candle.State == CandleStates.Finished)
this.GuiAsync(() => ProcessCandle(candle));
};
_trader.Connect();
}
private void Start_Click(object sender, RoutedEventArgs e)
{
if (_strategy == null)
{
// register our security and timeframe
var series = new CandleSeries(typeof(TimeFrameCandle), _lkoh, _timeFrame);
/*CREATION OF CANDLES FROM HISTORY *.txt*/
IEnumerable<Candle> candles = File.ReadAllLines("LKOH_history.txt").Select(line =>
{
var parts = line.Split(',');
//Returns a string array that contains the substrings that are delimited by ','.
var time = (parts[0] + parts[1]).ToDateTime("yyyyMMddHHmmss");
return (Candle)new TimeFrameCandle
{
OpenPrice = parts[2].To<decimal>(), //To<decimal>() is converter from string to decimal
HighPrice = parts[3].To<decimal>(),
LowPrice = parts[4].To<decimal>(),
ClosePrice = parts[5].To<decimal>(),
TimeFrame = _timeFrame,
OpenTime = time,
TotalVolume = parts[6].To<int>(),
Security = _lkoh,
State = CandleStates.Finished,
};
});
var lastCandleTime = default(DateTime);
// History candles drawing
foreach (var candle in candles)
{
ProcessCandle(candle);
lastCandleTime = candle.OpenTime;
}
/* now we try to get current data from quik */
_candleManager.Start(series);
// Calculation of time intervals of current candle
var bounds = _timeFrame.GetCandleBounds(series.Security);
// get candles from when quik started to the latest one
candles = _candleManager.Container.GetCandles(series, new Range<DateTime>(lastCandleTime + _timeFrame, bounds.Min));
// draw candles received from quik
foreach (var candle in candles)
{
ProcessCandle(candle);
}
}
}