レインボー移動平均取引戦略


作成日: 2023-09-28 11:01:59 最終変更日: 2023-09-28 11:01:59
コピー: 0 クリック数: 757
1
フォロー
1617
フォロワー

概要

虹の移動平均線取引戦略は虹の移動平均線指標に基づいて設計されている.この戦略は,7つの移動平均線を含む虹の移動平均線システムを構築して,トレンドの方向性を判断し,RSI指標と組み合わせて偽の信号をフィルタリングし,低リスクの取引入場を実現する.

戦略原則

この戦略は,主に以下のステップで取引シグナルを生成します.

  1. 虹の移動平均システムを構築する.このシステムは7つの移動平均を含み,そのうちの最初の移動平均は周期12で,ソースデータは終了価格の平均である.残りの6つの移動平均の周期は3周期ずつ減り,ソースデータは前の移動平均の値である.

  2. トレンドの方向を判断する.最初の移動平均線が虹の移動平均線の最も上にある場合,上昇傾向として定義される.最も下にある場合,下降傾向として定義される.中央にある場合,収束として定義される.

  3. 取引シグナルを生成する.虹の移動平均システムのトレンドが上昇から下落に変化したとき,売り出しシグナルを生成する.トレンドが下落から上昇に変化したとき,買い出しシグナルを生成する.トレンドが整合から上昇または下落に変化したとき,現在のポジションを平らにする.

  4. RSIフィルター。 RSI指標が正常な状態を示している場合にのみ取引信号を受けます。最初のRSI指標は,偽の突破を避けるために,過買過売の領域の間にあることを要求します.第二のRSIは,中間の領域に存在してはいけないことを要求し,突破の動力が十分であることを保証します。

戦略的優位性

この戦略の利点は以下の通りです.

  1. 虹の移動平均システムは,トレンドの方向を正確に判断できます.複数の移動平均の組み合わせは,トレンドの逆転を識別するために,市場のノイズを効果的にフィルターすることができます.

  2. RSI指標の二重フィルタリング機構は,偽の突破信号を効果的にフィルタリングし,被套を避ける.最初のRSIは正常領域にあり,第二のRSIは突破力が十分に大きいことを保証する.

  3. トレンドと逆転指標を組み合わせて,トレンドが逆転した時にタイムリーに入場し,また,落を追いかけるのを避けることができます.

  4. 清算段階での積極的な平仓は,regionselectionが市場を清算するリスクを回避する.

  5. この策略のパラメータ最適化スペースは広く,移動平均周期,長さの比率,RSIパラメータなどを調整して,異なる品種と周期に対して最適化することができ,それによってより良い効果を得ることができる.

戦略リスク

この戦略には以下のリスクがあります.

  1. トレンド反転が目立たない場合,誤った反転シグナルが生み出され,取引損失を招く可能性があります.反転シグナルをより明確にするため,移動平均周期を適切に調整できます.

  2. 標識の出現は,長期の区域収束時に,平和ポジションを頻繁に開き,取引コストと滑点損失を増加させる.RSIパラメータを最適化することによって,収束段階のフィルタリング強度を増加させることができます.

  3. 逆転が遅くなると,逆転信号が発せられた後,損失が拡大する時間と空間。移動平均周期差を大きくして,信号が発せられる時間がより早い。

  4. パラメータが設定されていない場合,部分的に正しい信号をフィルタリングしたり,信号が遅滞する可能性があります.異なる品種の特徴に応じてパラメータを調整する必要があります.

最適化の方向

この戦略は以下の点で最適化できます.

  1. 移動平均のパラメータ最適化.移動平均の周期長さ,周期差比率,移動平均の方法 (SMAまたはEMA) などのパラメータを最適化して,より正確な傾向判断を得ることができる.

  2. RSIパラメータの最適化. RSIの周期長さ,オーバーバイ地域,オーバーセール地域,中立地域などのパラメータを最適化することで,フィルタリングをより精密に効率的にすることができる.

  3. タイムサイクルの最適化 異なるタイムサイクルをテストして,その戦略に最も適したタイムサイクルを選択して,最高の効果を得る.

  4. 品種最適化: 品種の特性を考慮して,パラメータまたはルールを調整して,その品種に最適の効果を出すことができる.

  5. 追加ストップ・ストップ・メカニズム. 評価結果に基づいて,合理的なストップ・ストップレベルを設定し,単一取引のリスクと利益の大きさを制御することができる.

要約する

虹の移動平均線取引戦略は,トレンド判断と信号フィルタリングを組み合わせた方法で,トレンド転換点での信号捕捉の効果を実現している.この戦略は,判断の正確さ,リスクの制御の特徴があり,パラメータの最適化とルール完善により,非常に実用的量化取引戦略になり得る.全体的に,この戦略は,研究と応用の深さに値する.

ストラテジーソースコード
/*backtest
start: 2023-08-28 00:00:00
end: 2023-09-27 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//╔════════════════════════════════════════════════════════════════════════════╗
//║Rainbow Backtesting base on "Rainbow Moving Average" Strategy as below:     ║
//║1.Rainbow Moving Average setup                                              ║
//║- Source: source of 1st MA                                                  ║
//║- Type: SMA/EMA                                                             ║
//║- Period: period of 1st MA                                                  ║
//║- Displacement: period of 2nd MA to 7th MA with source is previous MA       ║
//║2.Trend Define                                                              ║
//║- Up Trend: Main MA moving at the top of Rainbow                            ║
//║- Down Trend: Main MA moving at the bottom of Rainbow                       ║
//║- Sideway: Main MA moving between the top and the bottom of Rainbow         ║
//║3.Signal                                                                    ║
//║- Buy Signal: When Rainbow change to Up Trend.                              ║
//║- Sell Signal: When Rainbow change to Down Trend.                           ║
//║- Exit: When Rainbow change to Sideway.                                     ║
//║4.RSI Filter                                                                ║
//║- "Enable": Only signals have 1st RSI moving between Overbought and Oversold║
//║and 2nd RSI moving outside Middle Channel are accepted.                     ║
//║- The filter may help trader avoid bull trap, bear trap and choppy market.  ║
//╚════════════════════════════════════════════════════════════════════════════╝

//@version=4
strategy("Rainbow Strategy Backtesting",overlay=false)
//++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++ Rainbow Moving Average +++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++
rainbow_tt="=== Rainbow Moving Average ==="
ma1_source=input(hlc3,title="Source",type=input.source, inline="set1", group=rainbow_tt)
rb_type=input("SMA",title="Type",options=["SMA","EMA"], inline="set1", group=rainbow_tt)
ma1_len=input(12,title="Period", inline="set2", group=rainbow_tt)
dis_len=input(3,title="Displacement", inline="set2", group=rainbow_tt,minval=2)
trend_tt="=== Trend Color ==="
up_col=input(color.new(color.blue,0),title="Up",inline="Color",group=trend_tt)
dn_col=input(color.new(color.red,0),title="Down",inline="Color",group=trend_tt)
sw_col=input(color.new(color.yellow,0),title="No",inline="Color",group=trend_tt)
//1st
ma1=rb_type=="SMA"?sma(ma1_source,ma1_len):ema(ma1_source,ma1_len)
//2nd
ma2=rb_type=="SMA"?sma(ma1,dis_len):ema(ma1,dis_len)
//3rd
ma3=rb_type=="SMA"?sma(ma2,dis_len):ema(ma2,dis_len)
//4
ma4=rb_type=="SMA"?sma(ma3,dis_len):ema(ma3,dis_len)
//5
ma5=rb_type=="SMA"?sma(ma4,dis_len):ema(ma4,dis_len)
//6
ma6=rb_type=="SMA"?sma(ma5,dis_len):ema(ma5,dis_len)
//7
ma7=rb_type=="SMA"?sma(ma6,dis_len):ema(ma6,dis_len)
//MinMax
rb_max=max(ma1,ma2,ma3,ma4,ma5,ma6,ma7)
rb_min=min(ma1,ma2,ma3,ma4,ma5,ma6,ma7)
dir_col=
       ma1==rb_max?up_col:
       ma1==rb_min?dn_col:
       sw_col
dir_style=shape.circle
plotshape(dir_col[1]==dir_col?0:na,title="Trend",style=dir_style,color=dir_col,location=location.absolute)
//++++++++++++++++++++++++++++++++++++++
//+++++++++++++ RSI Filter +++++++++++++
//++++++++++++++++++++++++++++++++++++++
rsi_tt="=== RSI Filter ==="
rsi_filter=input("Enable",title="Filter",options=["Enable","Disable"],inline="set",group=rsi_tt)
over_tt="Over Filter"
rsi_len_1=input(12,title="Period",inline="set",group=over_tt)
rsi_ovb=input(65,title="Overbought",inline="set",group=over_tt)
rsi_ovs=input(35,title="Oversold",inline="set",group=over_tt)
rsi_1=rsi(close,rsi_len_1)
mid_tt="Middle Filter"
rsi_len_2=input(9,title="Period",inline="set",group=mid_tt)
rsi_mid_top=input(56,title="Upper",inline="set",group=mid_tt)
rsi_mid_bot=input(44,title="Lower",inline="set",group=mid_tt)
rsi_2=rsi(close,rsi_len_2)
//Status
var rsi_status="None"
if (rsi_1>rsi_ovs and rsi_1<rsi_ovb) and (rsi_2[1]<rsi_mid_bot or rsi_2[1]>rsi_mid_top)
    rsi_status:="Normal"
else
    rsi_status:="None"
//Signal
BuySignal= 
       rsi_filter=="Disable"?
       dir_col[1]!=up_col
       and
       dir_col[0]==up_col
       :
       dir_col[1]!=up_col
       and
       dir_col[0]==up_col
       and
       rsi_status=="Normal"
       
SellSignal= 
       rsi_filter=="Disable"?
       dir_col[1]!=dn_col
       and
       dir_col[0]==dn_col
       :
       dir_col[1]!=dn_col
       and
       dir_col[0]==dn_col
       and
       rsi_status=="Normal"
       
exit=
       (dir_col[1]!=sw_col
       and
       dir_col[0]==sw_col)
buycol =
       BuySignal?
       up_col: na

sellcol =
       SellSignal?
       dn_col: na

exitcol =
       exit?
       sw_col: na

buy_style=shape.arrowup
sell_style=shape.arrowdown
exit_style=shape.square
plotshape(BuySignal?0:na,title="Buy",text="Buy",style=buy_style,color=buycol,location=location.absolute)
plotshape(SellSignal?0:na,title="Sell",text="Sell",style=sell_style,color=sellcol,location=location.absolute)
plotshape(exit?0:na,title="Exit",text="Exit",style=exit_style,color=exitcol,location=location.absolute)

filter=
       rsi_filter=="Enable"?
       dir_col[1]!=dir_col 
       and BuySignal==false 
       and SellSignal==false 
       and exit==false:
       na
filter_style=shape.xcross
filtercol=
       filter?
       dir_col:na
plotshape(filter?0:na,title="Filter",text="Filter",style=filter_style,color=filtercol,location=location.absolute)

//+++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++ Backtesting ++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++
strategy.entry("Long", strategy.long, when=BuySignal)
strategy.close("Long", when=exit or filter)
strategy.entry("Short", strategy.short, when=SellSignal)
strategy.close("Short", when=exit or filter)
//EOF