Charting Candles (received from Quik)


Charting Candles (received from Quik)
Atom
3/23/2014


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



Thanks:


Mikhail Sukhov

Avatar
Date: 3/23/2014
Reply


sunrising Go to

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),


First of all what kind of problem did you find? Also you didn't provided the source code of ProcessCandle

sunrising Go to

Please might you suggest us where the error could be? (We have already set up permissions to administrator for both quik and C# project)


Good expirience for those who do not speak Russian. How did you know that?
Thanks:

sunrising

Avatar
Date: 3/24/2014
Reply


Thanks.

For sure, ProcessCandles source code is the following one:

Code

        private void ProcessCandle(Candle candle)
        {
            var longValue = candle.State == CandleStates.Finished ? new ChartIndicatorValue(_strategy.LongSma, _strategy.LongSma.Process(candle)) : null;
            var shortValue = candle.State == CandleStates.Finished ? new ChartIndicatorValue(_strategy.ShortSma, _strategy.ShortSma.Process(candle)) : null;

            //_chart.ProcessCandle(_candlesElem, candle);

            _chart.ProcessValues(candle.OpenTime, new Dictionary<IChartElement, object>
			{
				{ _candlesElem, candle },
				{ _longMaElem, longValue },
				{ _shortMaElem, shortValue },
			});
        }


The problem consists of impossibility to draw candles from quik.

It seams that:
  • _candleManager.Container.GetCandles doesn't fill "candles" variable (maybe some issues with quik integration ?)
  • _candleManager.Processing event never fires, so we don't get real time data


Regarding your question, we use a lot google translate and we have a russian trader in our team.

Thank you again for your help. Really appreciated.
Thanks:

Mikhail Sukhov

Avatar
Date: 3/24/2014
Reply


sunrising Go to

_candleManager.Processing event never fires, so we don't get real time data


Check the table "Все сделки". This table should be filled by tick data (historical and realtime).
Thanks:

sunrising

Avatar
Date: 3/30/2014
Reply


Thanks Mihail,

It works on Windows 7, but we have some issues on Windows 8 (still not able to receive and draw candles from Quik). Source code and setting are the same. It isn't a big issue, cause we can always forget about Windows 8.

We start looking at Stock# Studio. Complements, it seems to be really well done and complete for developing and testing common algorithms.

I wonder if you plan to make an English version ? It would be cool.


Thanks:


Attach files by dragging & dropping, , or pasting from the clipboard.

loading
clippy