Chart, ChartArea, and IndicatorArea Objects

Created at 27 Feb 2019, 01:30
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!
lec0456's avatar

lec0456

Joined 14.11.2012

Chart, ChartArea, and IndicatorArea Objects
27 Feb 2019, 01:30


I recently went through the process of upgrading my code for the new API. 

I had to change all my ChartObject.DrawText references to Chart.DrawText.

Except I noticed that with my indicators if it is not an overlay, chart.Drawtext does not work.

I had to change it to IndicatorArea.Drawtext. To me is the Indicator is an overlay then the "indicator area" is the chart bu that is not how it works.

So now, I see 3 new objects in the API to implement the DrawText method.  Chart, ChartArea, and IndicatorArea.

Could you explain exactly what the 3 objects are for, the differences between them and how they should be used?


@lec0456
Replies

lec0456
27 Feb 2019, 01:32

RE:

lec0456 said:

I recently went through the process of upgrading my code for the new API. 

I had to change all my ChartObject.DrawText references to Chart.DrawText.

Except I noticed that with my indicators if it is not an overlay, chart.Drawtext does not work.

I had to change it to IndicatorArea.Drawtext. To me is the Indicator is an overlay then the "indicator area" is the chart bu that is not how it works.

So now, I see 3 new objects in the API to implement the DrawText method.  Chart, ChartArea, and IndicatorArea.

Could you explain exactly what the 3 objects are for, the differences between them and how they should be used?

correction: To me [if] the Indicator is an overlay, then the "indicator area" is the chart bu that is not how it works.


@lec0456

lec0456
27 Feb 2019, 09:50

Ok so after further testing.

If I use chart.DrawText. It does not display the text on the indicator histogram.

If I use ChartArea.DrawText, I get the following error:

Error CS0120: An object reference is required for the non-static field, method, or property 'cAlgo.API.ChartArea.DrawText(string, string, int, double, cAlgo.API.Color)'

If I use IndicatorArea.DrawText, It displays on the indicator histogram BUT! I get an error when running the cBot:

Object reference not set to an instance of an object.

SO NONE OF THEM WORK PROPERLY!!!

 


@lec0456

PanagiotisCharalampous
27 Feb 2019, 09:56

Hi lec0456,

Chart.DrawText() draws on the main chart. IndicatorArea.DrawText() draws on the separate indicator area only if this exists. If the indicator is an overlay then it is ignored.

Best Regards,

Panagiotis


@PanagiotisCharalampous

lec0456
27 Feb 2019, 10:32

OK, but IndicatorArea.DrawText() raises an error when referenced in a cBot. "Object reference not set to an instance of an object."


@lec0456

... Deleted by UFO ...

lec0456
27 Feb 2019, 19:02

Hi I need a little more support on this.  Its a bug. I changed my indicators back to chart.drawtext so that it would not cause a crash in my cbots. If IndicatorArea is supposed to work, then it needs to be debugged.  It happens with any indicator that uses IndicatorArea.DrawText, not just one. You can reproduce this error by placing the DrawText OnCalculate and referencing the indicator in any cBot.


@lec0456

PanagiotisCharalampous
28 Feb 2019, 09:22

Hi lec0456,

To resolve the issue you can just check if the IndicatorArea is null before calling the DrawText() function

            if (IndicatorArea != null)
                IndicatorArea.DrawText("Test", "Test", Server.Time, 1, Color.Green)

Best Regards,

Panagioits


@PanagiotisCharalampous

lec0456
28 Feb 2019, 17:21

ok, I didn't think of that because I didn't think the behavior was by design.

 

Previously you did not need to do that check.  Its a perfectly fine work around but I think it should be fixed so that it works like it did previously.

 

Could you escalate this issue to your developers?

 

Thanks for all your help.


@lec0456

imanlangaran
21 Sep 2020, 10:07

.


@imanlangaran