feat: Add linked trades and trade statistics to trading plan view
This commit is contained in:
parent
a2bbd31f27
commit
1506deff0d
@ -874,6 +874,52 @@ def trading_plan_page():
|
||||
if plan.profit_factor:
|
||||
st.write(f"**Profit Factor:** {plan.profit_factor}")
|
||||
|
||||
# Add Linked Trades section
|
||||
st.markdown("### Linked Trades")
|
||||
plan_trades = get_plan_trades(plan.id)
|
||||
if plan_trades:
|
||||
total_pl = 0
|
||||
winning_trades = 0
|
||||
total_trades = len(plan_trades)
|
||||
|
||||
for trade in plan_trades:
|
||||
with st.expander(f"{trade['ticker']} - {trade['entry_date']}"):
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
st.write(f"**Entry:** ${trade['entry_price']:.2f}")
|
||||
st.write(f"**Shares:** {trade['shares']}")
|
||||
st.write(f"**Direction:** {trade['direction']}")
|
||||
if trade['strategy']:
|
||||
st.write(f"**Strategy:** {trade['strategy']}")
|
||||
|
||||
with col2:
|
||||
if trade['exit_price']:
|
||||
pl = (trade['exit_price'] - trade['entry_price']) * trade['shares']
|
||||
total_pl += pl
|
||||
if pl > 0:
|
||||
winning_trades += 1
|
||||
st.write(f"**Exit:** ${trade['exit_price']:.2f}")
|
||||
st.write(f"**P/L:** ${pl:.2f}")
|
||||
st.write(f"**Exit Date:** {trade['exit_date']}")
|
||||
else:
|
||||
st.write("**Status:** Open")
|
||||
|
||||
# Display trade statistics
|
||||
st.markdown("#### Trade Statistics")
|
||||
col1, col2 = st.columns(2)
|
||||
with col1:
|
||||
st.write(f"**Total Trades:** {total_trades}")
|
||||
st.write(f"**Winning Trades:** {winning_trades}")
|
||||
if total_trades > 0:
|
||||
st.write(f"**Win Rate:** {(winning_trades/total_trades)*100:.2f}%")
|
||||
|
||||
with col2:
|
||||
st.write(f"**Total P/L:** ${total_pl:.2f}")
|
||||
if total_trades > 0:
|
||||
st.write(f"**Average P/L per Trade:** ${total_pl/total_trades:.2f}")
|
||||
else:
|
||||
st.info("No trades linked to this plan")
|
||||
|
||||
st.markdown("### Strategy Details")
|
||||
st.write("**Entry Criteria:**")
|
||||
st.write(plan.entry_criteria)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user