Skip to content

indicator ¤

plot_bollinger_bands ¤

plot_bollinger_bands(
    dataframe: DataFrame,
    upper: str | None = "upper",
    basis: str | None = "basis",
    lower: str | None = "lower",
    width: int = 1,
    upper_color: str = "#33BDFF",
    basis_color: str = "#D105F5",
    lower_color: str = "#33BDFF",
    filter: Series | None = None,
) -> dict

summary

Parameters:

  • dataframe (DataFrame) –

    description

  • upper (str, default: 'upper' ) –

    Column name. None mean skip plot. Defaults to "upper".

  • basis (str, default: 'basis' ) –

    Column name. None mean skip plot. Defaults to "basis".

  • lower (str, default: 'lower' ) –

    Column name. None mean skip plot. Defaults to "lower".

  • width (int, default: 1 ) –

    description. Defaults to 1.

  • upper_color (str, default: '#33BDFF' ) –

    Color code. Defaults to "#33BDFF".

  • lower_color (str, default: '#33BDFF' ) –

    Color code. Defaults to "#33BDFF".

  • basis_color (str, default: '#D105F5' ) –

    Color code. Defaults to "#D105F5".

  • filter (Series | None, default: None ) –

    description. Defaults to None.

Returns:

  • dict ( dict ) –

    description

Source code in lettrade/plot/plotly/indicator.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def plot_bollinger_bands(
    dataframe: pd.DataFrame,
    upper: str | None = "upper",
    basis: str | None = "basis",
    lower: str | None = "lower",
    width: int = 1,
    upper_color: str = "#33BDFF",
    basis_color: str = "#D105F5",
    lower_color: str = "#33BDFF",
    filter: pd.Series | None = None,
) -> dict:
    """_summary_

    Args:
        dataframe (pd.DataFrame): _description_
        upper (str, optional): Column name. `None` mean skip plot. Defaults to "upper".
        basis (str, optional): Column name. `None` mean skip plot. Defaults to "basis".
        lower (str, optional): Column name. `None` mean skip plot. Defaults to "lower".
        width (int, optional): _description_. Defaults to 1.
        upper_color (str, optional): Color code. Defaults to "#33BDFF".
        lower_color (str, optional): Color code. Defaults to "#33BDFF".
        basis_color (str, optional): Color code. Defaults to "#D105F5".
        filter (pd.Series | None, optional): _description_. Defaults to None.

    Returns:
        dict: _description_
    """
    if filter is not None:
        df_name = dataframe.name
        dataframe = dataframe.loc[filter]
        object.__setattr__(dataframe, "name", df_name)

    items = []

    if upper is not None:
        items.append(
            dict(
                type="scatter",
                x=dataframe.index,
                y=dataframe[upper],
                name=upper,
                mode="lines",
                line=dict(color=upper_color, width=width),
            )
        )
    if basis is not None:
        items.append(
            dict(
                type="scatter",
                x=dataframe.index,
                y=dataframe[basis],
                name=basis,
                mode="lines",
                line=dict(color=basis_color, width=width),
            )
        )
    if lower is not None:
        items.append(
            dict(
                type="scatter",
                x=dataframe.index,
                y=dataframe[lower],
                name=lower,
                mode="lines",
                line=dict(color=lower_color, width=width),
            )
        )
    return {f"{dataframe.name}": dict(items=items)}

plot_candlestick ¤

plot_candlestick(
    dataframe: DataFrame,
    name: str = "Candlestick",
    width: int = 1,
    increasing_line_color="#26c6da",
    decreasing_line_color="#ab47bc",
    row: int = 1,
    col: int = 1,
    filter: Series | None = None,
    **kwargs
) -> dict

summary

Parameters:

  • dataframe (DataFrame) –

    description

  • name (str, default: 'Candlestick' ) –

    description. Defaults to "Candlestick".

  • width (int, default: 1 ) –

    description. Defaults to 1.

  • increasing_line_color (str, default: '#26c6da' ) –

    description. Defaults to "#26c6da".

  • decreasing_line_color (str, default: '#ab47bc' ) –

    description. Defaults to "#ab47bc".

  • row (int, default: 1 ) –

    description. Defaults to 1.

  • col (int, default: 1 ) –

    description. Defaults to 1.

  • filter (Series | None, default: None ) –

    description. Defaults to None.

Returns:

  • dict ( dict ) –

    description

Source code in lettrade/plot/plotly/indicator.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
def plot_candlestick(
    dataframe: pd.DataFrame,
    name: str = "Candlestick",
    width: int = 1,
    increasing_line_color="#26c6da",
    decreasing_line_color="#ab47bc",
    row: int = 1,
    col: int = 1,
    filter: pd.Series | None = None,
    **kwargs,
) -> dict:
    """_summary_

    Args:
        dataframe (pd.DataFrame): _description_
        name (str, optional): _description_. Defaults to "Candlestick".
        width (int, optional): _description_. Defaults to 1.
        increasing_line_color (str, optional): _description_. Defaults to "#26c6da".
        decreasing_line_color (str, optional): _description_. Defaults to "#ab47bc".
        row (int, optional): _description_. Defaults to 1.
        col (int, optional): _description_. Defaults to 1.
        filter (pd.Series | None, optional): _description_. Defaults to None.

    Returns:
        dict: _description_
    """
    if filter is not None:
        df_name = dataframe.name
        dataframe = dataframe.loc[filter]
        object.__setattr__(dataframe, "name", df_name)

    config = dict(
        items=[
            dict(
                type="candlestick",
                x=dataframe.index,
                open=dataframe["open"],
                high=dataframe["high"],
                low=dataframe["low"],
                close=dataframe["close"],
                name=name,
                line=dict(width=width),
                increasing_line_color=increasing_line_color,
                decreasing_line_color=decreasing_line_color,
                hoverinfo="text",
                hovertext=name,
                row=row,
                col=col,
                **kwargs,
            ),
        ]
    )

    return {f"{dataframe.name}": config}

plot_ichimoku ¤

plot_ichimoku(
    dataframe: DataFrame,
    tenkan_sen="tenkan_sen",
    kijun_sen="kijun_sen",
    senkou_span_a="senkou_span_a",
    senkou_span_b="senkou_span_b",
    chikou_span="chikou_span",
    width=1,
    tenkan_sen_color="#33BDFF",
    kijun_sen_color="#D105F5",
    senkou_span_a_color="#228B22",
    senkou_span_b_color="#FF3342",
    chikou_span_color="#F1F316",
    filter: Series | None = None,
) -> dict

summary

Parameters:

  • dataframe (DataFrame) –

    description

  • tenkan_sen (str, default: 'tenkan_sen' ) –

    description. Defaults to "tenkan_sen".

  • kijun_sen (str, default: 'kijun_sen' ) –

    description. Defaults to "kijun_sen".

  • senkou_span_a (str, default: 'senkou_span_a' ) –

    description. Defaults to "senkou_span_a".

  • senkou_span_b (str, default: 'senkou_span_b' ) –

    description. Defaults to "senkou_span_b".

  • chikou_span (str, default: 'chikou_span' ) –

    description. Defaults to "chikou_span".

  • width (int, default: 1 ) –

    description. Defaults to 1.

  • tenkan_sen_color (str, default: '#33BDFF' ) –

    description. Defaults to "#33BDFF".

  • kijun_sen_color (str, default: '#D105F5' ) –

    description. Defaults to "#D105F5".

  • senkou_span_a_color (str, default: '#228B22' ) –

    description. Defaults to "#228B22".

  • senkou_span_b_color (str, default: '#FF3342' ) –

    description. Defaults to "#FF3342".

  • chikou_span_color (str, default: '#F1F316' ) –

    description. Defaults to "#F1F316".

  • filter (Series | None, default: None ) –

    description. Defaults to None.

Returns:

  • dict ( dict ) –

    description

Source code in lettrade/plot/plotly/indicator.py
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def plot_ichimoku(
    dataframe: pd.DataFrame,
    tenkan_sen="tenkan_sen",
    kijun_sen="kijun_sen",
    senkou_span_a="senkou_span_a",
    senkou_span_b="senkou_span_b",
    chikou_span="chikou_span",
    width=1,
    tenkan_sen_color="#33BDFF",
    kijun_sen_color="#D105F5",
    senkou_span_a_color="#228B22",
    senkou_span_b_color="#FF3342",
    chikou_span_color="#F1F316",
    filter: pd.Series | None = None,
) -> dict:
    """_summary_

    Args:
        dataframe (pd.DataFrame): _description_
        tenkan_sen (str, optional): _description_. Defaults to "tenkan_sen".
        kijun_sen (str, optional): _description_. Defaults to "kijun_sen".
        senkou_span_a (str, optional): _description_. Defaults to "senkou_span_a".
        senkou_span_b (str, optional): _description_. Defaults to "senkou_span_b".
        chikou_span (str, optional): _description_. Defaults to "chikou_span".
        width (int, optional): _description_. Defaults to 1.
        tenkan_sen_color (str, optional): _description_. Defaults to "#33BDFF".
        kijun_sen_color (str, optional): _description_. Defaults to "#D105F5".
        senkou_span_a_color (str, optional): _description_. Defaults to "#228B22".
        senkou_span_b_color (str, optional): _description_. Defaults to "#FF3342".
        chikou_span_color (str, optional): _description_. Defaults to "#F1F316".
        filter (pd.Series | None, optional): _description_. Defaults to None.

    Returns:
        dict: _description_
    """
    if filter is not None:
        df_name = dataframe.name
        dataframe = dataframe.loc[filter]
        object.__setattr__(dataframe, "name", df_name)

    items = []

    if tenkan_sen is not None:
        items.append(
            dict(
                type="scatter",
                x=dataframe.index,
                y=dataframe[tenkan_sen],
                name=tenkan_sen,
                mode="lines",
                line=dict(color=tenkan_sen_color, width=width),
            )
        )
    if kijun_sen is not None:
        items.append(
            dict(
                type="scatter",
                x=dataframe.index,
                y=dataframe[kijun_sen],
                name=kijun_sen,
                mode="lines",
                line=dict(color=kijun_sen_color, width=width),
            )
        )
    if senkou_span_a is not None:
        items.append(
            dict(
                type="scatter",
                x=dataframe.index,
                y=dataframe[senkou_span_a],
                name=senkou_span_a,
                mode="lines",
                line=dict(color=senkou_span_a_color, width=width),
            )
        )
    if senkou_span_b is not None:
        items.append(
            dict(
                type="scatter",
                x=dataframe.index,
                y=dataframe[senkou_span_b],
                name=senkou_span_b,
                mode="lines",
                fill="tonexty",
                line=dict(color=senkou_span_b_color, width=width),
            )
        )
    if chikou_span is not None:
        items.append(
            dict(
                type="scatter",
                x=dataframe.index,
                y=dataframe[chikou_span],
                name=chikou_span,
                mode="lines",
                line=dict(color=chikou_span_color, width=width),
            )
        )

    return {f"{dataframe.name}": dict(items=items)}

plot_line ¤

plot_line(
    series: Series | str,
    color: str = "#ffee58",
    width: int = 1,
    name: str | None = None,
    mode: str = "lines",
    fullfill: bool = False,
    dataframe: DataFrame | None = None,
    filter: Series | None = None,
    **kwargs
) -> dict

summary

Parameters:

  • series (Series | str) –

    description

  • color (str, default: '#ffee58' ) –

    description. Defaults to "#ffee58".

  • width (int, default: 1 ) –

    description. Defaults to 1.

  • name (str | None, default: None ) –

    description. Defaults to None.

  • mode (str, default: 'lines' ) –

    description. Defaults to "lines".

  • fullfill (bool, default: False ) –

    description. Defaults to False.

  • dataframe (DataFrame | None, default: None ) –

    description. Defaults to None.

  • filter (Series | None, default: None ) –

    description. Defaults to None.

Returns:

  • dict ( dict ) –

    description

Source code in lettrade/plot/plotly/indicator.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
def plot_line(
    series: pd.Series | str,
    color: str = "#ffee58",
    width: int = 1,
    name: str | None = None,
    mode: str = "lines",
    fullfill: bool = False,
    dataframe: pd.DataFrame | None = None,
    filter: pd.Series | None = None,
    **kwargs,
) -> dict:
    """_summary_

    Args:
        series (pd.Series | str): _description_
        color (str, optional): _description_. Defaults to "#ffee58".
        width (int, optional): _description_. Defaults to 1.
        name (str | None, optional): _description_. Defaults to None.
        mode (str, optional): _description_. Defaults to "lines".
        fullfill (bool, optional): _description_. Defaults to False.
        dataframe (pd.DataFrame | None, optional): _description_. Defaults to None.
        filter (pd.Series | None, optional): _description_. Defaults to None.

    Returns:
        dict: _description_
    """
    if isinstance(series, str):
        series = dataframe[series]

    if filter is not None:
        series = series.loc[filter]

    config = dict(
        items=[
            dict(
                type="scatter",
                x=series.index,
                y=series,
                line=dict(color=color, width=width),
                name=name or series.name,
                mode=mode,
                fullfill=fullfill,
                **kwargs,
            )
        ]
    )
    if dataframe is None:
        return config

    return {f"{dataframe.name}": config}

plot_lines ¤

plot_lines(
    *serieses: list[Series | str],
    color: str = "#ffee58",
    width: int = 1,
    name: str | None = None,
    mode: str = "lines",
    fullfill: bool = False,
    dataframe: DataFrame | None = None,
    **kwargs
) -> dict

summary

Parameters:

  • color (str, default: '#ffee58' ) –

    description. Defaults to "#ffee58".

  • width (int, default: 1 ) –

    description. Defaults to 1.

  • name (str | None, default: None ) –

    description. Defaults to None.

  • mode (str, default: 'lines' ) –

    description. Defaults to "lines".

  • fullfill (bool, default: False ) –

    description. Defaults to False.

  • dataframe (DataFrame | None, default: None ) –

    description. Defaults to None.

Returns:

  • dict ( dict ) –

    description

Source code in lettrade/plot/plotly/indicator.py
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
def plot_lines(
    *serieses: list[pd.Series | str],
    color: str = "#ffee58",
    width: int = 1,
    name: str | None = None,
    mode: str = "lines",
    fullfill: bool = False,
    dataframe: pd.DataFrame | None = None,
    **kwargs,
) -> dict:
    """_summary_

    Args:
        color (str, optional): _description_. Defaults to "#ffee58".
        width (int, optional): _description_. Defaults to 1.
        name (str | None, optional): _description_. Defaults to None.
        mode (str, optional): _description_. Defaults to "lines".
        fullfill (bool, optional): _description_. Defaults to False.
        dataframe (pd.DataFrame | None, optional): _description_. Defaults to None.

    Returns:
        dict: _description_
    """
    result = {}
    for series in serieses:
        plot_merge(
            result,
            plot_line(
                series=series,
                color=color,
                width=width,
                name=name,
                mode=mode,
                fullfill=fullfill,
                dataframe=dataframe,
                **kwargs,
            ),
        )
    return result

plot_mark ¤

plot_mark(
    series: Series | str,
    color: str = "#ffee58",
    width: int = 1,
    mode: str = "markers",
    name: str | None = None,
    fullfill: bool = False,
    dataframe: DataFrame | None = None,
    filter: Series | None = None,
    **kwargs
) -> dict

summary

Parameters:

  • series (Series | str) –

    description

  • color (str, default: '#ffee58' ) –

    description. Defaults to "#ffee58".

  • width (int, default: 1 ) –

    description. Defaults to 1.

  • mode (str, default: 'markers' ) –

    description. Defaults to "markers".

  • name (str | None, default: None ) –

    description. Defaults to None.

  • fullfill (bool, default: False ) –

    description. Defaults to False.

  • dataframe (DataFrame | None, default: None ) –

    description. Defaults to None.

  • filter (Series | None, default: None ) –

    description. Defaults to None.

Returns:

  • dict ( dict ) –

    description

Source code in lettrade/plot/plotly/indicator.py
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
def plot_mark(
    series: pd.Series | str,
    color: str = "#ffee58",
    width: int = 1,
    mode: str = "markers",
    name: str | None = None,
    fullfill: bool = False,
    dataframe: pd.DataFrame | None = None,
    filter: pd.Series | None = None,
    **kwargs,
) -> dict:
    """_summary_

    Args:
        series (pd.Series | str): _description_
        color (str, optional): _description_. Defaults to "#ffee58".
        width (int, optional): _description_. Defaults to 1.
        mode (str, optional): _description_. Defaults to "markers".
        name (str | None, optional): _description_. Defaults to None.
        fullfill (bool, optional): _description_. Defaults to False.
        dataframe (pd.DataFrame | None, optional): _description_. Defaults to None.
        filter (pd.Series | None, optional): _description_. Defaults to None.

    Returns:
        dict: _description_
    """

    return plot_line(
        series=series,
        color=color,
        width=width,
        mode=mode,
        name=name,
        fullfill=fullfill,
        dataframe=dataframe,
        filter=filter,
        **kwargs,
    )

plot_parabolic_sar ¤

plot_parabolic_sar(
    dataframe: DataFrame,
    long: str | None = "long",
    short: str | None = "short",
    width: int = 1,
    long_color: str = "#33BDFF",
    short_color: str = "#D105F5",
    filter: Series | None = None,
) -> dict

summary

Parameters:

  • dataframe (DataFrame) –

    description

  • long (str | None, default: 'long' ) –

    description. Defaults to "long".

  • short (str | None, default: 'short' ) –

    description. Defaults to "short".

  • width (int, default: 1 ) –

    description. Defaults to 1.

  • long_color (str, default: '#33BDFF' ) –

    description. Defaults to "#33BDFF".

  • short_color (str, default: '#D105F5' ) –

    description. Defaults to "#D105F5".

  • filter (Series | None, default: None ) –

    description. Defaults to None.

Returns:

  • dict ( dict ) –

    description

Source code in lettrade/plot/plotly/indicator.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
def plot_parabolic_sar(
    dataframe: pd.DataFrame,
    long: str | None = "long",
    short: str | None = "short",
    width: int = 1,
    long_color: str = "#33BDFF",
    short_color: str = "#D105F5",
    filter: pd.Series | None = None,
) -> dict:
    """_summary_

    Args:
        dataframe (pd.DataFrame): _description_
        long (str | None, optional): _description_. Defaults to "long".
        short (str | None, optional): _description_. Defaults to "short".
        width (int, optional): _description_. Defaults to 1.
        long_color (str, optional): _description_. Defaults to "#33BDFF".
        short_color (str, optional): _description_. Defaults to "#D105F5".
        filter (pd.Series | None, optional): _description_. Defaults to None.

    Returns:
        dict: _description_
    """
    if filter is not None:
        df_name = dataframe.name
        dataframe = dataframe.loc[filter]
        object.__setattr__(dataframe, "name", df_name)

    config = dict()

    if long is not None:
        plot_merge(
            config,
            plot_mark(
                series=long,
                color=long_color,
                name="psar_long",
                width=width,
                dataframe=dataframe,
            ),
        )
    if short is not None:
        plot_merge(
            config,
            plot_mark(
                series=short,
                color=short_color,
                name="psar_short",
                width=width,
                dataframe=dataframe,
            ),
        )
    return config