This strategy is an automated trading system based on moving average crossover signals, optimized through a fixed risk-reward ratio. The strategy uses the crossover of Fast MA and Slow MA to determine market trend direction, combining preset stop-loss and take-profit levels for position risk management.
The core logic relies on crossover signals generated by two moving averages (10-period and 30-period). The system generates long signals when the fast MA crosses above the slow MA, and short signals when the fast MA crosses below. After each entry, the system automatically calculates stop-loss levels based on a preset 2% loss percentage and sets take-profit targets according to a 2.5 risk-reward ratio. This approach ensures each trade has consistent risk-reward characteristics.
This strategy combines classical technical analysis methods with modern risk management concepts to build a complete trading system. While it has certain limitations, continuous optimization and improvement allow the strategy to maintain stable performance across different market conditions. The key lies in constantly adjusting parameter settings based on actual trading results to find the most suitable configuration for the current market environment.
/*backtest start: 2019-12-23 08:00:00 end: 2024-12-25 08:00:00 period: 1d basePeriod: 1d exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("SOL 15m 2.5 R:R Strategy", overlay=true, margin_long=100, margin_short=100, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.1) //--------------------------------------------------- // User Inputs //--------------------------------------------------- // sym = input.symbol("swap", "Symbol") timeframe = input.timeframe("15", "Timeframe") fastLength = input.int(10, "Fast MA Length") slowLength = input.int(30, "Slow MA Length") stopLossPerc = input.float(2.0, "Stop Loss %", step=0.1) // This is an example; adjust to achieve ~45% win rate RR = input.float(2.5, "Risk to Reward Ratio", step=0.1) //--------------------------------------------------- // Data Sources //--------------------------------------------------- price = request.security("swap", timeframe, close) // Compute moving averages fastMA = ta.sma(price, fastLength) slowMA = ta.sma(price, slowLength) // Entry Conditions longCondition = ta.crossover(fastMA, slowMA) shortCondition = ta.crossunder(fastMA, slowMA) //--------------------------------------------------- // Stop Loss and Take Profit Calculation //--------------------------------------------------- var entryPrice = 0.0 if (strategy.position_size == 0) // not in a position if longCondition // Long entry entryPrice := price strategy.entry("Long", strategy.long) if shortCondition // Short entry entryPrice := price strategy.entry("Short", strategy.short) if strategy.position_size > 0 // We are in a long position if strategy.position_avg_price > 0 and strategy.position_size > 0 longStop = strategy.position_avg_price * (1 - stopLossPerc/100) longTarget = strategy.position_avg_price * (1 + (stopLossPerc/100)*RR) strategy.exit("Long Exit", "Long", stop=longStop, limit=longTarget) if strategy.position_size < 0 // We are in a short position if strategy.position_avg_price > 0 and strategy.position_size < 0 shortStop = strategy.position_avg_price * (1 + stopLossPerc/100) shortTarget = strategy.position_avg_price * (1 - (stopLossPerc/100)*RR) strategy.exit("Short Exit", "Short", stop=shortStop, limit=shortTarget) //--------------------------------------------------- // Plotting //--------------------------------------------------- plot(fastMA, color=color.new(color.teal, 0), title="Fast MA") plot(slowMA, color=color.new(color.orange, 0), title="Slow MA")