交差期突破システム

作者: リン・ハーンチャオチャン,日付: 2023-11-22 15:22:49
タグ:

img

概要

これは,両方向の突破操作のために移動平均値とMACD指標を使用する定量的な取引戦略である.これは,より長い時間枠でトレンド方向を判断し,より短い時間枠で機会を探す,クロス期間のオペレーションの特徴を持っています.

戦略原則

この戦略は,トレンド方向を決定するために,異なる長さの3つのSMMA移動平均と1つのEMA移動平均を使用する.同時に,短期的なトレンドとエントリー機会を判断するためにMACD指標を組み合わせる.具体的には,購入トリガー条件は:価格がすべての移動平均を上向きに突破し,より短い平均はより長い平均を上回る.販売トリガー条件は反対である一方で,価格はすべての移動平均を下向きに突破し,より短い平均はより長い平均を下回る.

この戦略は,中期および長期的トレンド方向を判断するために移動平均を活用し,短期的な逆転を判断することによってより良いエントリー機会を捉えるMACDを使用していることが見られます.このマルチタイムフレームの共同操作は戦略の重要な特徴です.

利点分析

このクロスペリオド・オペレーションの利点は,高い確率のトレンド方向に進むために適切な短期的な逆転点を選択でき,より良いリスク/リターン比を得ることができるということです.特に,主に以下の3つの利点はあります.

  1. 3つのSMMA平均値と1つのEMAラインの多レベルフィルタリングにより,中長期のトレンド方向を効果的に決定し,トレンドに反する取引を避けることができます.

  2. MACD指標は,入場の短期的な逆転点を判断することで,より良い入場価格レベルを得ることができます.

  3. フィルタリング条件として厳格な移動平均順序関係により,誤った操作の確率を減らすことができます.

リスク分析

この戦略の主なリスクは,

  1. 移動平均値自体は遅延特性が高く,短期的なトレンド逆転の機会を逃す可能性があります.

  2. MACD指標は誤った信号を生む傾向があり,価格レベルと組み合わせてフィルタリングする必要があります.

  3. 複数のタイムフレームによる判断は 戦略の複雑さを高め 失敗しやすいのです

リスク1とリスク2に対処するために,移動平均とシグナルサイクルを適切に短縮することで,短期的なトレンド逆転に迅速に対応するために最適化することができます.リスク3については,戦略パラメータをその多様性の特徴に厳格に適応するために,さまざまな品種とサイクルを最適化しテストする必要があります.

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

この戦略を最適化できる主な側面は以下の通りです.

  1. 移動平均値とMACDのパラメータを最適化して,異なるサイクルや多様性の特徴に最適化します.移動平均値の長さを短縮したり,信号パラメータを増加させたりなど.

  2. 合理的な移動停止を設定するために,ATRやその他の指標を使用してストップ損失戦略を増やす.これは戦略のリスク管理を大幅に改善することができます.

  3. MACD信号を代替するより良い指標やフィルタリング方法を探します.例えば,変動指標を導入し,それに応じてフィルタリング信号を導入します.

  4. 利回り比の異なる関係をテストし,よりよいリスク/報酬比を持つパラメータの組み合わせを得ます.

概要

一般的に,これはクロスタイムフレーム思考のユニークな突破型システムである.複数のタイムフレームにわたる共同判断操作戦略を達成するために,移動平均値とMACDの両方の利点を利用する.パラメータとフィルタリング基準を最適化し調整することにより,この戦略は非常に実践的な定量的な取引ソリューションになることができます.


/*backtest
start: 2023-10-22 00:00:00
end: 2023-11-21 00:00:00
period: 1h
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/
// © SoftKill21

//@version=4
strategy("Koala Script",initial_capital=1000, 
     commission_type=strategy.commission.cash_per_contract, 
     commission_value=0.000065,
     slippage=3)
fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2000, title = "From Year", minval = 1970)
 
// To Date Inputs
toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 8, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2031, title = "To Year", minval = 1970)
 


startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)




len = input(3, minval=1, title="Length")
src = input(hl2, title="Source")
smma = 0.0
sma1 = sma(src, len)
smma := na(smma[1]) ? sma1 : (smma[1] * (len - 1) + src) / len

len2 = input(6, minval=1, title="Length")
src2 = input(hl2, title="Source")
smma2 = 0.0
sma2 = sma(src2, len2)
smma2 := na(smma2[1]) ? sma2 : (smma2[1] * (len2 - 1) + src2) / len2

len3 = input(9, minval=1, title="Length")
src3 = input(hl2, title="Source")
smma3 = 0.0
sma3 = sma(src3, len3)
smma3 := na(smma3[1]) ? sma3 : (smma3[1] * (len3 - 1) + src3) / len3

len4 = input(50, minval=1, title="Length")
src4 = input(close, title="Source")
smma4 = 0.0
sma4 = sma(src4, len4)
smma4 := na(smma4[1]) ? sma4  : (smma4[1] * (len4 - 1) + src4) / len4

len5 = input(200, minval=1, title="Length")
src5 = input(close, title="Source")
out5 = ema(src5, len5)

timeinrange(res, sess) => time(res, sess) != 0
london=timeinrange(timeframe.period, "0300-1045")
londonEntry=timeinrange(timeframe.period, "0300-0845")

time_cond = time >= startDate and time <= finishDate and londonEntry

fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
srcc = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Simple MA(Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA(Signal Line)", type=input.bool, defval=false)


// Calculating
fast_ma = sma_source ? sma(srcc, fast_length) : ema(srcc, fast_length)
slow_ma = sma_source ? sma(srcc, slow_length) : ema(srcc, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal


longCond = close > out5 and close > smma4 and close > smma3 and close > smma2 and close > smma and londonEntry and smma > smma2 and smma2>smma3 and smma3>smma4 and smma4>out5 
shortCond = close < out5 and close < smma4 and close < smma3 and close < smma2 and close < smma and londonEntry and smma < smma2 and smma2<smma3 and smma3<smma4 and smma4<out5 
//longCond2 = crossover(close,out5) and crossover(close,smma4) and crossover(close,smma3) and crossover(close,smma2) and crossover(close,smma) and time_cond
//shortCond2 = crossunder(close,out5) and crossunder(close,smma4) and crossunder(close,smma3) and crossunder(close,smma2) and crossunder(close,smma) and time_cond

length=input(14, title="ATR Length")
mult=input(1.0, title="Percentage Multiplier (for ex., 0.7 = 70%)", step=0.1, minval=0.1, maxval=5.0)

oa=input(false, title="Show actual ATR")

ii=syminfo.pointvalue==0
s=ii?na:oa?atr(length):(syminfo.pointvalue * mult * atr(length))

tp=input(300,title="tp")
sl=input(300,title="sl")


//tp = s*10000
//sl= s*10000



//if(tp>300)
//    tp:=300
//if(sl>300)
//    sl:=300
//if(sl<150)
//    sl:=150
//if(tp<150)
//    tp:=150
strategy.initial_capital = 50000
//MONEY MANAGEMENT--------------------------------------------------------------''
balance = strategy.netprofit + strategy.initial_capital //current balance
floating = strategy.openprofit          //floating profit/loss
risk = input(3,type=input.float,title="Risk %")/100           //risk % per trade


    //Calculate the size of the next trade
temp01 = balance * risk     //Risk in USD
temp02 = temp01/sl        //Risk in lots
temp03 = temp02*100000      //Convert to contracts
size = temp03 - temp03%1000 //Normalize to 1000s (Trade size)
if(size < 10000)
    size := 10000           //Set min. lot size



strategy.entry("long",1,when=longCond )
strategy.exit("closelong","long", profit=tp,loss=sl)
//strategy.close("long",when= crossunder(close[4],smma4) and close[4] > close[3] and close[3]>close[2] and close[2] > close[1] and close[1] > close)
strategy.entry("short",0,when=shortCond )
strategy.exit("closeshort","short", profit=tp,loss=sl)
//strategy.close("short",when= crossover(close[4],smma4) and close[4] < close[3] and close[3]< close[2] and close[2] < close[1] and close[1] < close)

strategy.close_all(when = not london)

maxEntry=input(2,title="max entries")
// strategy.risk.max_intraday_filled_orders(maxEntry)

もっと