
この戦略は,主に二重移動平均を買取と売却のシグナルとして使用し,トレンドが逆転する時に利益を得る.短期移動平均の上部に長期移動平均を穿越する際に多額で,短期移動平均の下部に長期移動平均を穿越する際に空白で,一般的な追跡ストップ戦略に属します.
この戦略は,まず,2つの移動平均を設定し,より短い20日平均線,より長い60日平均線を設定する. 短期平均線と長期平均線の交差点を判断して入場を決定する.
具体的には,短期平均線上に長期平均線を穿ったとき,現在上昇傾向にあることを示す,このとき多;短期平均線の下に長期平均線を穿ったとき,現在下降傾向にあることを示す,このとき空きをする.
余分な空白の後,ストップの方法は,トラッキングストップであり,最高価格と最低価格に基づいてトレーリングストップをすることで,最大利益をロックすることができます.
コードの主な論理は次のとおりです.
この戦略の利点は以下の通りです.
この戦略にはいくつかのリスクがあります.
リスクの最適化には以下の方法があります.
この戦略は,以下の点でさらに最適化できます.
他の指標のフィルタを追加し,複数の条件の入場メカニズムを形成し,偽突破を避ける.例えば,RSI指標の判断が加えられる.
移動平均線の周期パラメータを最適化して,最適なパラメータの組み合わせを見つける. ステップ・オブ・スルー方式で異なる周期パラメータをテストすることができる.
停止範囲を最適化します. 最適な停止範囲を測定データから計算できます. また,動的な停止範囲を設定できます.
再入場メカニズムを設定する. 止損退出後に,合理的な再入場論理を設定して,取引回数を減らすことができる.
トレンド判断指標と組み合わせて,トレンドが目立たない時に取引を一時停止し,無効取引を避ける.
ポジション管理メカニズムに参加し,市場状況に応じてポジションとストップの範囲を動的に調整する.
この二重移動平均線反転戦略は,全体的に比較的シンプルで実用的で,二重均等線によってトレンドの転換点を判断する一般的な方法であり,有効な方法である.しかし,一定のリスクがあり,パラメータ設定と止損範囲を最適化テストし,他のフィルタリング指標と組み合わせて使用する必要がある.戦略の最大限の効果を発揮するためには.細心の最適化と厳格なリスク管理が施されれば,この戦略は,安定した収益性の波段取引戦略になることができる.
/*backtest
start: 2023-09-23 00:00:00
end: 2023-10-15 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy("Noro's Bands Scalper Strategy v1.4", shorttitle = "Scalper str 1.4", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0)
//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
takepercent = input(0, defval = 0, minval = 0, maxval = 1000, title = "take, %")
needbe = input(true, defval = true, title = "Bands Entry")
needct = input(false, defval = false, title = "Counter-trend entry")
needdb = input(true, defval = true, title = "Double Body")
len = input(20, defval = 20, minval = 2, maxval = 200, title = "Period")
needbb = input(true, defval = true, title = "Show Bands")
needbg = input(true, defval = true, title = "Show Background")
src = close
//PriceChannel 1
lasthigh = highest(src, len)
lastlow = lowest(src, len)
center = (lasthigh + lastlow) / 2
//Distance
dist = abs(src - center)
distsma = sma(dist, len)
hd = center + distsma
ld = center - distsma
hd2 = center + distsma * 2
ld2 = center - distsma * 2
//Trend
trend = close < ld and high < center ? -1 : close > hd and low > center ? 1 : trend[1]
//Lines
colo = needbb == false ? na : black
plot(hd2, color = colo, linewidth = 1, transp = 0, title = "High band 2")
plot(hd, color = colo, linewidth = 1, transp = 0, title = "High band 1")
plot(center, color = colo, linewidth = 1, transp = 0, title = "center")
plot(ld, color = colo, linewidth = 1, transp = 0, title = "Low band 1")
plot(ld2, color = colo, linewidth = 1, transp = 0, title = "Low band 2")
//Background
col = needbg == false ? na : trend == 1 ? lime : red
bgcolor(col, transp = 80)
//Body
body = abs(close - open)
smabody = needdb == false ? ema(body, 30) : ema(body, 30) * 2
candle = high - low
//Signals
bar = close > open ? 1 : close < open ? -1 : 0
up7 = trend == 1 and ((bar == -1 and bar[1] == -1) or (body > smabody and bar == -1)) ? 1 : 0
dn7 = trend == 1 and ((bar == 1 and bar[1] == 1) or (close > hd and needbe == true)) and close > strategy.position_avg_price * (100 + takepercent) / 100 ? 1 : 0
up8 = trend == -1 and ((bar == -1 and bar[1] == -1) or (close < ld2 and needbe == true)) and close < strategy.position_avg_price * (100 - takepercent) / 100 ? 1 : 0
dn8 = trend == -1 and ((bar == 1 and bar[1] == 1) or (body > smabody and bar == 1)) ? 1 : 0
if up7 == 1 or up8 == 1
strategy.entry("Long", strategy.long, needlong == false ? 0 : trend == -1 and needct == false ? 0 : na)
if dn7 == 1 or dn8 == 1
strategy.entry("Short", strategy.short, needshort == false ? 0 : trend == 1 and needct == false ? 0 : na)