support for vbt indicators in helpers
This commit is contained in:
@ -6,7 +6,7 @@ from datetime import datetime
|
||||
from typing import Callable, Union, Literal, List, Optional
|
||||
import pandas as pd
|
||||
import random
|
||||
from vectorbtpro.indicators import IndicatorFactory
|
||||
#from vectorbtpro.indicators import IndicatorFactory
|
||||
from .table import Table
|
||||
from .toolbox import ToolBox
|
||||
from .drawings import Box, HorizontalLine, RayLine, TrendLine, TwoPointDrawing, VerticalLine, VerticalSpan
|
||||
@ -14,18 +14,12 @@ from .topbar import TopBar
|
||||
from .util import (
|
||||
BulkRunScript, Pane, Events, IDGen, as_enum, jbool, js_json, TIME, NUM, FLOAT,
|
||||
LINE_STYLE, MARKER_POSITION, MARKER_SHAPE, CROSSHAIR_MODE, MARKER_TYPE,
|
||||
PRICE_SCALE_MODE, marker_position, marker_shape, js_data,
|
||||
PRICE_SCALE_MODE, marker_position, marker_shape, js_data, is_vbt_indicator
|
||||
)
|
||||
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
INDEX = os.path.join(current_dir, 'js', 'index.html')
|
||||
|
||||
def is_indicator(variable):
|
||||
# Get the module path of the variable's type
|
||||
module_path = variable.__class__.__module__
|
||||
# Check if it starts with 'vectorbtpro.indicators'
|
||||
return module_path.startswith('vectorbtpro.indicators')
|
||||
|
||||
# # Predefined colors that stand out well on dark backgrounds
|
||||
# COLORS = [
|
||||
# 'rgba(255, 0, 0, 0.6)', # Red
|
||||
@ -309,7 +303,7 @@ class SeriesCommon(Pane):
|
||||
self.run_script(f'{self.id}.series.setData([])')
|
||||
self.data = pd.DataFrame()
|
||||
return
|
||||
if is_indicator(df):
|
||||
if is_vbt_indicator(df):
|
||||
df = df.real
|
||||
#if df is pd.Series then convert to df
|
||||
if isinstance(df, pd.Series):
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
from lightweight_charts.widgets import JupyterChart
|
||||
from .widgets import JupyterChart
|
||||
from .util import (
|
||||
is_vbt_indicator
|
||||
)
|
||||
|
||||
class Panel:
|
||||
"""
|
||||
@ -167,6 +170,17 @@ def chart(panes: list[Panel], sync=False, title='', size="m"):
|
||||
series, name, entries, exits, markers = (tup + (None, None, None, None, None))[:5]
|
||||
if series is None:
|
||||
continue
|
||||
|
||||
#pokud jde o vbt indikator vytahneme vsechny output a predpokladame, ze jde o lines a vykreslime je
|
||||
if is_vbt_indicator(series):
|
||||
for output in series.output_names:
|
||||
output_series = getattr(series, output)
|
||||
tmp = active_chart.create_line(name=output, priceScaleId=att_name)#, color="blue")
|
||||
tmp.set(output_series)
|
||||
else:
|
||||
if name is None:
|
||||
name = "no_name"
|
||||
|
||||
tmp = active_chart.create_line(name=name, priceScaleId=att_name)#, color="blue")
|
||||
tmp.set(series)
|
||||
|
||||
|
||||
@ -7,6 +7,12 @@ from numpy import isin
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def is_vbt_indicator(variable):
|
||||
# Get the module path of the variable's type
|
||||
module_path = variable.__class__.__module__
|
||||
# Check if it starts with 'vectorbtpro.indicators'
|
||||
return module_path.startswith('vectorbtpro.indicators')
|
||||
|
||||
class Pane:
|
||||
def __init__(self, window):
|
||||
from lightweight_charts import Window
|
||||
|
||||
Reference in New Issue
Block a user