trade29.sc.SCBridge.add_chart_drawing#

SCBridge.add_chart_drawing(key: str, chart_drawing: ChartDrawing) ChartDrawingResponse#

Adds a drawing to the chart.

These parameters are based off of the Sierra Chart API for adding drawings, for more detail into how the parameters work, see the Sierra Chart docs.

Parameters:
keystr

The key matching the key given to the SC-dX custom study in Sierra Chart.

chart_drawingdrawing.ChartDrawing

The drawing to add.

Returns:
ChartDrawingResponse

Examples

>>> from trade29.sc import SCBridge, ChartDrawing, constants, color
>>> bridge = SCBridge()
running bridge v0.17.0--------2024/08/08 16:27:17
connecting to sc
starting receiver
starting sender
sc version: 2666, scdx version 208, connection: t29scdx2, keys: xx
>>> data = bridge.get_chart_data(key = "xx", base_data = [constants.SCBaseData.SC_LAST], include_live_bar = False)
>>> df = data.as_df(datetime_index = False, include_bar_index = True)
>>> df
            DateTime  BarIndex  IsBarClosed         Last
0 2024-08-08 16:16:00     21636         True  2419.540039
1 2024-08-08 16:17:00     21637         True  2419.879883
2 2024-08-08 16:18:00     21638         True  2420.299805
3 2024-08-08 16:19:00     21639         True  2419.580078
4 2024-08-08 16:21:00     21640         True  2420.395020
5 2024-08-08 16:22:00     21641         True  2420.984863
6 2024-08-08 16:23:00     21642         True  2422.314941
7 2024-08-08 16:24:00     21643         True  2422.114990
8 2024-08-08 16:25:00     21644         True  2422.304932
9 2024-08-08 16:26:00     21645         True  2422.465088
>>> values = df["Last"]
>>> indices = df["BarIndex"]
>>> dates = df["DateTime"] 
>>> # Now that we have chart data, lets try drawing lines between data points:
>>> ret = bridge.add_chart_drawing(
        key="xx", 
        chart_drawing = ChartDrawing(
            drawing_type = constants.ChartDrawingType.LINE, 
            line_width = 2, primary_color = color.BLUE, 
            first_anchor_horizontal = dates[0], first_anchor_vertical = values[0], 
            second_anchor_horizontal = dates[9], second_anchor_vertical = values[9]
        )
    ) 
>>> # We can also use bar indices:
>>> ret = bridge.add_chart_drawing(
        key="xx", 
        drawing_type = ChartDrawing(
            constants.ChartDrawingType.LINE, 
            line_width = 2, primary_color = color.MAGENTA, # Line info
            first_anchor_horizontal = indices[2], first_anchor_vertical = values[2], # First anchor
            second_anchor_horizontal = indices[7], second_anchor_vertical = values[7]) # Second anchor
>>> # We can verify if the chart drawing addition was a success:
>>> ret.is_success
True