
この策略は,双ALMA移動平均の金叉死叉信号に基づいて,MACD指標の多空信号と組み合わせて,自動多空を行うことを実現する.この策略は,4時間以上の時間周期に適用され,テストデータはBNB/USDTであり,時間帯は2017年から現在までで,手数料は0.03%に設定されている.
戦略は,ALMA快線と慢線を使用して二重移動平均を構築する.快線長さは20で,慢線長さは40で,それぞれ0.9の偏移量を使用し,標準差は5である.快線上の慢線を横切るときに多信号が生成され,快線下の慢線を横切るときに空白信号が生成される.
同時に,戦略がMACD指標の直角図信号と結合する。MACD直角図が正であるときのみ,多信号が有効である;MACD直角図が負であるときのみ,空信号が有効である。
この戦略は同時に,ストップ・ストップ・条件を設定した.多ストップは2倍,ストップは0.2倍;空きストップは0.05倍,ストップは1倍.
この戦略は,双動平均のトレンド判断とMACD指標のエネルギー判断を組み合わせて,偽信号を効果的にフィルターし,入場の正確性を向上させる. ストップ・ストップ・損失の設定は合理的で,利益を最大限にロックし,大きな損失を避ける.
追溯データ adopted 2017年以来,多回の牛と熊の変換を含み,戦略は周期間条件で良好なパフォーマンスを続けている.これは,戦略が市場の線形および非線形特性に適応していることを証明している.
この戦略には以下のリスクがあります.
解決策は
この戦略は,以下の点で最適化できます.
この戦略は,移動平均のトレンド判断とMACDの補助判断を組み合わせて,合理的なストップ・ロスを設定し,さまざまな状況で安定した利益を得ることができます.継続的に最適化されたパラメータ設定,追加のフィルター条件の追加などの手段によって,戦略の安定性と収益性がさらに向上することができます.
/*backtest
start: 2023-11-04 00:00:00
end: 2023-12-04 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/
// © exlux99
//@version=4
strategy(title = "Full Crypto Swing Strategy ALMA Cross", overlay = true, pyramiding=1,initial_capital = 1, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.03)
//time condition
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 = 2010, title = "From Year", minval = 1970)
//monday and session
// To Date Inputs
toDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 12, 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)
time_cond = time >= startDate and time <= finishDate
UseHAcandles = input(false, title="Use Heikin Ashi Candles in Algo Calculations")
haClose = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, close) : close
haOpen = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, open) : open
haHigh = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, high) : high
haLow = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, low) : low
//alma fast and slow
src = haClose
windowsize = input(title="Length Size Fast", type=input.integer, defval=20)
windowsize2 = input(title="Length Size Slow", type=input.integer, defval=40)
offset = input(title="Offset", type=input.float, defval=0.9, step=0.05)
sigma = input(title="Sigma", type=input.float, defval=5)
outfast=alma(src, windowsize, offset, sigma)
outslow=alma(src, windowsize2, offset, sigma)
//macd
fast_length = input(title="Fast Length", type=input.integer, defval=6)
slow_length = input(title="Slow Length", type=input.integer, defval=25)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
// Calculating
fast_ma = ema(src, fast_length)
slow_ma = ema(src, slow_length)
macd = fast_ma - slow_ma
signal = ema(macd, signal_length)
hist = macd - signal
long=crossover(outfast,outslow) and hist > hist[1] and time_cond
short=crossunder(outfast,outslow) and hist < hist[1] and time_cond
takeProfit_long=input(2.0, step=0.005)
stopLoss_long=input(0.2, step=0.005)
takeProfit_short=input(0.05, step=0.005)
stopLoss_short=input(1.0, step=0.005)
strategy.entry("long",1,when=long)
strategy.entry("short",0,when=short)
strategy.exit("short_tp/sl", "long", profit=close * takeProfit_long / syminfo.mintick, loss=close * stopLoss_long / syminfo.mintick, comment='LONG EXIT', alert_message = 'closeshort')
strategy.exit("short_tp/sl", "short", profit=close * takeProfit_short / syminfo.mintick, loss=close * stopLoss_short / syminfo.mintick, comment='SHORT EXIT', alert_message = 'closeshort')