Rainbow Oscillator Backtesting Strategy
Overview
The Rainbow Oscillator backtesting strategy is a quantitative trading strategy based on the Rainbow Oscillator indicator. This strategy judges the trend direction and strength of the market by calculating the deviation between the price and moving average to determine long and short positions.
Strategy Logic
The core indicator of this strategy is the Rainbow Oscillator (RO), which is calculated as follows:
RO = 100 * ((Close - 10-day Moving Average) / (HHV(High, N) - LLV(Low, N)))
Where the 10-day moving average is the simple moving average of closing prices over the past 10 periods. This indicator reflects the deviation of the price relative to its own moving average. When RO > 0, it means the price is above the moving average, a bullish signal; when RO < 0, it means the price is below the moving average, a bearish signal.
The strategy also calculates an auxiliary indicator - Bandwidth (RB), which is calculated as:
RB = 100 * ((Highest value of moving averages - Lowest value of moving averages) / (HHV(High, N) - LLV(Low, N)))
RB reflects the width between moving averages. The larger the RB, the greater the price fluctuation, and vice versa the price is more stable. The RB indicator can be used to judge the stability of the market.
According to the values of the RO and RB indicators, the strategy judges the degree of price deviation and market stability, and generates trading signals for long and short positions.
Advantages
The advantages of this strategy are:
- Dual indicator judgment avoids the limitations of single indicator judgment.
- Can judge price trends and market stability simultaneously.
- Simple to calculate, easy to understand and implement.
- Visualized indicators form a "rainbow" effect that is intuitive and easy to read.
Risks
There are also some risks with this strategy:
- Improper parameter settings of RO and RB indicators may cause wrong trading signals.
- Dual moving average strategies tend to generate false signals and frequent trading.
- Inappropriate backtesting period and product selection will affect strategy effectiveness.
- Trading costs are not considered, actual results may be poor.
Countermeasures:
- Optimize parameters for RO and RB indicators.
- Add filter conditions to avoid frequent trading.
- Select appropriate backtesting cycle and variety.
- Calculate and consider transaction costs.
Optimization
The strategy can also be optimized in the following ways:
- Add Smooth feature to RO indicator to avoid dramatic fluctuations.
- Add stop loss strategy to control single loss.
- Combine with other indicators for portfolio trading to increase profitability.
- Add machine learning model for prediction and evaluate indicator effectiveness.
- Optimize parameters for different varieties to improve adaptability.
Conclusion
The Rainbow Oscillator backtesting strategy judges market trends and stability by calculating the deviation between prices and moving averages, and uses this information to make long/short trading decisions. This strategy is intuitive, easy to implement, and has some practical value. But there are also some risks that need to be mitigated by optimizing parameters and trading rules to reduce risk and improve real trading performance.
/*backtest
start: 2023-11-25 00:00:00
end: 2023-12-25 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 18/03/2018
// Ever since the people concluded that stock market price movements are not - 1

