The resource loading... loading...

Risk-Reward Ratio Optimized Strategy Based on Moving Average Crossover

Author: ChaoZhang, Date: 2024-12-27 15:46:05
Tags: MASMARRSLTP

img

Overview

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.

Strategy Principle

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.

Strategy Advantages

  1. Systematic Risk Management: Achieves standardized capital management through fixed stop-loss percentages and risk-reward ratios
  2. Objective Trading Mechanism: Signal system based on MA crossovers eliminates subjective judgment bias
  3. Strong Parameter Adaptability: Key parameters like stop-loss percentage and risk-reward ratio can be flexibly adjusted
  4. High Automation Level: Automated processes from signal generation to position management reduce human error

Strategy Risks

  1. Choppy Market Risk: MA crossover signals may generate frequent false breakouts in ranging markets
  2. Slippage Risk: Actual execution prices may significantly deviate from signal prices in fast-moving markets
  3. Fixed Stop-Loss Risk: Single stop-loss percentage may not suit all market conditions
  4. Commission Costs: Frequent trading may result in high transaction costs

Strategy Optimization Directions

  1. Implement Trend Filters: Add longer-period moving averages or other trend indicators to filter false signals
  2. Dynamic Stop-Loss Mechanism: Adjust stop-loss percentages based on market volatility for better adaptability
  3. Volume Confirmation: Incorporate volume indicators to verify breakout validity
  4. Entry Timing Optimization: Wait for pullbacks after MA crossovers before entering positions

Summary

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")


Related

More