Skip to content

How to plot enter trade events #714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
romanbsd opened this issue Aug 10, 2022 · 1 comment
Closed

How to plot enter trade events #714

romanbsd opened this issue Aug 10, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@romanbsd
Copy link

Sorry if I missed it in the documentation, but how one plots the trade events (long or short)? It's hard to understand from the candlestick chart when exactly the position was opened (the beginning of the dashed line). Thanks!

@kernc
Copy link
Owner

kernc commented Aug 10, 2022

There are only trade exits on the P/L triangles plot.

I considered adding a gray line extending from trade entry to its exit triangle (I thought I uploaded an example image somewhere on the forum, but now I can't find it), but that has yet to manifest.

The relevant code is to be added here:

def _plot_pl_section():
"""Profit/Loss markers section"""
fig = new_indicator_figure(y_axis_label="Profit / Loss")
fig.add_layout(Span(location=0, dimension='width', line_color='#666666',
line_dash='dashed', line_width=1))
returns_long = np.where(trades['Size'] > 0, trades['ReturnPct'], np.nan)
returns_short = np.where(trades['Size'] < 0, trades['ReturnPct'], np.nan)
size = trades['Size'].abs()
size = np.interp(size, (size.min(), size.max()), (8, 20))
trade_source.add(returns_long, 'returns_long')
trade_source.add(returns_short, 'returns_short')
trade_source.add(size, 'marker_size')
if 'count' in trades:
trade_source.add(trades['count'], 'count')
r1 = fig.scatter('index', 'returns_long', source=trade_source, fill_color=cmap,
marker='triangle', line_color='black', size='marker_size')
r2 = fig.scatter('index', 'returns_short', source=trade_source, fill_color=cmap,
marker='inverted_triangle', line_color='black', size='marker_size')
tooltips = [("Size", "@size{0,0}")]
if 'count' in trades:
tooltips.append(("Count", "@count{0,0}"))
set_tooltips(fig, tooltips + [("P/L", "@returns_long{+0.[000]%}")],
vline=False, renderers=[r1])
set_tooltips(fig, tooltips + [("P/L", "@returns_short{+0.[000]%}")],
vline=False, renderers=[r2])
fig.yaxis.formatter = NumeralTickFormatter(format="0.[00]%")
return fig

@kernc kernc added the enhancement New feature or request label Feb 4, 2025
@kernc kernc self-assigned this Feb 19, 2025
@kernc kernc closed this as completed in 9286232 Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants