Trailing Stop Loss Percent Strategy
This strategy is designed for a long position entry with a date-specific trigger and a trailing stop loss mechanism for risk management. It is particularly useful for traders who want to automate their entries based…

Overview
This strategy is designed for a long position entry with a date-specific trigger and a trailing stop loss mechanism for risk management. It is particularly useful for traders who want to automate their entries based on specific calendar dates and manage their positions with a dynamic risk control method like a trailing stop loss.
Strategy Logic
The strategy first takes input of specific entry dates, including month and day, then calculates the accurate entry timestamp based on these dates. It also inputs the percentage parameter for trailing stop loss.
On the entry date, the strategy will open a long position. At the same time, it records the highest price (highestPrice) and stop loss price (stopLoss). The highestPrice keeps updating over time, while the stopLoss trails it by a certain percentage downwards.
If the price falls below the stopLoss, the position will be closed. Otherwise, the position remains open, and the stopLoss keeps trailing the highestPrice to lock in profits and control risk.
Advantage Analysis
The main advantages of this strategy are:
- Automated entry based on specific dates. Suitable for strategies trading around significant events.
- Applies trailing stop loss to dynamically lock in profits and effectively manage risks.
- Stop loss set as percentage, simple and intuitive to operate. Customizable loss range.
- Allows long-term holding to maximize upside potential.
Risk Analysis
There are also some risks:
- Risk of stop loss failure. If price drops sharply below stop loss briefly then bounces back, the position may get stopped out and fail to capture the rebound.
- No limit on maximum loss. If trailing stop loss percentage set too wide, max loss can exceed expectations.
Possible improvements:
- Combine other indicators to pause trailing stop when market faces correction, avoiding failure.
- Set stop loss percentage carefully, usually under 10%. Or set maximum tolerable loss.
Optimization
Possible optimization directions:
- Add profit taking mechanisms. When price rises 50% etc, take partial or full profits.
- Optimize trailing width based on market regime signals from indices. Widen when market consolidating.
- Enhance position sizing. Consider pyramiding when new highs breakout for greater profits.
Conclusion
This strategy provides automated date-based entry and dynamic risk management via trailing stop loss. Simple and intuitive to operate, suitable for long-term holdings. Further optimizations can make it a very practical quant trading strategy.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | true | Entry Day |
| v_input_int_2 | true | Entry Month |
| v_input_int_3 | 2023 | Entry Year |
| v_input_float_1 | 5 | Trailing Stop Loss (%) |
Source Pine Script
/*backtest
start: 2024-01-24 00:00:00
end: 2024-01-31 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title="Trailing Stop Loss Percent",
overlay=true, pyramiding=1)
// Input for the specific entry date
entryDay = input.int(defval = 1, title = "Entry Day", minval = 1, maxval = 31)
entryMonth = input.int(defval = 1, title = "Entry Month", minval = 1, maxval = 12)
entryYear = input.int(defval = 2023, title = "Entry Year", minval = 1970)
// Calculate the entry date timestamp
entryDate = timestamp(entryYear, entryMonth, entryDay, 00, 00)
// Trailing Stop Loss Percentage
trailStopPercent = input.float(defval = 5.0, title = "Trailing Stop Loss (%)", minval = 0.1)
// Entry Condition
enterTrade = true
// Variables to track the highest price and stop loss level since entry
var float highestPrice = na
var float stopLoss = na
// Update the highest price and stop loss level
if strategy.position_size > 0
highestPrice := math.max(highestPrice, high)
stopLoss := highestPrice * (1 - trailStopPercent / 100)
// Enter the strategy
if enterTrade
strategy.entry("Long Entry", strategy.long)
highestPrice := high
stopLoss := highestPrice * (1 - trailStopPercent / 100)
// Exit the strategy if the stop loss is hit
if strategy.position_size > 0 and low <= stopLoss
strategy.close("Long Entry")
// Plotting the stop loss level for reference
plot(strategy.position_size > 0 ? stopLoss : na, "Trailing Stop Loss", color=color.red)Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-01. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Trailing-Stop-Loss-Percent-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- 5 Day Moving Average Channel Breakout Strategy Combined With Mileage ConceptPine Script · Breakout · 1d
- ATR Trailing Stops StrategyPine Script · Breakout · 1h
- ATR Trend Breakout StrategyPine Script · Breakout · 1d
- Adaptive Bollinger Breakout with Moving Average Quantitative Strategy SystemPine Script · Breakout · 1h
- Adaptive Channel Breakout StrategyPine Script · Breakout · 1d
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h