[docs]classIndicatorBase:"""Base class for all technical indicators."""def__init__(self,trader):self.id=str(uuid.uuid4()).split('-')[0]self.instance=trader.instance
[docs]defdispose(self):"""Disposes the indicator."""self.instance.send(self.id,'dispose',{})returnself
[docs]defset_name(self,name:str):"""Sets the name of the indicator. Args: name (str): New indicator name. """self.name=nameself.instance.send(self.id,'setName',{'name':name})returnself
[docs]defget_name(self):"""Gets the indicator name."""returnself.nameifself.nameelseNone
[docs]defset_offset(self,offset:int|float):"""Moves the indicator from its calculated position forward or backward. Args: offset (int | float): New offset value. """self.instance.send(self.id,'setOffset',{'offset':offset})returnself
[docs]defset_visible(self,visible:bool):"""Sets the visibility of the indicator. Hiding the indicator via setVisible(false) does not remove it. Use dispose() to delete any indicator. Args: visible (bool): Visibility of the indicator. """self.instance.send(self.id,'setVisible',{'visible':visible})returnself
[docs]defset_value_label_type(self,label_type:str):"""Sets the value label type for the indicator. Args: label_type (str): 'LabelAndLine', 'Label', 'Line', or 'Hidden' """valid_types=['LabelAndLine','Label','Line','Hidden']iflabel_typenotinvalid_types:raiseValueError(f"Invalid label_type. Must be one of: {', '.join(valid_types)}")self.instance.send(self.id,'setValueLabelType',{'labelType':label_type})returnself
[docs]defset_line_color(self,color:str):"""Sets the line color of the indicator. Args: color (str): New line color as string, should be in HEX format e.g. #FFFFFF. """self.instance.send(self.id,'setLineColor',{'color':color})returnself
[docs]defset_line_width(self,width:int|float):"""Sets the line width of the indicator. Args: width (int | float): New line width. """self.instance.send(self.id,'setLineWidth',{'width':width})returnself
[docs]defset_period_count(self,count:int):"""Sets the number of time periods (n) used to calculate the indicator. Args: count (int): New period count. """self.instance.send(self.id,'setPeriodCount',{'count':count})returnself