Strategy vault / Mean reversion
EMA100 and NUPL Relative Unrealized Profit Quantitative Trading Strategy
This trading strategy is based on three indicators: the 100-period Exponential Moving Average (EMA100), Net Unrealized Profit/Loss (NUPL), and Relative Unrealized Profit. It generates trading signals by determining…

Overview
This trading strategy is based on three indicators: the 100-period Exponential Moving Average (EMA100), Net Unrealized Profit/Loss (NUPL), and Relative Unrealized Profit. It generates trading signals by determining the crossover of price with EMA100 and the positivity or negativity of NUPL and Relative Unrealized Profit. A long signal is triggered when the price crosses above EMA100 and both NUPL and Relative Unrealized Profit are positive. A short signal is triggered when the price crosses below EMA100 and both NUPL and Relative Unrealized Profit are negative. The strategy uses a fixed position size of 10% and sets a stop loss of 10%.
Strategy Principles
- Calculate the 100-period EMA as the main trend indicator
- Use NUPL and Relative Unrealized Profit as auxiliary indicators to confirm trend strength and sustainability
- Generate long/short signals when the price crosses above/below EMA100 while NUPL and Relative Unrealized Profit are simultaneously positive/negative
- Adopt a fixed position size of 10% and set a stop loss of 10% to control risk
- When holding a long position, if the price falls below the stop loss price, close the long position; when holding a short position, if the price rises above the stop loss price, close the short position
Advantage Analysis
- Simple and easy to understand: The strategy logic is clear and uses common technical indicators, making it easy to understand and implement
- Trend following: By capturing the main trend using EMA100, it is suitable for use in trending markets
- Risk control: Setting fixed position sizes and stop losses can effectively control risk
- Adaptability: The strategy can be applied to various markets and trading instruments
Risk Analysis
- False signals: In choppy markets, frequent crossovers between price and EMA100 may generate more false signals, leading to losses
- Lag: As a lagging indicator, EMA may react slowly at trend reversals, missing the best entry opportunities
- Parameter optimization: Strategy parameters (such as EMA period, position size, stop loss ratio) need to be optimized for different markets, and inappropriate parameters may result in poor strategy performance
Optimization Directions
- Parameter optimization: Optimize parameters such as EMA period, position size, and stop loss ratio to improve strategy performance
- Signal filtering: Add other technical indicators or market sentiment indicators to filter false signals
- Dynamic position management: Dynamically adjust positions based on market volatility, account profit/loss, and other factors to increase returns and control risk
- Long-short combination: Hold both long and short positions simultaneously to hedge market risk and improve strategy stability
Summary
This trading strategy generates trading signals through three indicators: EMA100, NUPL, and Relative Unrealized Profit. It has advantages such as clear logic, controllable risk, and strong adaptability. At the same time, it also has risks such as false signals, lag, and parameter optimization. In the future, the strategy can be optimized and improved through parameter optimization, signal filtering, dynamic position management, and long-short combinations.
Source Pine Script
/*backtest
start: 2023-06-11 00:00:00
end: 2024-06-16 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Scalping Strategy with EMA 100, NUPL, and Relative Unrealized Profit", overlay=true)
// Input for EMA period
emaPeriod = input.int(100, title="EMA Period", minval=1)
ema100 = ta.ema(close, emaPeriod)
plot(ema100, color=color.blue, title="EMA 100")
// Placeholder function for NUPL (Net Unrealized Profit/Loss)
// Replace this with actual NUPL data or calculation
NUPL = close * 0.0001 // Dummy calculation
// Placeholder function for relative unrealized profit
// Replace this with actual relative unrealized profit data or calculation
relativeUnrealizedProfit = close * 0.0001 // Dummy calculation
// Define conditions for long and short entries
longCondition = ta.crossover(close, ema100) and NUPL > 0 and relativeUnrealizedProfit > 0
shortCondition = ta.crossunder(close, ema100) and NUPL < 0 and relativeUnrealizedProfit < 0
// Plot buy and sell signals on the chart
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal")
// Calculate stop loss levels
longStopLoss = close * 0.90
shortStopLoss = close * 1.10
// Strategy entry and exit rules
if (longCondition)
strategy.entry("Long", strategy.long, stop=longStopLoss)
if (shortCondition)
strategy.entry("Short", strategy.short, stop=shortStopLoss)
// Set stop loss levels for active positions
if (strategy.position_size > 0)
strategy.exit("Exit Long", "Long", stop=longStopLoss)
if (strategy.position_size < 0)
strategy.exit("Exit Short", "Short", stop=shortStopLoss)
// Alerts for long and short entries
alertcondition(longCondition, title="Long Entry Alert", message="Long entry signal based on EMA 100, NUPL, and relative unrealized profit")
alertcondition(shortCondition, title="Short Entry Alert", message="Short entry signal based on EMA 100, NUPL, and relative unrealized profit")
// Visualize the entry conditions
plotshape(series=longCondition, location=location.belowbar, color=color.blue, style=shape.cross, title="Long Condition")
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.cross, title="Short Condition")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-06-17. 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/EMA100-and-NUPL-Relative-Unrealized-Profit-Quantitative-Trading-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
- 1 2 3 Pattern Quantitative Trading Strategy with EMAs MACD and 4th Candle ExtensionPine Script · Mean reversion · 1h
- ATR and EMA based Dynamic Take Profit and Stop Loss Adaptive StrategyPine Script · Mean reversion · 1h
- Advanced 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d
- Advanced Quantitative Trading Strategy Combining RSI Divergence and Moving AveragesPine Script · Mean reversion · 1h
- Advanced Quantitative Trend Following and Cloud Reversal Composite Trading StrategyPine Script · Mean reversion · 1d