
この戦略はATR指数に基づくトレンドブレイク戦略である.その主な考えは,価格がATRの一定倍数を超えるとトレンドブレイク操作を行うことである.戦略は,トレンドの確認と,日付範囲を利用して取引を制限する機能を同時に含んでいる.
策略はATR指数を使用して価格変動幅を判断する.ATRは,特定の時間周期内の平均価格変動幅を測定する平均実際の波幅を表す.策略には,ATR周期を計算するlengthパラメータが設定され,numATRsパラメータは,突破したATR倍数を表す.
価格上昇が上位numATRs倍ATRを突破したとき,多操作を行います.価格下落が下位numATRs倍ATRを突破したとき,空白操作を行います.
さらに,戦略は,長所要 (needlong) と空所要 (needshort) のBOOL変数を追加し,多所要または空所要のみを制御できます.戦略は,指定された日付間の間の取引のみを行う日程範囲を設定し,時間範囲の制限を実現します.
戦略は,size変数を使用してポジションを判断し,ポジション状況に応じて下手数を計算する.手数は,アカウントの権利益のパーセントに従って計算する.
この戦略の全体的な考え方は明確で分かりやすい.ATR指標を使用して市場の変動に自動的に適応することは,一般的なトレンド追跡戦略である.パラメータ最適化および他の戦略を組み合わせることで,戦略のパフォーマンスと安定性をさらに改善することができます.しかし,単一損失を過大に防ぐことに注意し,市場状況が急激に変化するときに損失停止不足の問題に注意する必要があります.
/*backtest
start: 2023-09-30 00:00:00
end: 2023-10-30 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//Noro
//2018
//@version=3
strategy(title = "Noro's Volty Strategy v1.0", shorttitle = "Volty 1.0", 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, %")
length = input(5)
numATRs = input(0.75)
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")
//Indicator
atrs = sma(tr, length) * numATRs
//Trading
size = strategy.position_size
lot = 0.0
lot := size == 0 ? strategy.equity / close * capital / 100 : lot[1]
if (not na(close[length])) and needlong
strategy.entry("L", strategy.long, lot, stop = close + atrs, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if (not na(close[length])) and needlong == false
strategy.entry("L", strategy.long, 0, stop = close + atrs, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if (not na(close[length])) and needshort
strategy.entry("S", strategy.short, lot, stop = close - atrs, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if (not na(close[length])) and needshort == false
strategy.entry("S", strategy.short, 0, stop = close - atrs, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))