trade29.sc.SCBridge.modify_chart_drawing#

SCBridge.modify_chart_drawing(key: str, line_number: int, chart_drawing: ChartDrawing) ChartDrawingResponse#

Modifies a drawing on the chart.

This method is almost functionally identical to add_chart_drawing(), except there is a line number parameter. If there is an existing drawing with the supplied line number, then it will be modified with the supplied parameters. Any parameters left to their default will leave the current drawing’s settings unchanged. If there is no existing drawing with the supplied line number (or in the case of line number = -1 a random unused line number will be assigned), then a new drawing will be created.

Parameters:
keystr

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

line_numberint

The line number of the drawing to modify. If a drawing with the specified line number doesnt exist, then a new drawing will be created at the specified line number.

chart_drawingdrawing.ChartDrawing

The modification to make to the drawing at the given line number. All parameters of the ChartDrawing class (but use_relative_vertical_values and user_drawn_drawing) have unset values, it is either -1 or in the case of an enum there is an UNSET enumeration. Setting the attributes to their unset value will leave them unmodified.

Returns:
ChartDrawingResponse

Examples

>>> from trade29.sc import SCBridge, ChartDrawing, constants, color
>>> bridge = SCBridge()
running bridge v0.17.0--------2024/08/08 16:44:07
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)
>>> values = df["Last"]
>>> indices = df["BarIndex"]
>>> 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 get the line number of the drawing we just added                      
>>> ret.line_number
80
>>> # Now we supply that line number as a parameter
>>> # Let's make the drawing super thick, and change its second anchor to be at the last point we have
>>> ret = bridge.modify_chart_drawing(
        key="xx",
        drawing_type = ChartDrawing(
            line_number = ret.line_number, line_width = 10, 
            second_anchor_horizontal = indices[9], second_anchor_vertical = values[9]
        )
    ) 
>>> # Modify gives the same response as add and delete
>>> ret.is_success
True
>>> ret.line_number
80