
This strategy is a trading system based on dual moving average crossovers, combined with a specific trading time window and risk management mechanisms. The core logic utilizes the crossover relationship between a fast moving average and a slow moving average to determine changes in market trends, thereby generating buy and sell signals. The strategy also implements trade execution within fixed time periods and sets stop-loss and take-profit mechanisms to control risk. This is a complete trading system that combines technical analysis and risk management, suitable for intraday traders and short-term trend-following investors.
The core principle of this strategy is based on a moving average crossover system, implemented as follows:
Dual Moving Average Calculation:
Trade Signal Generation:
Trading Time Window:
Risk Management Mechanism:
System Logic Flow:
Through this systematic approach, the strategy achieves an organic combination of trend identification and risk control.
Analyzing the code implementation of this strategy, the following significant advantages can be summarized:
Effectiveness of Trend Following: The dual moving average crossover is a classic trend identification method that can effectively capture medium and short-term market trend changes. The fast moving average (10-period) responds sensitively to price changes, while the slow moving average (25-period) filters out short-term market noise.
Standardized Trading Time Management: By setting a specific trading window (08:30-15:00), the strategy avoids low liquidity risks during non-primary trading sessions and focuses on trading during the most active market hours.
Comprehensive Risk Control Mechanism: The strategy incorporates built-in stop-loss and take-profit functions, with each trade having preset risk and reward targets, ensuring standardized fund management.
Forced Closing Mechanism: By forcing position closure at 15:00 daily, overnight position risks are avoided, making it particularly suitable for intraday traders who do not wish to bear overnight risks.
Flexible Adjustable Parameters: Key parameters in the strategy (moving average periods, stop-loss and take-profit ticks, trading quantity) are designed as input parameters, allowing users to adjust according to different market environments and personal risk preferences.
Clear Trading Logic: The strategy implements clear entry and exit conditions without complex decision logic, making it easy to understand and execute, reducing the possibility of operational errors.
Despite the relatively comprehensive design of this strategy, the following potential risks still exist:
Moving Average Lag Risk: Moving averages are inherently lagging indicators and may generate delayed signals in rapidly changing markets, leading to untimely entries or exits, especially producing frequent false signals during sideways, oscillating markets.
Fixed Stop-Loss Risk: The strategy uses a fixed number of ticks as stop-loss settings without considering changes in market volatility. The stop-loss might be too small in high-volatility environments and too large in low-volatility environments.
Time Window Limitations: Fixed trading time windows may miss important trading opportunities outside the window, especially when significant market events occur during non-trading sessions.
Insufficient Fund Management: The strategy uses a fixed trading quantity without dynamically adjusting position size based on account size and risk level.
Lack of Market Environment Adaptability: Dual moving average crossover strategies perform well in trending markets but may lead to frequent trading and losses in oscillating markets.
Based on code analysis and strategy characteristics, the following are several possible optimization directions:
Dynamic Stop-Loss and Take-Profit Mechanism:
Add Trend Filters:
Optimize Moving Average Types:
Add Trailing Stop-Loss Mechanism:
Refine Trading Time Window:
Implement Dynamic Position Management:
The “Dual Moving Average Crossover with Trading Window and Risk Management Strategy” is a complete trading system that combines trend following and risk management functionality. It identifies market trend changes through the crossover relationship between fast and slow moving averages, while combining specific trading time windows and stop-loss/take-profit mechanisms to achieve a systematic trading decision process.
The main advantages of this strategy lie in its clear logic, comprehensive risk control, and standardized operations. However, as a system based on moving averages, it also faces inherent risks such as signal lag and false signals. By introducing dynamic stop-loss, trend filters, optimizing moving average types, implementing trailing stops, and dynamic position management, the strategy’s robustness and adaptability can be significantly enhanced.
For intraday traders and short-term trend followers, this strategy combining technical analysis and risk management provides a solid trading framework. Through continuous optimization of parameters and adaptive adjustments to market environments, this strategy has the potential to maintain relatively stable performance under different market conditions.
/*backtest
start: 2025-02-24 00:00:00
end: 2025-02-28 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"SOL_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © szapatamejia193
//@version=5
strategy("Custom MACrossOver", overlay=true)
// Parámetros configurables
fastLength = input(10, title="Fast Period")
slowLength = input(25, title="Slow Period")
stopLossTicks = input(50, title="Stop (Ticks)")
profitTargetTicks = input(50, title="Target (Ticks)")
defaultQuantity = input(2, title="Default Quantity")
// Cálculo de medias móviles
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// Condiciones de cruce
longCondition = ta.crossover(fastMA, slowMA)
shortCondition = ta.crossunder(fastMA, slowMA)
// Guardar precio de entrada
var float tradeEntryPrice = na
// Definir rango de mercado abierto (08:30 - 15:00)
market_open = (hour >= 8 and minute >= 30) and (hour < 15)
// Apertura de operaciones
if (market_open)
if (longCondition)
strategy.entry("Long", strategy.long, defaultQuantity)
tradeEntryPrice := close
else if (shortCondition)
strategy.entry("Short", strategy.short, defaultQuantity)
tradeEntryPrice := close
// Definir Stop Loss y Take Profit
if (not na(tradeEntryPrice))
stopLossPrice = tradeEntryPrice - stopLossTicks * syminfo.mintick
takeProfitPrice = tradeEntryPrice + profitTargetTicks * syminfo.mintick
if (strategy.position_size > 0) // Si estamos en largo
strategy.exit("SL/TP", from_entry="Long", stop=stopLossPrice, limit=takeProfitPrice)
else if (strategy.position_size < 0) // Si estamos en corto
strategy.exit("SL/TP", from_entry="Short", stop=stopLossPrice, limit=takeProfitPrice)
// Salir de todas las operaciones a las 15:00
if (hour == 15 and minute == 0)
strategy.close_all()
// Dibujar medias móviles
plot(fastMA, title="Fast MA", color=color.blue)
plot(slowMA, title="Slow MA", color=color.red)