We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Draw trade line between 2 points in Candle Series

I would like to overlay completed trades on the SfCartesianChart using a candle series by drawing a line between the entry price and close price. I have looked into trendlines and markers but cannot see how I would draw a simple trade line between 2 points on the chart.

Any suggestions?

Many Thanks

Alistair


27 Replies 1 reply marked as answer

LA Lavanya Anaimuthu Syncfusion Team January 26, 2023 11:03 AM UTC

Hi Alistair,


Greetings from Syncfusion.


We have achieved your requirement ‘drawing a line between the open price and close price’ with the help of the  onCreateRenderer
callback in the chart to create a customizable series. This allows you to create a custom rendering in series. We have prepared a sample based on your requirement and attached a sample below for your reference.


Screenshot:

Chart, line chart, box and whisker chart

Description automatically generated


For more details, please refer this ug:

https://help.syncfusion.com/flutter/cartesian-charts/callbacks#oncreaterenderer


Note: We have rendered the black line to connect the open and close value. Please change the sample based on your requirement.


Regards,

Lavanya A.


Attachment: f180195_b9dfb0b2.zip


AR Arconomy January 27, 2023 12:49 AM UTC

Hi Lavanya,

Thanks for getting back to me. I think you may have mis-understood the requirement though - I would like to draw a line from the open and close of a trade, not the open and close of a candle. I need to just plot the 2 points on the same chart as the candle series and join them with a line. Ideally I would be able to pop up a tooltip at the start point and end point to show the trade details.

I have updated your demo screenshot to illustrate.

I think the onCreateRenderer looks like it will support this - maybe it is should be LineSeries on top of the CandleSeries? Is that possible?


Many Thanks

Alistair


image.png












YG Yuvaraj Gajaraj Syncfusion Team January 27, 2023 02:13 PM UTC

Hi Arconomy,


We are checking for a feasible solution to achieve your requirement and we need time on this. We will update the further status in one business day on 30 January 2023. We appreciate your patience until then.


Regards,

Yuvaraj.




AR Arconomy January 27, 2023 09:26 PM UTC

Hi Yuvaraj,

Thanks for looking into this. Let me know if I can provide any support.


Many thanks

Alistair 









YG Yuvaraj Gajaraj Syncfusion Team January 30, 2023 01:51 PM UTC

Hi Arconomy,


We are still looking for a feasible solution to achieve your requirement and we need one more business day. We will update the further detail on 31 January 2023. We appreciate your patience until then.


Regards,

Yuvaraj.



AR Arconomy January 30, 2023 08:40 PM UTC

Thanks for the update Yuvaraj.

Looking forward to hearing from you tomorrow.

Many thanks

Alistair







YG Yuvaraj Gajaraj Syncfusion Team January 31, 2023 02:14 PM UTC

Hi Arconomy,


We have achieved your requirement with the help of a custom painter widget. We have placed the chart widget inside a Stack, and used the SchedulerBinding to generate a list of CustomPaint widgets. Each CustomPaint object has a LinePainter object as its painter. We have stored the line trade points in the tradePoints property, and the LinePainter takes start and end offsets as inputs, which are calculated by converting the trade point data into pixel values using the pointToPixel method in the  ChartSeriesController, accessed from the onRendererCreated callback. We have shared a sample below for your reference.


Screenshot:



Note:

We have used simple data points for rendering the line above the candle. Please change the tradePoints values based on your requirement.


Regards,

Yuvaraj.


Attachment: f180195_75f9e966.zip


AR Arconomy January 31, 2023 10:37 PM UTC

Hi Yuvaraj,


Well done! Thanks for spending time on this. I will try and integrate your solution today and let you know how I get on.


Many Thanks

Alistair



AR Arconomy February 1, 2023 06:40 AM UTC

Hi Yuvaraj,


I have integrated your solution into my chart and made some updates to suport redrawing the trade lines when the chart pans and zooms. I still have a few issues that I am struggling with though;

1) Preventing the CustomPaint widgets being repainted and added to the Stack if they are outside the visible chart area (see screenshots). Is there a way of getting the minimum and maximum visble points on the X axis and Y axis?

2) Do you know whether I could apply the TooltipBehavior to the CustomPaint Widget to show the trade details (e.g. Datetime, entry and close prices)?


Many Thanks

Alistair

Screenshot 2023-02-01 at 4.29.20 pm.png