Strategy vault / Mean reversion
Closing Position Strategy
The core idea of this strategy is to buy stocks at market close and sell them at next day's market open, in order to profit from the price increase at open.

Overview
The core idea of this strategy is to buy stocks at market close and sell them at next day's market open, in order to profit from the price increase at open.
Strategy Logic
The strategy is based on two judgments:
Intraday traders tend to go long at market open, driving up opening prices.
Closing prices reflect the true value of stocks.
Specifically, the strategy checks if the closing price is above the 200-day simple moving average at market close (20:00). If yes, it goes long. If not, it goes short.
At next day's market open (9:30), it closes long positions opened on previous day, and closes short positions as well.
By buying at low closing prices and selling at high opening prices, it aims to profit from the opening price increase.
Advantage Analysis
The advantages of this strategy:
Utilize intraday traders' inertia to go long at open and sell for profit.
The 200-day MA helps identify the trend.
Low frequency with only two trade points daily reduces transaction costs.
Backtesting provides confidence in parameters.
Automated system minimizes emotional interference.
Risk Analysis
The risks to consider:
Opening price may reverse sharply resulting in losses.
Closing price may be manipulated.
Stock suspension may prevent opening positions.
High transaction costs make frequent trading expensive.
Improper parameter tuning leads to excessive trading or losses.
Solutions include:
Set stop loss to limit losses.
Check volume and adjustments to validate closing price.
Prioritize liquid stocks.
Optimize MA length and trade times.
Improvement Directions
The strategy can be improved by:
Adding stops to cut losses on opening reversal.
Using other indicators to determine price range.
Considering liquidity risk and selecting liquid stocks.
Testing different MA parameters.
Optimizing open/close times.
Checking news for closing price validity.
Considering transaction costs and selecting low-cost stocks.
Using multifactor models.
Conclusion
The strategy profits from the opening price increase by buying low at close and selling high at open. It has some advantages but also risks to consider. Further optimizations on parameters, stops, stock selection can improve performance. Overall it provides a simple closing position strategy idea for intraday traders.
Source Pine Script
/*backtest
start: 2023-10-10 00:00:00
end: 2023-11-09 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Youngmoneyinvestments
//@version=5
strategy("End of Day Trading Strategy", overlay=true)
// Get the daily open, high, low, and close prices
daily_open = request.security(syminfo.tickerid, "D", open)
daily_close = request.security(syminfo.tickerid, "D", close)
// Calculate the 200 period SMA on daily close
sma200 = ta.sma(daily_close, 200)
// Define the entry and exit conditions
end_of_day = (hour == 20) and (minute == 0) // Assuming the end of the regular trading hours is 20:00
start_of_day = (hour == 9) and (minute == 30) // Assuming the start of the trading session is 09:30
long_condition = end_of_day and (daily_close > sma200)
short_condition = end_of_day and (daily_close < sma200)
// Execute the strategy logic
if (long_condition)
strategy.entry("Long", strategy.long)
if (short_condition)
strategy.entry("Short", strategy.short)
// Exit conditions
if (strategy.position_size > 0 and start_of_day) // If we are long, sell at the open of the session
strategy.close("Long")
if (strategy.position_size < 0 and start_of_day) // If we are short, buy at the open of the session
strategy.close("Short")
// Plot the SMA on the chart
plot(sma200, "200 SMA", color=color.blue)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-10. 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/Closing-Position-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
- 3 10 Oscillator Profile Flagging StrategyPine Script · Mean reversion · 1d
- A Trend Reversal Strategy Based on Moving Averages Price Patterns and VolumePine Script · Mean reversion · 1d
- Adaptive Mean Reversion Trading Strategy Based on Chande Momentum OscillatorPine Script · Mean reversion · 1d
- Adaptive Trading Strategy Combining Dynamic Trend Reversal and Stochastic IndicatorPine Script · Mean reversion · 1d
- 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