モメントと移動平均の組み合わせ ロング戦略

作者: リン・ハーンチャオチャン, 開催日:2024年2月29日 11:57:18
タグ:

img

概要

原則

この戦略の項目は,MACDとDMIの指標に基づいています.

  • MACD が正であるとき (MACD 線がシグナル線より上にある場合),それは市場の上昇勢力の強化を示します.
  • DI+がDMIでDI-より高い場合,市場は上昇傾向にあることを示します.

両方の条件が同時に満たされたら,長引く.

ポジション出口には2つの基準があります

  • 固定得益:得益の決まった割合まで閉じる価格が上昇する
  • 変動後止損失:動的に調整されたストップ損失ポジションを計算するために,ATRと最近の最高価格を使用します.これは市場の変動に応じてストップ損失を後押しすることができます.

利点

リスク

  • MACD と DMI の両方が誤った信号を出し,不必要な損失を引き起こす可能性があります.

オプティマイゼーションの方向性

  • 入力シグナルをフィルターする他の指標を追加することを検討してください.例えば,KDJ指標を使用して,過買いまたは過売りかどうかを判断します.
  • 利益とストップ損失の効果をより良くするために,異なるパラメータをテストすることができます.

概要

この戦略は,市場動向と条件を判断するために複数の指標を合成し,相対的に大きな有利な可能性のある状況に介入する.利益を得る条件は,利益をロックする柔軟性を考慮しながら一定の利益を確保するために最適に設計されている.パラメータ調整とさらなるリスク管理を通じて,この戦略は安定した定量的な取引システムになることができます.


/*backtest
start: 2024-01-29 00:00:00
end: 2024-02-28 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4
strategy(shorttitle='(MACD + DMI Scalping with Volatility Stop',title='MACD + DMI Scalping with Volatility Stop by (Coinrule)', overlay=true, initial_capital = 100, process_orders_on_close=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type=strategy.commission.percent, commission_value=0.1)

// Works better on 3h, 1h, 2h, 4h

//Backtest dates
fromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)
fromDay   = input(defval = 1,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)
fromYear  = input(defval = 2021, title = "From Year",       type = input.integer, minval = 1970)
thruMonth = input(defval = 1,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)
thruDay   = input(defval = 1,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)
thruYear  = input(defval = 2112, title = "Thru Year",       type = input.integer, minval = 1970)

showDate  = input(defval = true, title = "Show Date Range", type = input.bool)

start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window
finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish window
window()  => true

// DMI and MACD inputs and calculations

[pos_dm, neg_dm, avg_dm] = dmi(14, 14)
[macd, macd_signal, macd_histogram] = macd(close, 12, 26, 9)


Take_profit= ((input (3))/100)

longTakeProfit = strategy.position_avg_price * (1 + Take_profit)

length = input(20, "Length", minval = 2)
src = input(close, "Source")
factor = input(2.0, "vStop Multiplier", minval = 0.25, step = 0.25)
volStop(src, atrlen, atrfactor) =>
    var max     = src
    var min     = src
    var uptrend = true
    var stop    = 0.0
    atrM        = nz(atr(atrlen) * atrfactor, tr)
    max         := max(max, src)
    min         := min(min, src)
    stop        := nz(uptrend ? max(stop, max - atrM) : min(stop, min + atrM), src)
    uptrend     := src - stop >= 0.0
    if uptrend != nz(uptrend[1], true)
        max    := src
        min    := src
        stop   := uptrend ? max - atrM : min + atrM
    [stop, uptrend]

[vStop, uptrend] = volStop(src, length, factor)


closeLong = close > longTakeProfit or crossunder(close, vStop)


//Entry 
strategy.entry(id="long", long = true, when = crossover(macd, macd_signal) and pos_dm > neg_dm and window())


//Exit
strategy.close("long", when = closeLong and window())


もっと