戦略をフォローする二重移動平均傾向

作者: リン・ハーンチャオチャン,日付: 2023-09-18 21:57:00
タグ:

概要

この戦略は,トレンド方向を特定し,高速MAが遅いMAを横切るときに信号を生成するために,高速および遅い移動平均を使用し,二重MAシステムを作成します.

原則

この戦略は,より短い高速MMAとより長い遅いMMAを使用します.

スローMAは主要なトレンド方向を定義します.MAを超える価格は上昇傾向であり,下下の価格は下落傾向です.

アップトレンドでは,高速MAが遅いMAを横切ると長信号が生成される.ダウントレンドでは,高速MAが遅いMAを下回ると短信号が生成される.

シグナルが鳴った後,フォローストップはオプションで有効にできます.

利点

  1. 速くて遅いMAコンボが 効率的にトレンドを特定します

  2. 迅速なMAは敏感な取引信号を生成します

  3. 遅いMAは 音をフィルタリングして 誤った突破を防ぎます

  4. EMAやDEMAのような様々なMAタイプが使用できます

  5. トレイリングストップ損失を有効にすることができます.

リスクと緩和策

  1. MA遅延が信号を遅らせます より敏感なパラメータをテストできます

  2. ストップ・ロスは太りすぎて 早く退場する

  3. 価格操作の危険性があるので 取引量を確認できます

  4. 誤った信号に 傾向がある 追加確認が必要です

  5. パラメータ最適化が難しい.ステップバイズ最適化またはGAは最適なパラメータを見つけることができます.

増進 の 機会

  1. 最適な結果を得るため,異なるMAタイプとパラメータを試験する.

  2. 適性移動平均を調査して 感度を上げます

  3. シグナルフィルタリングのための他の指標や要素を追加します.

  4. 柔軟なストップのために ダイナミックストップを作ります

  5. 動的ポジションサイジングのような 資金管理を最適化します

概要

この戦略は,リスクを制限するストップで,トレンドを特定するためにダブルMAクロスオーバーを取引する.論理はシンプルで明確だが,パラメータ選択やその他の問題も存在する.最適化,フィルタリング,ストップによる改善により強度が向上する.これは合理的なベースラインのトレンドフォローシステムとして機能する.


/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy(title = "Noro's Trend MAs Strategy v1.7", shorttitle = "Trend MAs str 1.7", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0)

//Settings
needlong = input(true, "long")
needshort = input(true, "short")
needstops = input(false, "stops")
stoppercent = input(5, defval = 5, minval = 1, maxval = 50, title = "Stop, %")
type = input(7, defval = 7, minval = 1, maxval = 7, title = "Type of Slow MA")
src = input(close, defval = close, title = "Source of Slow MA")
usefastsma = input(true, "Use fast MA Filter")
fastlen = input(5, defval = 5, minval = 1, maxval = 50, title = "fast MA Period")
len = input(20, defval = 20, minval = 2, maxval = 200, title = "slow MA Period")
bars = input(2, defval = 2, minval = 0, maxval = 3, title = "Bars Q")
needbg = input(false, defval = false, title = "Need trend Background?")
needarr = input(false, defval = false, title = "Need entry arrows?")

fastsma = ema(src, fastlen)

//DEMA
dema = 2 * ema(src, len) - ema(ema(close, len), len)

//TEMA
xPrice = close
xEMA1 = ema(src, len)
xEMA2 = ema(xEMA1, len)
xEMA3 = ema(xEMA2, len)
tema = 3 * xEMA1 - 3 * xEMA2 + xEMA3

//KAMA
xvnoise = abs(src - src[1])
nfastend = 0.20
nslowend = 0.05
nsignal = abs(src - src[len])
nnoise = sum(xvnoise, len)
nefratio = iff(nnoise != 0, nsignal / nnoise, 0)
nsmooth = pow(nefratio * (nfastend - nslowend) + nslowend, 2) 
kama = nz(kama[1]) + nsmooth * (src - nz(kama[1]))

//PriceChannel
lasthigh = highest(src, len)
lastlow = lowest(src, len)
center = (lasthigh + lastlow) / 2

//Trend
ma = type == 1 ? sma(src, len) : type == 2 ? ema(src, len) : type == 3 ? vwma(src, len) : type == 4 ? dema : type == 5 ? tema : type == 6 ? kama : type == 7 ? center : 0
trend = low > ma and low[1] > ma[1] and low[2] > ma[2] ? 1 : high < ma and high[1] < ma[1] ? -1 : trend[1]

//Bars
bar = close > open ? 1 : close < open ? -1 : 0
redbars = bars == 0 ? 1 : bars == 1 and bar == -1 ? 1 : bars == 2 and bar == -1 and bar[1] == -1 ? 1 : bars == 3 and bar == -1 and bar[1] == -1 and bar[2] == -1 ? 1 : 0
greenbars = bars == 0 ? 1 : bars == 1 and bar == 1 ? 1 : bars == 2 and bar == 1 and bar[1] == 1 ? 1 : bars == 3 and bar == 1 and bar[1] == 1 and bar[2] == 1 ? 1 : 0

//Signals
min = min(open, close)
max = max(open, close)
up = trend == 1 and (low < fastsma or usefastsma == false) and redbars == 1 ? 1 : 0
dn = trend == -1 and (high > fastsma or usefastsma == false) and greenbars == 1 ? 1 : 0

//Lines
colorfastsma = usefastsma == true ? red : na
plot(fastsma, color = colorfastsma, title = "Fast MA")
plot(ma, color = blue, linewidth = 3, transp = 0, title = "Slow MA")

//Arrows
plotarrow(up == 1 and needarr == true ? 1 : 0, colorup = black, colordown = black, transp = 0)
plotarrow(dn == 1 and needarr == true ? -1 : 0, colorup = black, colordown = black, transp = 0)

//Background
col = needbg == false ? na : trend == 1 ? lime : red
bgcolor(col, transp = 90)

//Alerts
alertcondition(up == 1, title='buy', message='Uptrend')
alertcondition(dn == 1, title='sell', message='Downtrend')

//Trading
stoplong = up == 1 and needstops == true ? close - (close / 100 * stoppercent) : stoplong[1]
stopshort = dn == 1 and needstops == true ? close + (close / 100 * stoppercent) : stopshort[1]

longCondition = up == 1
if (longCondition)
    strategy.entry("Long", strategy.long, needlong == false ? 0 : na)
    strategy.exit("Stop Long", "Long", stop = stoplong)

shortCondition = dn == 1
if (shortCondition)
    strategy.entry("Short", strategy.short, needshort == false ? 0 : na)
    strategy.exit("Stop Short", "Short", stop = stopshort)

もっと