ギャップ・トレーディング 移動平均戦略

作者: リン・ハーンチャオチャン開催日:2023年10月26日16時05分01秒
タグ:

img

この記事では,Noroによってコードされた移動平均ギャップ取引戦略の詳細な分析を提供します.この戦略は,閉値と単純な移動平均との間の偏差を計算することによってトレンド逆転を特定し,低値で購入し,高値で販売します.

戦略の論理

この戦略は,まず3日間の単純な移動平均値 (SMA) を計算する.その後,閉じる価格 (閉じる) とSMAマイナス1の比率を指標 (ind) として計算する.indが既定パラメータの限界を超えると,閉じる価格がSMAを大幅に超えたことを意味し,ロングポジションが考慮される.indが -limitを下回ると,閉じる価格がSMAを下回って,ショートポジションが考慮される.

この戦略は0軸,限界軸,限界軸を図に描く.判断を助けるためにインダキタは別々の領域で色が異なる.インダキタが限界または限界を超えると,長または短エントリーをシグナルします.

ロング/ショートシグナルで,戦略は最初に反対ポジションを閉じて,その後ロング/ショートポジションを開きます.

利点

  1. トレンドをフォローする戦略とは異なり,トレンドの逆転を捉えるためにギャップ・トレード原則を採用する.

  2. インディケーター位置とクロスオーバーの直感的な判断のためにインディケーター軸をプロットする.

  3. 方向を逆転する前に既存の位置を閉じ,不必要な反対位置を避ける.

  4. 取引時間帯を定義し,不必要なオバーナイトポジションを回避する.

  5. ロング・ショート・トレードを有効/無効にするための柔軟性

リスク

  1. 移動平均戦略は 複数の負ける取引を生む傾向があり 保持に耐心が必要です

  2. 移動平均値は,リアルタイムでの価格変動を把握する柔軟性がない.

  3. 前もって設定された限界パラメータは静的であり,異なる製品と市場環境に合わせて調整する必要があります.

  4. 動向の変動を特定できないため,変動指標と組み合わせる必要がある.

  5. ストップ・ロスト,利益を取ること,初期ギャップを捕まえるだけ.

改善の方向性

  1. 異なるパラメータ設定をテストします.例えばSMA期間,EMAのような適応移動平均値.

  2. 意味のない取引を避けるために 移動平均の方向と傾斜の検証を追加します

  3. 波動性が上昇すると取引を一時停止するために ボリンジャーバンドのような波動性指標と組み合わせることを検討してください

  4. ポジションのサイズを決める規則を導入する.例えば,定量,増量ピラミッド,マネーマネジメント.

  5. ストップ・ロスト/テイク・プロフィートラインを設定し,または固定パーセントストップ・ロストが起動したときに新しいオーダーを一時停止し,取引リスクごとに制御します.

概要

この記事では,Noroの移動平均ギャップ取引戦略を包括的に分析した.移動平均の特徴から価格ギャップを利用し,エントリータイミングのための指標軸とカラーを実装する.また,緊密な論理を最適化し,取引時間範囲を定義する.しかし,移動平均追跡の固有の弱点は残っており,パラメータ,ストップ損失規則,インディケーターを組み合わせることなどにさらなる最適化が必要である.


/*backtest
start: 2022-10-19 00:00:00
end: 2023-10-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Noro
//2018

//@version=3
strategy(title = "Noro's Shift Close Strategy v1.0", shorttitle = "Shift Close 1.0", default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 5)

//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot, %")
limit = input(10)
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From Day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To Day")

//Shift MA
sma = sma(ohlc4, 3)
ind = ((close / sma) - 1) * 100

//Oscilator
plot(3 * limit, color = na, transp = 0)
plot(limit, color = black, transp = 0)
plot(0, color = black, transp = 0)
plot(-1 * limit, color = black, transp = 0)
plot(-3 * limit, color = na, transp = 0)
plot(ind, linewidth = 3, transp = 0)
col = ind > limit ? red : ind < -1 * limit ? lime : na
bgcolor(col, transp = 0)

//Signals
size = strategy.position_size
up = ind < -1 * limit
dn = ind > limit
exit = ind > -1 * limit and ind < limit

//Trading
lot = 0.0 
lot := size == 0 ? strategy.equity / close * capital / 100 : lot[1]

if up
    if strategy.position_size < 0
        strategy.close_all()
        
    strategy.entry("Long", strategy.long, needlong == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))

if dn
    if strategy.position_size > 0
        strategy.close_all()
        
    strategy.entry("Short", strategy.short, needshort == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
    
if exit
    strategy.close_all()

もっと