Why ChartObjects don`t work in infinite loop?

Created at 09 Aug 2014, 12:58
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!
PI

Pirat

Joined 09.08.2014

Why ChartObjects don`t work in infinite loop?
09 Aug 2014, 12:58


Hello all!

I try to create infinite loop in OnTick. For ex.:

double price1 = 1.3340;
double price2 = 1.3350;

protected override void OnTick()
{
	do
	{
		
	ChartObjects.DrawHorizontalLine("A", price1, Colors.Yellow, 1, LineStyle.Lines);
	ChartObjects.DrawHorizontalLine("B", price2, Colors.Red, 1, LineStyle.Lines);
	
	Thread.Sleep(100);
	Print(Symbol.Bid);
	RefreshData();
	
	} while (true);
}

And objects dont draw (not displayed on the chart). If i delete do{}while  - Bot start work (objects displayed).

What is a the problem ? Thx!


@Pirat
Replies

Spotware
11 Aug 2014, 09:02

All chart objects created inside OnTick handler will be displayed on chart only after OnTick handler will be finished. We can recommend you to use OnTimer handler instead of infinite loop.


@Spotware

Pirat
12 Aug 2014, 13:54

dont work too (


@Pirat

Spotware
12 Aug 2014, 14:02

RE:

Pirat said:

dont work too (

Please provide sample of code that you use to draw objects in OnTimer event.


@Spotware