Control indicator from within cBot

Created at 30 Apr 2020, 17:56
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!
SH

Shares4us

Joined 01.04.2020

Control indicator from within cBot
30 Apr 2020, 17:56


How to Draw an internal cbot indicator on the chart

In a cBot sometimes there is the need to draw a line on the chart which is not straight but for instance follows the closeprice on certain moments.

We can do that in an indicator but not in a cBot without attaching an indicator and  then then value of the indicator cannot be controlled

Is there something like the following or a viable & fast workaround?  

//in cBot global :

        [Output("Poke", PlotType = PlotType.Line)]
        private IndicatorDataSeries Poke { get; set; }

//in cBot onStart:
        Poke.Visible = True;

//in cBot onBar:
        Poke[index] = MyValue;

 


@Shares4us
Replies

firemyst
01 May 2020, 12:25

RE:

ctid956028 said:

How to Draw an internal cbot indicator on the chart

In a cBot sometimes there is the need to draw a line on the chart which is not straight but for instance follows the closeprice on certain moments.

We can do that in an indicator but not in a cBot without attaching an indicator and  then then value of the indicator cannot be controlled

Is there something like the following or a viable & fast workaround?  

//in cBot global :

        [Output("Poke", PlotType = PlotType.Line)]
        private IndicatorDataSeries Poke { get; set; }

//in cBot onStart:
        Poke.Visible = True;

//in cBot onBar:
        Poke[index] = MyValue;

 

You can draw any line you want really. I do it all the time in cBots.

Examples from my code:

                    Chart.DrawTrendLine("position" + kvp.Key + "pipline", entryPriceOpenBarIndex, kvp.Value, _currentIndex, pipTextEndPoint, lineColor);

                Chart.DrawHorizontalLine(key + " line", priceAmountToBreakEven, Color.Goldenrod, 2, LineStyle.Dots);

So in your case, get the value of Poke you want, and then use that value as the "y-axis" value to plot when drawing lines.

 

 


@firemyst

Shares4us
01 May 2020, 22:00

RE: RE:

@firemyst  
@panagiotis

Thanks for taking he time and your answer, but alas, I already was aware of those possibilities!
The case is that Spotware already has an method for drawing multiple cornered lines. They use it in indicators.
I can draw a trendline for every timemove but that is not the most efficient way to do it and messes up de chartobjects by adding tons of objects over time.
The most beautifull thing would be to make the drawroutine used in indicators public for cBots.
That way it's cleaner, better maintainable and probably also faster than drawing a trendline for every bartimeMove .


@Shares4us