レインボーオシレーターバックテスト戦略

作者: リン・ハーンチャオチャン開催日:2023年12月26日 15:08:17
タグ:

img

概要

レインボーオシレーターバックテスト戦略は,レインボーオシレーター指標に基づいた定量的な取引戦略である.この戦略は,ロングとショートポジションを決定するために価格と移動平均の間の偏差を計算することによって,市場のトレンド方向と強さを判断する.

戦略の論理

この戦略の核心指標はRainbow Oscillator (RO) で,次のように計算されます.

RO = 100 * ((Close - 10-day Moving Average) / (HHV(High, N) - LLV(Low, N))) 

10日間の移動平均は過去10期間の閉値の単純な移動平均である.この指標は,その移動平均値に対する価格の偏差を反映する.RO > 0の場合,価格は移動平均値以上であり,上昇信号である.RO < 0の場合,価格は移動平均値以下であり,下落信号である.

この戦略は,次のような方法で計算される補助指標 - バンドウィッド (RB) も計算しています.

RB = 100 * ((Highest value of moving averages - Lowest value of moving averages) / (HHV(High, N) - LLV(Low, N)))

RBは移動平均値間の幅を反映する.RBが大きいほど,価格変動が大きくなり,その逆も価格がより安定している.RB指標は市場の安定性を判断するために使用できる.

ROとRB指標の値に基づいて,この戦略は価格偏差と市場の安定度を判断し,ロングとショートポジションの取引信号を生成します.

利点

この戦略の利点は次のとおりです.

  1. 二重指標判断は単一指標判断の限界を回避する.
  2. 価格動向と市場の安定を同時に判断できる
  3. 計算し理解し 実行するのも簡単です
  4. 視覚化された指標は直感的で読みやすい"虹"効果を形成します.

リスク

この戦略にはいくつかのリスクもあります:

  1. RO と RB インジケーターのパラメータの設定が正しくない場合,間違った取引信号が発生する可能性があります.
  2. 二重移動平均戦略は,誤った信号と頻繁な取引を生成する傾向があります.
  3. 不適切なバックテスト期間と製品選択は 戦略の有効性に影響します
  4. 取引コストは考慮されていないため,実際の結果は不十分である可能性があります.

対策:

  1. ROとRB指標のパラメータを最適化する.
  2. 頻繁に取引しないようにフィルター条件を追加します
  3. 適切なバックテストサイクルと種類を選択する.
  4. トランザクションコストを計算し,考慮してください.

最適化

また,戦略は以下の方法で最適化できます.

  1. 劇的な変動を避けるために,ROインジケーターにスムーズな機能を追加します.
  2. ストップ・ロスの戦略を追加して 単一の損失を制御します
  3. 収益性を高めるため,ポートフォリオ取引の他の指標と組み合わせます.
  4. 予測や指標の有効性を評価するための機械学習モデルを追加します
  5. 適応性を向上させるため,異なる品種のためのパラメータを最適化します.

結論

レインボーオシレーターバックテスト戦略は,価格と移動平均の間の偏差を計算して市場動向と安定性を判断し,この情報を使用して長/短取引決定を下します.この戦略は直感的で,実装が簡単で,いくつかの実用的な価値があります.しかし,リスクを軽減し,実際の取引パフォーマンスを改善するためにパラメータと取引規則を最適化することで緩和する必要があるリスクもあります.


/*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 
// random or chaotic, but follow specific trends that can be forecasted, they 
// tried to develop different tools or procedures that could help them identify 
// those trends. And one of those financial indicators is the Rainbow Oscillator 
// Indicator. The Rainbow Oscillator Indicator is relatively new, originally 
// introduced in 1997, and it is used to forecast the changes of trend direction.
//
// As market prices go up and down, the oscillator appears as a direction of the 
// trend, but also as the safety of the market and the depth of that trend. As 
// the rainbow grows in width, the current trend gives signs of continuity, and 
// if the value of the oscillator goes beyond 80, the market becomes more and more 
// unstable, being prone to a sudden reversal. When prices move towards the rainbow 
// and the oscillator becomes more and more flat, the market tends to remain more 
// stable and the bandwidth decreases. Still, if the oscillator value goes below 20, 
// the market is again, prone to sudden reversals. The safest bandwidth value where 
// the market is stable is between 20 and 80, in the Rainbow Oscillator indicator value. 
// The depth a certain price has on a chart and into the rainbow can be used to judge 
// the strength of the move.
//
// You can change long to short in the Input Settings
// WARNING:
//  - For purpose educate only
//  - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title="Rainbow Oscillator Backtest")
Length = input(2, minval=1)
LengthHHLL = input(10, minval=2, title="HHV/LLV Lookback")
reverse = input(false, title="Trade reverse")
xMA1 = sma(close, Length)
xMA2 = sma(xMA1, Length)
xMA3 = sma(xMA2, Length)
xMA4 = sma(xMA3, Length)
xMA5 = sma(xMA4, Length)
xMA6 = sma(xMA5, Length)
xMA7 = sma(xMA6, Length)
xMA8 = sma(xMA7, Length)
xMA9 = sma(xMA8, Length)
xMA10 = sma(xMA9, Length)
xHH = highest(close, LengthHHLL)
xLL = lowest(close, LengthHHLL)
xHHMAs = max(xMA1,max(xMA2,max(xMA3,max(xMA4,max(xMA5,max(xMA6,max(xMA7,max(xMA8,max(xMA9,xMA10)))))))))
xLLMAs = min(xMA1,min(xMA2,min(xMA3,min(xMA4,min(xMA5,min(xMA6,min(xMA7,min(xMA8,min(xMA9,xMA10)))))))))
xRBO = 100 * ((close - ((xMA1+xMA2+xMA3+xMA4+xMA5+xMA6+xMA7+xMA8+xMA9+xMA10) / 10)) / (xHH - xLL))
xRB = 100 * ((xHHMAs - xLLMAs) / (xHH - xLL))
clr = iff(xRBO >= 0, green, red)
pos = iff(xRBO > 0, 1,
       iff(xRBO < 0, -1, nz(pos[1], 0))) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1, 1, pos))	   
if (possig == 1) 
    strategy.entry("Long", strategy.long)
if (possig == -1)
    strategy.entry("Short", strategy.short)	   	    
barcolor(possig == -1 ? red: possig == 1 ? green : blue ) 
plot(xRBO, color=clr, title="RO", style= histogram, linewidth=2)
p0 = plot(0, color = gray, title="0")
p1 = plot(xRB, color=green, title="RB")
p2 = plot(-xRB, color=red, title="RB")
fill(p1, p0, color=green)
fill(p2, p0, color=red)

もっと