
この戦略は,動的移動平均線戦略と呼ばれる.主な考えは,移動平均線の方向と価格の関係を利用してトレンドを判断し,トレンドの方向に入場し,トレンドがない時に平仓する.
この戦略は,長周期の源価格を使用して移動平均線を計算し,源価格はOHLC4,HLC3,閉店価格などを選択できます. 計算された移動平均線は,smaとして定義されます. そして,移動平均線値の比率に基づいて長線と短線を描画し,長線と短線の位置関係によって,現在上昇傾向にあるか下降傾向にあるかを判断します.
具体的には,ショートラインの計算式は:shortline = sma * ((100 + shortlevel) / 100), shortlevelは,ユーザが設定できる正数で,ショートライン距離の移動平均線の比率を表している。長線は,計算式は:longline = sma * ((100 + longlevel) / 100),longlevelはユーザが設定できる負数で,長線距離の移動平均線の比率を表している。
このように,ショートライン値は常に移動平均線より大きく,ロングライン値は常に移動平均線より小さい. 価格がショートラインを上方に突破すると,上昇傾向に入ります. このとき,needlongが多くを許す場合は,ロングライン価格レベルで多くを注文します.
オーバーまたは空調のいずれにせよ,価格が移動平均線に戻ると,トレンドの終わりを表し,この時点で以前のすべてのポジションは平らになります.
このように,長短線と移動均線の動的関係によってトレンド方向を判断し,それに応じて入場と出場を行う.
この戦略の最大の利点は,長短線動的に買賣点を設定することで,主要トレンドの方向を比較的柔軟に把握できるという点にある.この戦略は,単に固定レベルで買賣点を触発する戦略に比べて,より高度で賢明である.
第二に,移動均等線自体は,一定の波作用があり,一定程度に高周波振動に閉じ込められることを回避する.移動均等線レベルに基づいてトレンドが終了するかどうかを判断するタイミングでの出場も非常に重要です.
この戦略の最大のリスクは,移動平均線が異なる期間に異なる強さを持つことである.通常,移動平均線はトレンドの方向を表すのに十分であるが,いくつかの極端な状況では,移動平均線は短期間に穿越され,誤入場を引き起こしたり,頂部から背離したりする可能性がある.この場合,トレンド判断の正確性を確保するために,より長い周期の移動平均線を使用する必要がある.
リスクのもうひとつの側面は,移動平均線自体は緩慢性があることである.いくつかの短期間で激しい価格の変動,移動平均線が困難であり,時を追跡する場合は,入場点または出場点を逃す可能性がある.移動平均線の反応速度を速めるために周期を減らす必要がある.
この戦略は,以下の点で改善できる:
この戦略は,ダイナミックに買い買いポイントを設定する方法でトレンド判断を行い,対応する多空取引を行う.移動平均線のダイナミックに取引シグナルを設定するこの方法では,静的トリガーポイントと比較して,価格トレンドをより柔軟に,そして賢く捉えることができる.同時に,移動平均線そのもののタイムリー性の欠如の問題も解決する.システムの反測とパラメータの最適化により,この戦略は良い収益を得ることができると信じています.
/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//Noro
//2018
//@version=3
strategy(title = "Noro's ShiftMA Strategy v1.1", shorttitle = "ShiftMA str 1.1", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 100)
//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(false, defval = false, title = "Short")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot, %")
per = input(3, title = "Length")
src = input(ohlc4, title = "Source")
shortlevel = input(10.0, title = "Short line (red)")
longlevel = input(-5.0, title = "Long line (lime)")
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")
//SMAs
sma = sma(src, per)
//sma = lowest(low, per)
shortline = sma * ((100 + shortlevel) / 100)
longline = sma * ((100 + longlevel) / 100)
plot(shortline, linewidth = 2, color = red, title = "Short line")
plot(sma, linewidth = 2, color = blue, title = "SMA line")
plot(longline, linewidth = 2, color = lime, title = "Long line")
//plot(round(buy * 100000000), linewidth = 2, color = lime)
//plot(round(sell * 100000000), linewidth = 2, color = red)
//Trading
size = strategy.position_size
lot = 0.0
lot := size == 0 ? strategy.equity / close * capital / 100 : lot[1]
if (not na(close[per])) and size == 0 and needlong
strategy.entry("L", strategy.long, lot, limit = longline, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if (not na(close[per])) and size == 0 and needshort
strategy.entry("S", strategy.short, lot, limit = shortline, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if (not na(close[per])) and size > 0
strategy.entry("Close", strategy.short, 0, limit = sma, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if (not na(close[per])) and size < 0
strategy.entry("Close", strategy.long, 0, limit = sma, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if time > timestamp(toyear, tomonth, today, 23, 59)
strategy.close_all()