
この戦略は,移動平均と平均実際の変動率を用いて市場のトレンド方向を判断し,トレンドの方向に応じてトレンド追跡取引を行う.
この戦略は,レン周期の移動平均maと2倍レン周期平均の真波動率atrを使用して市場の傾向を判断する.具体的判断ルールは:
最低値が移動平均と平均実際の変動率より大きいとき ((low > ma + atr),上昇傾向として判断する。
最高値が移動平均より小さい時,平均実際の変動率を引いたとき (high < ma - atr),下降傾向として判断する.
他の場合も前述の判断は維持されます.
上昇傾向を判断する際には,余分なことが許される場合には,一定比例で余分なことを行う.
ダウントレンドを判断する際には,空白が許される時,一定比例で空白する.
平仓条件は,指定された取引終了日に到達すること.
この戦略の利点は以下の通りです.
この戦略には以下の主要なリスクがあります.
解決策は
この戦略は以下の点で最適化できます.
この戦略の全体的な考え方は明確で分かりやすい.移動平均を使ってトレンドの方向を判断し,平均実動率を使ってストップを設定し,トレンドを効果的に追跡することができる.しかし,一定のリスクがあり,パラメータの設定をさらに最適化し,他の判断指標を追加する必要がある.全体的に,この戦略はトレンドを追跡する取引のための実行可能な考え方を提供している.
/*backtest
start: 2024-01-04 00:00:00
end: 2024-01-11 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//2019
//Noro
//@version=4
strategy(title = "Noro's MA+ATR Strategy", shorttitle = "MA+ATR str", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)
//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Capital, %")
len = input(30, minval = 2, title = "MA Length")
src = input(ohlc4, title = "MA Source")
limitmode = input(false)
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")
//MA + BG
atr = sma(tr, len) * 2
ma = sma(src, len)
plot(ma, color = color.blue, linewidth = 4)
trend = 0
trend := low > ma + atr ? 1 : high < ma - atr ? -1 : trend[1]
col = trend == 1 ? color.lime : color.red
bgcolor(col, transp = 70)
//Trading
lot = 0.0
lot := strategy.position_size != strategy.position_size[1] ? strategy.equity / close * capital / 100 : lot[1]
if trend == 1 and limitmode == false
strategy.entry("Long", strategy.long, needlong == false ? 0 : lot)
if trend == -1 and limitmode == false
strategy.entry("Short", strategy.short, needshort == false ? 0 : lot)
if trend == 1 and limitmode
strategy.entry("Long", strategy.long, needlong == false ? 0 : lot)
if trend == -1 and limitmode
strategy.entry("Short", strategy.short, needshort == false ? 0 : lot)
// if time > timestamp(toyear, tomonth, today, 23, 59)
// strategy.close_all()