wanting to plot a "dot" at each candle in a functioning cBot

Created at 28 Mar 2016, 13:49
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!
1007601's avatar

1007601

Joined 16.05.2015

wanting to plot a "dot" at each candle in a functioning cBot
28 Mar 2016, 13:49


Hi;

 

Kind of a basic question but it is so frustrating that I can't work this out on my own (I know plotting doesn't work in back testing, but I'm reluctant to stop something to experiment with my chartobject skills).  

 

Basically my bot handles multiple positions, and one thing I want to plot is the average entry price...  so "onBar" I recalculate the positions, find the average entry and then want to plot a dot relative to this (or target, whatever, my result is a price on the Y axis).  

 

So, I understand each point needs to have a unique identity, is this correct?

What are the co-ordinates for the X axis... is it index based like an indicator, or absolute time based, or something else...  

Level 2 question would be: if I wanted to connect these lines like a moving average, how would I do that ?!?

 

Many thanks from frustrated CAlgoBotter;

GH


@1007601
Replies

solark
29 Mar 2016, 00:23

Yes each point needs to have a unique ID in the context of the chart. Maybe just something like `"Label_Dot_" + count` where count is incremented everytime you draw an object. This may be what you're after.

...

        private double lastAverage = 0.0;
        private int count = 0;
...

        protected override void OnBar()
        {
            var positions = Positions.FindAll("label", Symbol);
            if(positions.Length > 0) {
                var avg = positions.Average(x => x.EntryPrice);
                ChartObjects.DrawLine("label_dot" + count.ToString(), MarketSeries.OpenTime.Last(1), lastAverage, MarketSeries.OpenTime.Last(0), avg, Colors.DarkGray, 2, LineStyle.Dots);
                lastAverage = avg;
                count++;
            }
            else {
                lastAverage = 0.0;
            }
                
        }

There will be a vertical line on entry, but you could work around that by checking if lastAverage is zero. This would be connected dotted lines, if you want dots you could just do shorten up the line and increase the thickness.


@solark

1007601
29 Mar 2016, 13:05

RE:

That's great, thanks !!  

My problem was the x-axis;  but also lacking the patience to experiment by running it live...  weekends were the best time to try it but the markets weren't live !

Cheers,

GH

solark said:

Yes each point needs to have a unique ID in the context of the chart. Maybe just something like `"Label_Dot_" + count` where count is incremented everytime you draw an object. This may be what you're after.

...

        private double lastAverage = 0.0;
        private int count = 0;
...

        protected override void OnBar()
        {
            var positions = Positions.FindAll("label", Symbol);
            if(positions.Length > 0) {
                var avg = positions.Average(x => x.EntryPrice);
                ChartObjects.DrawLine("label_dot" + count.ToString(), MarketSeries.OpenTime.Last(1), lastAverage, MarketSeries.OpenTime.Last(0), avg, Colors.DarkGray, 2, LineStyle.Dots);
                lastAverage = avg;
                count++;
            }
            else {
                lastAverage = 0.0;
            }
                
        }

There will be a vertical line on entry, but you could work around that by checking if lastAverage is zero. This would be connected dotted lines, if you want dots you could just do shorten up the line and increase the thickness.

 


@1007601