Early Profit Taking Moving Average Opening Bell Exit Strategy
This strategy implements long and short based on moving average crossovers, and exits only in the afternoon based on early profit-taking statistics to avoid being trapped by high opening volatility.

Overview
This strategy implements long and short based on moving average crossovers, and exits only in the afternoon based on early profit-taking statistics to avoid being trapped by high opening volatility.
Strategy Logic
The strategy uses 3 moving averages with different parameters: 14-day, 28-day and 56-day lines. It goes long when the 14-day line crosses above the 56-day one, and goes short when crossing below. This basic approach tracks long-term trends. To filter out some noise, the 28-day line is added as a reference, so that signals are triggered only when the 14-day line is also above or below the 28-day one.
The key innovation is that it stops loss and takes profit only between 4 pm and 5 pm. Statistics show 70% chance of daily high/low happening in the first hour after opening. To avoid impact from high opening volatility, exits are enabled only during regular afternoon trading hours.
Advantage Analysis
The advantages of this strategy include:
- Track mid-long term trends, avoid excessive noise
- Utilize statistics of opening volatility for stop loss logic to avoid false breakouts
- Simple and intuitive logic, easy to understand and modify
Risks and Solutions
There are also some risks:
- Missing opportunities if reversal happens early in the day. Can test compatibility with specific stocks.
- Still risks of being trapped after hours. Can test loosening stop loss range.
- Bad setting of backtest period leading to overfitting. Should expand backtest duration.
Enhancement Opportunities
Some ways to further optimize the strategy:
- Test different moving average combinations to find optimum parameters
- Fine tune stop loss range based on volatility patterns of specific stocks
- Add volume filter to avoid traps
- Add dynamic stops to trail pullbacks after breakouts
Conclusion
The strategy has clear and simple logic, effectively uses opening features for stop loss to avoid volatility traps. But risks exist of missing chances and being trapped. Parameters should be adjusted per stock. Overall a simple yet effective idea for novice quants.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 2014 | Backtest Start Year |
| v_input_2 | true | Backtest Start Month |
| v_input_3 | 2 | Backtest Start Day |
| v_input_4 | 2025 | Backtest Stop Year |
| v_input_5 | 12 | Backtest Stop Month |
| v_input_6 | 30 | Backtest Stop Day |
Source Pine Script
/*backtest
start: 2023-11-23 00:00:00
end: 2023-11-30 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy("MAC 1st Trading Hour Walkover", overlay=true)
// Setting up timeperiod for testing
startPeriodYear = input(2014, "Backtest Start Year")
startPeriodMonth = input(1, "Backtest Start Month")
startPeriodDay = input(2, "Backtest Start Day")
testPeriodStart = timestamp(startPeriodYear, startPeriodMonth, startPeriodDay, 0, 0)
stopPeriodYear = input(2025, "Backtest Stop Year")
stopPeriodMonth = input(12, "Backtest Stop Month")
stopPeriodDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(stopPeriodYear, stopPeriodMonth, stopPeriodDay, 0, 0)
// Moving Averages
ema14 = ema(close, 14)
ema28 = ema(close, 28)
sma56 = sma(close, 56)
// Plot
plot(ema14, title="ema14", linewidth=2, color=green)
plot(ema28, title="ema28", linewidth=2, color=red)
plot(sma56, title="sma56", linewidth=3, color=blue)
// Strategy
goLong = cross(ema14, sma56) and ema14 > ema28
goShort = cross(ema14, sma56) and ema14 < ema28
// Strategy.When to enter
if time >= testPeriodStart
if time <= testPeriodStop
strategy.entry("Go Long", strategy.long, 1.0, when=goLong)
strategy.entry("Go Short", strategy.short, 1.0, when=goShort)
// Strategy.When to take profit
if time >= testPeriodStart
if time <= testPeriodStop
strategy.exit("Close Long", "Go Long", profit=2000)
strategy.exit("Close Short", "Go Short", profit=2000)
// Strategy.When to stop out
// Some studies show that 70% of the days high low happen in the first hour
// of trading. To avoid having that volatility fire our loss stop we
// ignore price action in the morning, but allow stops to fire in the afternoon.
if time("60", "1000-1600")
strategy.exit("Close Long", "Go Long", loss=500)
strategy.exit("Close Short", "Go Short", loss=500)Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-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/Early-Profit-Taking-Moving-Average-Opening-Bell-Exit-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
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h
- Dynamic Bollinger Bands Breakout Quantitative Trading StrategyPine Script · Breakout · 2d
- Flexible Long Short Trading Strategy Based on Keltner ChannelsPine Script · Breakout · 1d
- Momentum Breakout Trading Strategy 435896Pine Script · Breakout · 1d
- Multi Filter Trend Breakthrough Smart Moving Average Trading StrategyPine Script · Breakout · 1h
- Multi Indicator Trend Breakout Strategy with Dynamic Stop LossPine Script · Breakout · 1d