TP/SL Toolkit [AxeAlgo] — Strategy by AxeAlgo
By AxeAlgo
Performance Metrics
- Author: AxeAlgo
- Symbol: OANDA:EURUSD
- Timeframe: 15 minutes
- Win Rate: 13.9%
- Profit Factor: 0.047
Description
OVERVIEWTP/SL Toolkit [AxeAlgo] is a fast/slow EMA crossover strategy built around a modular take-profit and stop-loss engine. The crossover logic is intentionally simple — it exists mainly to give the exit engine something to trade — because the real purpose of this script is the exit engine itself: every take-profit, stop-loss, trailing-stop, break-even, time-based-exit and trend-filter calculation is written as a small, self-contained Pine Script function with no dependency on the rest of the script.That means any of these functions can be copy-pasted directly into your own strategy and used as-is, without pulling in anything else from this script. This publication is written and commented with that specific audience in mind — Pine coders who want ready-made, tested exit logic rather than another closed black-box signal.═══════════════════════════════════════════════════════════════════════WHAT THE STRATEGY DOESA fast EMA and a slow EMA are calculated from the chosen source price. When the fast EMA crosses above the slow EMA (a "Golden Cross"), the strategy opens a long and closes any open short. When the fast EMA crosses below the slow EMA (a "Death Cross"), it opens a short and closes any open long. This is one of the oldest and most widely known trend-following patterns in technical analysis — it performs best while a market is trending and is prone to whipsaws (false signals) in sideways, choppy conditions. An optional ADX-based trend filter (explained below) exists specifically to reduce that weakness.Every trade can optionally carry a take-profit and a stop-loss, calculated one of four ways, selectable from a single input:- Points mode places the exit a fixed number of ticks from entry. The distance is constant in price terms regardless of how far price has moved, and is converted from "points" to real price using the symbol's minimum tick, so the same input behaves sensibly on instruments with very different price scales.- Percentage mode places the exit a fixed percentage of the entry price away, so the distance automatically scales with price and stays comparable across symbols trading at very different price levels.- ATR mode places the exit a multiple of the Average True Range away from entry, so exits automatically widen during volatile conditions and tighten during quiet ones instead of staying fixed.- Pivot mode sets the stop-loss at the most recently confirmed swing high or low (market structure) and derives the take-profit as a risk:reward multiple of that stop's distance, mirroring how many discretionary traders place stops beyond structure. Because a pivot only confirms a fixed number of bars after it actually forms, this mode is inherently a few bars delayed relative to the live swing point — a stop placed at "the last pivot" was already that many bars old at the moment the trade opened. This is disclosed here because it affects how the backtest results for Pivot mode should be interpreted.On top of the static take-profit/stop-loss, two independent stop-management mechanisms are available and can be combined:- A trailing stop that recalculates every bar to sit a fixed distance (points, percentage, or ATR multiple — same three distance types as above) behind the best price reached since entry, and can only tighten in the trade's favor, never loosen.- A break-even stop that sits still until the trade has moved favorably by a chosen trigger distance, at which point it jumps once to entry price (plus an optional small offset) and stays there or better from then on, so the trade can no longer turn into a loss once triggered.When both are enabled, the script keeps whichever of the two is currently more protective on any given bar. On the chart, the take-profit and stop-loss are drawn as shaded zones (boxes) stretching from the entry price to the current bar rather than as flat lines — the stop-loss zone changes color once the break-even stop actually triggers, so a trade that has become risk-free is visually distinct from one still risking a real loss.An optional time-based exit force-closes a trade that is still open after a configurable number of bars, instead of waiting indefinitely for take-profit or stop-loss to be hit.An optional ADX trend filter withholds new entries while ADX is below a configurable threshold (i.e., while the market isn't trending strongly), which is the standard way to reduce EMA-crossover whipsaws in range-bound conditions. The filter only gates new entries — an already-open trade still closes normally on an opposite crossover regardless of the filter's state.A compact on-chart status table (optional, position configurable) shows the current trend direction, position, entry price, take-profit, stop-loss, computed risk:reward, and ADX reading, so the trade's state is readable at a glance instead of having to trace colored zones back to their exact values.═══════════════════════════════════════════════════════════════════════HOW TO USE ITAs a strategy: pick a TP/SL mode, optionally enable the trailing stop and/or break-even stop, optionally enable the ADX trend filter, and run it through the Strategy Tester like any other strategy. Every input has an in-editor tooltip explaining exactly which mode it applies to.As a toolkit: each exit mechanism — points-based, percentage-based, ATR-based, and pivot-based TP/SL, the trailing-stop updater, the break-even-stop calculator, the two-stop combiner, the time-based-exit check, and the ADX trend-filter gate — is written as an independent function with no external state, documented inline with what it takes in and what it returns. Any one of them can be lifted into another script without needing the rest of this one.═══════════════════════════════════════════════════════════════════════ALERTSTwo alert conditions are provided — a bullish crossover ("buy") signal and a bearish crossover ("sell") signal — both gated by the same trend filter used for actual entries, so an alert only fires when the strategy would genuinely take that trade.═══════════════════════════════════════════════════════════════════════BACKTESTING NOTES & DISCLAIMERThis script is published primarily to demonstrate and share reusable exit-management code, not as a ready-to-trade signal service or a claim of profitability. The default strategy settings do not model commission or slippage and use a fixed starting capital with no margin restriction — before drawing any conclusion from the Strategy Tester's results, set the commission, slippage, initial capital, and position sizing to values that realistically match your own broker/exchange and account size. Backtested and simulated results have well-known limitations (including curve-fitting and lack of live-market friction) and do not guarantee similar performance going forward.Nothing in this script or its description constitutes financial advice. Trading involves substantial risk of loss and is not suitable for everyone. Past performance — simulated or real — is not indicative of future results. Test thoroughly on a paper/demo account before considering any live use, and use position sizing appropriate to your own risk tolerance.═══════════════════════════════════════════════════════════════════════