tbapi.api.bases.indicator

  1from __future__ import annotations
  2from typing import TYPE_CHECKING
  3import clr
  4from tbapi.common.decorators import tb_class, tb_interface
  5from tbapi.common.converters import to_python_datetime, to_net_datetime
  6from datetime import datetime
  7from Tickblaze.Scripts.Api.Bases import Indicator as _Indicator
  8from typing import Any, overload
  9from abc import ABC, abstractmethod
 10from tbapi.api.bases.symbol_script import SymbolScript
 11from tbapi.api.bases.iindicator import IIndicator
 12from tbapi.api.interfaces.ichart_object import IChartObject
 13from tbapi.api.enums.ztype import ZType
 14from Tickblaze.Scripts.Api.Enums import ZType as _ZType
 15from tbapi.api.interfaces.idrawing_context import IDrawingContext
 16if TYPE_CHECKING:
 17    from tbapi.api.interfaces.ichart import IChart
 18    from tbapi.api.interfaces.ichart_scale import IChartScale
 19    from tbapi.api.interfaces.isymbol import ISymbol
 20    from tbapi.api.series import Series
 21    from tbapi.api.plot_series import PlotSeries
 22    from tbapi.api.bases.watchlist_cell_value import WatchlistCellValue
 23
 24@tb_interface(_Indicator)
 25class Indicator(SymbolScript, IIndicator, IChartObject):
 26    """Represents a base class for indicator scripts. Provides functionality for calculating and rendering the indicator on the chart."""
 27
 28    @staticmethod
 29    def new(*args, **kwargs):
 30        """Generic factory method for Indicator. Use overloads for IDE type hints."""
 31        return Indicator(*args, **kwargs)
 32
 33    @property
 34    def display_name(self) -> str:
 35        """Gets the display name of the indicator."""
 36        val = self._value.DisplayName
 37        return val
 38    @property
 39    def is_overlay(self) -> bool:
 40        val = self._value.IsOverlay
 41        return val
 42    @is_overlay.setter
 43    def is_overlay(self, val: bool):
 44        tmp = self._value
 45        tmp.IsOverlay = val
 46        self._value = tmp
 47    @property
 48    def is_percentage(self) -> bool:
 49        val = self._value.IsPercentage
 50        return val
 51    @is_percentage.setter
 52    def is_percentage(self, val: bool):
 53        tmp = self._value
 54        tmp.IsPercentage = val
 55        self._value = tmp
 56    @property
 57    def auto_rescale(self) -> bool:
 58        val = self._value.AutoRescale
 59        return val
 60    @auto_rescale.setter
 61    def auto_rescale(self, val: bool):
 62        tmp = self._value
 63        tmp.AutoRescale = val
 64        self._value = tmp
 65    @property
 66    def apply_background_color_to_all_panels(self) -> bool:
 67        val = self._value.ApplyBackgroundColorToAllPanels
 68        return val
 69    @apply_background_color_to_all_panels.setter
 70    def apply_background_color_to_all_panels(self, val: bool):
 71        tmp = self._value
 72        tmp.ApplyBackgroundColorToAllPanels = val
 73        self._value = tmp
 74    @property
 75    def scale_precision(self) -> int | None:
 76        val = self._value.ScalePrecision
 77        return val
 78    @scale_precision.setter
 79    def scale_precision(self, val: int | None):
 80        tmp = self._value
 81        tmp.ScalePrecision = val
 82        self._value = tmp
 83    @property
 84    def show_on_chart(self) -> bool:
 85        val = self._value.ShowOnChart
 86        return val
 87    @show_on_chart.setter
 88    def show_on_chart(self, val: bool):
 89        tmp = self._value
 90        tmp.ShowOnChart = val
 91        self._value = tmp
 92    @property
 93    def yaxis_top_margin_min(self) -> float | None:
 94        """Gets or sets the minimum top margin for the Y-axis as a percentage.      The value must be between 0.0 and 1.0."""
 95        val = self._value.YAxisTopMarginMin
 96        return val
 97    @yaxis_top_margin_min.setter
 98    def yaxis_top_margin_min(self, val: float | None):
 99        tmp = self._value
100        tmp.YAxisTopMarginMin = val
101        self._value = tmp
102    @property
103    def yaxis_bottom_margin_min(self) -> float | None:
104        """Gets or sets the minimum bottom margin for the Y-axis as a percentage.      The value must be between 0.0 and 1.0."""
105        val = self._value.YAxisBottomMarginMin
106        return val
107    @yaxis_bottom_margin_min.setter
108    def yaxis_bottom_margin_min(self, val: float | None):
109        tmp = self._value
110        tmp.YAxisBottomMarginMin = val
111        self._value = tmp
112    @property
113    def plots(self) -> IReadOnlyList:
114        """Gets the plots of the indicator."""
115        val = self._value.Plots
116        return val
117    @plots.setter
118    def plots(self, val: IReadOnlyList):
119        tmp = self._value
120        tmp.Plots = val
121        self._value = tmp
122    @property
123    def levels(self) -> IReadOnlyList:
124        """Gets the levels of the indicator."""
125        val = self._value.Levels
126        return val
127    @levels.setter
128    def levels(self, val: IReadOnlyList):
129        tmp = self._value
130        tmp.Levels = val
131        self._value = tmp
132    @property
133    def chart(self) -> IChart:
134        from tbapi.api.interfaces.ichart import IChart
135        val = self._value.Chart
136        return IChart(_existing=val)
137    @chart.setter
138    def chart(self, val: IChart):
139        tmp = self._value
140        tmp.Chart = val._value
141        self._value = tmp
142    @property
143    def chart_scale(self) -> IChartScale:
144        from tbapi.api.interfaces.ichart_scale import IChartScale
145        val = self._value.ChartScale
146        return IChartScale(_existing=val)
147    @chart_scale.setter
148    def chart_scale(self, val: IChartScale):
149        tmp = self._value
150        tmp.ChartScale = val._value
151        self._value = tmp
152    @property
153    def symbol(self) -> ISymbol:
154        from tbapi.api.interfaces.isymbol import ISymbol
155        val = self._value.Symbol
156        return ISymbol(_existing=val)
157    @property
158    def ztype(self) -> ZType:
159        val = int(self._value.ZType)
160        return ZType(val)
161    @ztype.setter
162    def ztype(self, val: ZType):
163        tmp = self._value
164        tmp.ZType = _ZType(val.value if hasattr(val, "value") else int(val))
165        self._value = tmp
166    @property
167    def background_color(self) -> Series:
168        val = self._value.BackgroundColor
169        return val
170
171    def calculate_untill(self, last_bar_index: int) -> None:
172        result = self._value.CalculateUntill(last_bar_index)
173        return result
174  
175    def shade_between(self, series1: PlotSeries, series2: PlotSeries, fill1: Color | None, fill2: Color | None, opacity: float = 1) -> None:
176        """Shades the area between two plot series.            The first plot series.      The second plot series.      The color to shade when first series is above second series.      The color to shade when first series is below second series.      The opacity of the shading, ranging from 0.0 (fully transparent) to 1.0 (fully opaque)."""
177        result = self._value.ShadeBetween(series1._value, series2._value, (None if fill1 is None else fill1._value), (None if fill2 is None else fill2._value), opacity)
178        return result
179  
180    def configure_watchlist_cell(self, cell_value: WatchlistCellValue) -> None:
181        """Configures the watchlist cell representation.            The watchlist cell value to configure."""
182        result = self._value.ConfigureWatchlistCell(cell_value._value)
183        return result
184  
185    def get_yrange(self) -> tuple[float, float]:
186        """Gets the visible range of the indicator values on the Y-axis.            The minimum and maximum value."""
187        result = self._value.GetYRange()
188        return result
189  
190
191    @clr.clrmethod(None, [int])
192    def calculate(self, index: int) -> None:
193        """Calculate the value(s) of the indicator for a given index.            The index of the calculated value."""
194        ...
195
196    @clr.clrmethod(None, [Any])
197    def on_render(self, context: IDrawingContext) -> None:
198        """Renders the indicator on the chart.            The drawing context to render the indicator."""
199        ...
 32@tb_interface(_Indicator)
 33class Indicator(SymbolScript, IIndicator, IChartObject):
 34    """Represents a base class for indicator scripts. Provides functionality for calculating and rendering the indicator on the chart."""
 35
 36    @staticmethod
 37    def new(*args, **kwargs):
 38        """Generic factory method for Indicator. Use overloads for IDE type hints."""
 39        return Indicator(*args, **kwargs)
 40
 41    @property
 42    def display_name(self) -> str:
 43        """Gets the display name of the indicator."""
 44        val = self._value.DisplayName
 45        return val
 46    @property
 47    def is_overlay(self) -> bool:
 48        val = self._value.IsOverlay
 49        return val
 50    @is_overlay.setter
 51    def is_overlay(self, val: bool):
 52        tmp = self._value
 53        tmp.IsOverlay = val
 54        self._value = tmp
 55    @property
 56    def is_percentage(self) -> bool:
 57        val = self._value.IsPercentage
 58        return val
 59    @is_percentage.setter
 60    def is_percentage(self, val: bool):
 61        tmp = self._value
 62        tmp.IsPercentage = val
 63        self._value = tmp
 64    @property
 65    def auto_rescale(self) -> bool:
 66        val = self._value.AutoRescale
 67        return val
 68    @auto_rescale.setter
 69    def auto_rescale(self, val: bool):
 70        tmp = self._value
 71        tmp.AutoRescale = val
 72        self._value = tmp
 73    @property
 74    def apply_background_color_to_all_panels(self) -> bool:
 75        val = self._value.ApplyBackgroundColorToAllPanels
 76        return val
 77    @apply_background_color_to_all_panels.setter
 78    def apply_background_color_to_all_panels(self, val: bool):
 79        tmp = self._value
 80        tmp.ApplyBackgroundColorToAllPanels = val
 81        self._value = tmp
 82    @property
 83    def scale_precision(self) -> int | None:
 84        val = self._value.ScalePrecision
 85        return val
 86    @scale_precision.setter
 87    def scale_precision(self, val: int | None):
 88        tmp = self._value
 89        tmp.ScalePrecision = val
 90        self._value = tmp
 91    @property
 92    def show_on_chart(self) -> bool:
 93        val = self._value.ShowOnChart
 94        return val
 95    @show_on_chart.setter
 96    def show_on_chart(self, val: bool):
 97        tmp = self._value
 98        tmp.ShowOnChart = val
 99        self._value = tmp
100    @property
101    def yaxis_top_margin_min(self) -> float | None:
102        """Gets or sets the minimum top margin for the Y-axis as a percentage.      The value must be between 0.0 and 1.0."""
103        val = self._value.YAxisTopMarginMin
104        return val
105    @yaxis_top_margin_min.setter
106    def yaxis_top_margin_min(self, val: float | None):
107        tmp = self._value
108        tmp.YAxisTopMarginMin = val
109        self._value = tmp
110    @property
111    def yaxis_bottom_margin_min(self) -> float | None:
112        """Gets or sets the minimum bottom margin for the Y-axis as a percentage.      The value must be between 0.0 and 1.0."""
113        val = self._value.YAxisBottomMarginMin
114        return val
115    @yaxis_bottom_margin_min.setter
116    def yaxis_bottom_margin_min(self, val: float | None):
117        tmp = self._value
118        tmp.YAxisBottomMarginMin = val
119        self._value = tmp
120    @property
121    def plots(self) -> IReadOnlyList:
122        """Gets the plots of the indicator."""
123        val = self._value.Plots
124        return val
125    @plots.setter
126    def plots(self, val: IReadOnlyList):
127        tmp = self._value
128        tmp.Plots = val
129        self._value = tmp
130    @property
131    def levels(self) -> IReadOnlyList:
132        """Gets the levels of the indicator."""
133        val = self._value.Levels
134        return val
135    @levels.setter
136    def levels(self, val: IReadOnlyList):
137        tmp = self._value
138        tmp.Levels = val
139        self._value = tmp
140    @property
141    def chart(self) -> IChart:
142        from tbapi.api.interfaces.ichart import IChart
143        val = self._value.Chart
144        return IChart(_existing=val)
145    @chart.setter
146    def chart(self, val: IChart):
147        tmp = self._value
148        tmp.Chart = val._value
149        self._value = tmp
150    @property
151    def chart_scale(self) -> IChartScale:
152        from tbapi.api.interfaces.ichart_scale import IChartScale
153        val = self._value.ChartScale
154        return IChartScale(_existing=val)
155    @chart_scale.setter
156    def chart_scale(self, val: IChartScale):
157        tmp = self._value
158        tmp.ChartScale = val._value
159        self._value = tmp
160    @property
161    def symbol(self) -> ISymbol:
162        from tbapi.api.interfaces.isymbol import ISymbol
163        val = self._value.Symbol
164        return ISymbol(_existing=val)
165    @property
166    def ztype(self) -> ZType:
167        val = int(self._value.ZType)
168        return ZType(val)
169    @ztype.setter
170    def ztype(self, val: ZType):
171        tmp = self._value
172        tmp.ZType = _ZType(val.value if hasattr(val, "value") else int(val))
173        self._value = tmp
174    @property
175    def background_color(self) -> Series:
176        val = self._value.BackgroundColor
177        return val
178
179    def calculate_untill(self, last_bar_index: int) -> None:
180        result = self._value.CalculateUntill(last_bar_index)
181        return result
182  
183    def shade_between(self, series1: PlotSeries, series2: PlotSeries, fill1: Color | None, fill2: Color | None, opacity: float = 1) -> None:
184        """Shades the area between two plot series.            The first plot series.      The second plot series.      The color to shade when first series is above second series.      The color to shade when first series is below second series.      The opacity of the shading, ranging from 0.0 (fully transparent) to 1.0 (fully opaque)."""
185        result = self._value.ShadeBetween(series1._value, series2._value, (None if fill1 is None else fill1._value), (None if fill2 is None else fill2._value), opacity)
186        return result
187  
188    def configure_watchlist_cell(self, cell_value: WatchlistCellValue) -> None:
189        """Configures the watchlist cell representation.            The watchlist cell value to configure."""
190        result = self._value.ConfigureWatchlistCell(cell_value._value)
191        return result
192  
193    def get_yrange(self) -> tuple[float, float]:
194        """Gets the visible range of the indicator values on the Y-axis.            The minimum and maximum value."""
195        result = self._value.GetYRange()
196        return result
197  
198
199    @clr.clrmethod(None, [int])
200    def calculate(self, index: int) -> None:
201        """Calculate the value(s) of the indicator for a given index.            The index of the calculated value."""
202        ...
203
204    @clr.clrmethod(None, [Any])
205    def on_render(self, context: IDrawingContext) -> None:
206        """Renders the indicator on the chart.            The drawing context to render the indicator."""
207        ...

Represents a base class for indicator scripts. Provides functionality for calculating and rendering the indicator on the chart.

Indicator(*args, **kwargs)
199        def __init__(self, *args, **kwargs):
200            pass
@staticmethod
def new(*args, **kwargs):
36    @staticmethod
37    def new(*args, **kwargs):
38        """Generic factory method for Indicator. Use overloads for IDE type hints."""
39        return Indicator(*args, **kwargs)

Generic factory method for Indicator. Use overloads for IDE type hints.

display_name: str
41    @property
42    def display_name(self) -> str:
43        """Gets the display name of the indicator."""
44        val = self._value.DisplayName
45        return val

Gets the display name of the indicator.

is_overlay: bool
46    @property
47    def is_overlay(self) -> bool:
48        val = self._value.IsOverlay
49        return val

Indicates whether this instance is overlayed on the chart or plotted on a separate indicator panel.

is_percentage: bool
55    @property
56    def is_percentage(self) -> bool:
57        val = self._value.IsPercentage
58        return val

Indicates whether the indicator is a percentage indicator. The default value is false.

auto_rescale: bool
64    @property
65    def auto_rescale(self) -> bool:
66        val = self._value.AutoRescale
67        return val

Indicates whether this instance automatically rescales the chart or not.

apply_background_color_to_all_panels: bool
73    @property
74    def apply_background_color_to_all_panels(self) -> bool:
75        val = self._value.ApplyBackgroundColorToAllPanels
76        return val

Indicates whether a background color should be applied to all panels.

scale_precision: int | None
82    @property
83    def scale_precision(self) -> int | None:
84        val = self._value.ScalePrecision
85        return val

The number of decimals displayed on the price scale of the indicator panel.

show_on_chart: bool
91    @property
92    def show_on_chart(self) -> bool:
93        val = self._value.ShowOnChart
94        return val

Indicates whether the object is visible on the chart.

yaxis_top_margin_min: float | None
100    @property
101    def yaxis_top_margin_min(self) -> float | None:
102        """Gets or sets the minimum top margin for the Y-axis as a percentage.      The value must be between 0.0 and 1.0."""
103        val = self._value.YAxisTopMarginMin
104        return val

Gets or sets the minimum top margin for the Y-axis as a percentage. The value must be between 0.0 and 1.0.

yaxis_bottom_margin_min: float | None
110    @property
111    def yaxis_bottom_margin_min(self) -> float | None:
112        """Gets or sets the minimum bottom margin for the Y-axis as a percentage.      The value must be between 0.0 and 1.0."""
113        val = self._value.YAxisBottomMarginMin
114        return val

Gets or sets the minimum bottom margin for the Y-axis as a percentage. The value must be between 0.0 and 1.0.

plots: 'IReadOnlyList'
120    @property
121    def plots(self) -> IReadOnlyList:
122        """Gets the plots of the indicator."""
123        val = self._value.Plots
124        return val

Gets the plots of the indicator.

levels: 'IReadOnlyList'
130    @property
131    def levels(self) -> IReadOnlyList:
132        """Gets the levels of the indicator."""
133        val = self._value.Levels
134        return val

Gets the levels of the indicator.

140    @property
141    def chart(self) -> IChart:
142        from tbapi.api.interfaces.ichart import IChart
143        val = self._value.Chart
144        return IChart(_existing=val)

The chart to which this object belongs.

150    @property
151    def chart_scale(self) -> IChartScale:
152        from tbapi.api.interfaces.ichart_scale import IChartScale
153        val = self._value.ChartScale
154        return IChartScale(_existing=val)

The scale used by this object on the chart.

160    @property
161    def symbol(self) -> ISymbol:
162        from tbapi.api.interfaces.isymbol import ISymbol
163        val = self._value.Symbol
164        return ISymbol(_existing=val)
ztype: tbapi.api.enums.ztype.ZType
165    @property
166    def ztype(self) -> ZType:
167        val = int(self._value.ZType)
168        return ZType(val)
background_color: tbapi.api.series.Series
174    @property
175    def background_color(self) -> Series:
176        val = self._value.BackgroundColor
177        return val

Sets the background color of the chart panel.

def calculate_untill(self, last_bar_index: int) -> None:
179    def calculate_untill(self, last_bar_index: int) -> None:
180        result = self._value.CalculateUntill(last_bar_index)
181        return result
def shade_between( self, series1: tbapi.api.plot_series.PlotSeries, series2: tbapi.api.plot_series.PlotSeries, fill1: 'Color | None', fill2: 'Color | None', opacity: float = 1) -> None:
183    def shade_between(self, series1: PlotSeries, series2: PlotSeries, fill1: Color | None, fill2: Color | None, opacity: float = 1) -> None:
184        """Shades the area between two plot series.            The first plot series.      The second plot series.      The color to shade when first series is above second series.      The color to shade when first series is below second series.      The opacity of the shading, ranging from 0.0 (fully transparent) to 1.0 (fully opaque)."""
185        result = self._value.ShadeBetween(series1._value, series2._value, (None if fill1 is None else fill1._value), (None if fill2 is None else fill2._value), opacity)
186        return result

Shades the area between two plot series. The first plot series. The second plot series. The color to shade when first series is above second series. The color to shade when first series is below second series. The opacity of the shading, ranging from 0.0 (fully transparent) to 1.0 (fully opaque).

def configure_watchlist_cell( self, cell_value: tbapi.api.bases.watchlist_cell_value.WatchlistCellValue) -> None:
188    def configure_watchlist_cell(self, cell_value: WatchlistCellValue) -> None:
189        """Configures the watchlist cell representation.            The watchlist cell value to configure."""
190        result = self._value.ConfigureWatchlistCell(cell_value._value)
191        return result

Configures the watchlist cell representation. The watchlist cell value to configure.

def get_yrange(self) -> tuple[float, float]:
193    def get_yrange(self) -> tuple[float, float]:
194        """Gets the visible range of the indicator values on the Y-axis.            The minimum and maximum value."""
195        result = self._value.GetYRange()
196        return result

Gets the visible range of the indicator values on the Y-axis. The minimum and maximum value.

def calculate(unknown):

Method decorator for exposing python methods to .NET. The argument and return types must be specified as arguments to clrmethod.

e.g.::

class X(object):
    @clrmethod(int, [str])
    def test(self, x):
        return len(x)

Methods decorated this way can be called from .NET, e.g.::

dynamic x = getX(); // get an instance of X declared in Python
int z = x.test("hello"); // calls into python and returns len("hello")
def on_render(unknown):

Method decorator for exposing python methods to .NET. The argument and return types must be specified as arguments to clrmethod.

e.g.::

class X(object):
    @clrmethod(int, [str])
    def test(self, x):
        return len(x)

Methods decorated this way can be called from .NET, e.g.::

dynamic x = getX(); // get an instance of X declared in Python
int z = x.test("hello"); // calls into python and returns len("hello")