Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
PlusEV Wiki Page
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Component:Trade Execution
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= Trade Execution Engine = == Purpose == '''"How do we execute & manage trade to protect capital & maximize profit?"''' This component is the executor. It takes signals from Layer 4 and: # Converts signals to trades with realistic slippage # Monitors open positions (stop, target, time) # Manages stops dynamically (breakeven, trailing) # Calculates complete P&L with all costs ---- == Trading Market Principle == '''"Let winners run, cut losers short. Protect profits once we have them."''' * Breakeven stop = protect capital once trade is working β move stop to entry at 25pt profit * Trailing stop = let winners run β trail stop behind price using ATR * Time exit = don't hold losing trades forever β 8 hour maximum * Slippage modeling = realistic execution β winners don't fill perfectly either ---- == Trade Lifecycle == <pre> βββββββββββββββββββββββββββββββββββββββββ β Signal from Layer 4 β β (Direction, Entry, Stop, Target) β βββββββββββββββββββββββββββββββββββββββββ β βΌ βββββββββββββββββββββββββββββββββββββββββ β ENTRY EXECUTION β β β’ Add entry slippage (1-2 pts) β β β’ Calculate costs (commission + CTT) β β β’ Create Trade object β βββββββββββββββββββββββββββββββββββββββββ β βΌ βββββββββββββββββββββββββββββββββββββββββ β POSITION MANAGEMENT (per bar) β β β β 1. Update MFE/MAE tracking β β 2. Check breakeven activation (25pt) β β 3. Update trailing stop (ATR-based) β β 4. Check stop hit β β 5. Check target hit β β 6. Check time exit (8 hours) β βββββββββββββββββββββββββββββββββββββββββ β βΌ βββββββββββββββββββββββββββββββββββββββββ β EXIT EXECUTION β β β’ Add exit slippage (stop=2pt, TP=0.5pt)β β β’ Calculate final P&L β β β’ Record exit reason β βββββββββββββββββββββββββββββββββββββββββ </pre> ---- == Two-Phase Stop Management == === Phase 1: Breakeven Stop === Once trade is profitable by 25 points, move stop to entry price + buffer: <pre> IF current_profit >= 25 points: LONG: stop = entry_price + 2 (buffer) SHORT: stop = entry_price - 2 (buffer) </pre> '''Purpose:''' Lock in a no-loss trade (or small profit with buffer). === Phase 2: Trailing Stop === After profit exceeds activation threshold, trail stop behind price: <pre> Trailing Distance = ATR Γ 2.0 (minimum 15 points) LONG: IF profit >= 20 points: new_stop = current_high - trailing_distance IF new_stop > current_stop: current_stop = new_stop // Only moves UP SHORT: IF profit >= 20 points: new_stop = current_low + trailing_distance IF new_stop < current_stop: current_stop = new_stop // Only moves DOWN </pre> '''Purpose:''' Let winners run while protecting accumulated profit. ---- == ATR Calculation == ATR (Average True Range) measures volatility for adaptive trailing: <pre> True Range = max( high - low, |high - previous_close|, |low - previous_close| ) ATR = average(True Range over 14 bars) Trailing Distance = ATR Γ 2.0 </pre> '''Effect:''' * High volatility β wider trailing stop (more room to breathe) * Low volatility β tighter trailing stop (protect more profit) ---- == Slippage Model == Realistic slippage based on market conditions: === Entry Slippage === <pre> entry_slippage = base (1.0 pt) + position_impact (0.1 Γ lots, capped at 2.0) + volatility (0.5 pt) Minimum: 0.5 points </pre> === Exit Slippage === {| class="wikitable" |- ! Exit Type !! Slippage !! Reason |- | Stop Loss || 2.0 points || Panic selling, worse fills |- | Take Profit || 0.5 points || Limit order, better fills |- | Time Exit || 0.0 points || Market order at close |} ---- == MFE/MAE Tracking == Tracks Maximum Favorable and Adverse Excursion for each trade: {| class="wikitable" |- ! Metric !! What It Measures !! Usage |- | '''MFE''' || Best profit point reached during trade || Entry timing quality |- | '''MAE''' || Worst loss point during trade || Stop placement optimization |} <pre> LONG: MFE = max profit seen = (highest_high - entry) Γ 100 Γ lots MAE = max loss seen = (lowest_low - entry) Γ 100 Γ lots SHORT: MFE = max profit seen = (entry - lowest_low) Γ 100 Γ lots MAE = max loss seen = (entry - highest_high) Γ 100 Γ lots </pre> ---- == Exit Conditions == Trades exit when any condition is met (checked in order): {| class="wikitable" |- ! Priority !! Condition !! Exit Price !! Reason Code |- | 1 || Stop hit || stop_price - slippage (LONG) || "stop" |- | 2 || Target hit || target_price - slippage (LONG) || "target" |- | 3 || Time limit (8 hours) || current_close || "timeout" |} ---- == Configuration == {| class="wikitable" |- ! Parameter !! Value !! Description |- | <code>base_slippage_points</code> || 1.0 || Base entry slippage |- | <code>market_impact_factor</code> || 0.1 || Slippage per lot |- | <code>max_market_impact_slippage</code> || 2.0 || Cap on position slippage |- | <code>stop_loss_slippage</code> || 2.0 || Additional slippage on stops |- | <code>take_profit_slippage</code> || 0.5 || Reduced slippage on targets |- | <code>max_holding_period_minutes</code> || 480 || 8 hours max holding |- | <code>enable_trailing_stop</code> || True || Enable trailing stop |- | <code>trailing_stop_method</code> || "ATR_MULTIPLE" || ATR-based or fixed |- | <code>atr_period</code> || 14 || ATR lookback period |- | <code>atr_multiplier</code> || 2.0 || Trailing = ATR Γ 2 |- | <code>enable_breakeven_stop</code> || True || Enable breakeven |- | <code>breakeven_activation</code> || 25.0 || Points profit to activate |- | <code>breakeven_buffer</code> || 2.0 || Buffer above/below entry |- | <code>max_concurrent_trades</code> || 3 || Maximum open positions |} ---- == Output == '''Trade Object (after exit):''' {| class="wikitable" |- ! Field !! Type !! Description |- | <code>entry_price</code> || float || Actual entry (with slippage) |- | <code>exit_price</code> || float || Actual exit (with slippage) |- | <code>exit_reason</code> || str || "stop", "target", "timeout" |- | <code>gross_pnl_inr</code> || float || P&L before costs |- | <code>net_pnl_inr</code> || float || P&L after commission + CTT |- | <code>brokerage_cost</code> || float || Commission paid |- | <code>tax_cost</code> || float || CTT paid |- | <code>max_favorable_excursion_inr</code> || float || Best P&L during trade |- | <code>max_adverse_excursion_inr</code> || float || Worst P&L during trade |- | <code>current_stop_price</code> || float || Final stop (after trailing) |} ---- == Dependencies == '''Upstream:''' * [[Component:Signal_Generation|signal_generation_trade_management.py]] - Provides signals to execute '''Uses:''' * SignalGenerationTradeManagement.execute_signal() - For entry * SignalGenerationTradeManagement.close_trade() - For exit ---- == Quick Reference == {| class="wikitable" |- ! Event !! Action |- | New signal received || Execute with slippage, create trade |- | Profit reaches 25pt || Move stop to breakeven (entry + 2pt) |- | Profit reaches 20pt || Start trailing stop (ATR Γ 2) |- | Price hits stop || Exit with 2pt slippage, reason="stop" |- | Price hits target || Exit with 0.5pt slippage, reason="target" |- | 8 hours elapsed || Exit at market, reason="timeout" |- | Higher high (LONG) || Trail stop up if trailing active |- | Lower low (SHORT) || Trail stop down if trailing active |} ---- [[Category:Components]] [[Category:Layer 5]]
Summary:
Please note that all contributions to PlusEV Wiki Page may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Component:Trade Execution
(section)
Add topic