この戦略は,日内取引に適用される超トレンド指標に基づくショートライン戦略である. ユーザーは日内取引時間を定義することができ,戦略は,その時間帯のみで動作する. 戦略は,倍数の逆転開設ポジションによってシグナル反転を実現する. 当日の日内取引時間が終了し,ポジションがクリアされていない場合,クリアポジションを強制する.
超トレンド指標を計算する. ユーザ定義の倍数とATR周期に基づいて超トレンドラインを計算する.
スーパートレンドラインを描画する. サポートとレジスタンスラインとしてスーパートレンドラインを描画する.
長期・短期条件を判断する.超トレンドラインより高い閉盘価格を多条件とし,超トレンドラインより低い閉盘価格を空調条件とする.
取引時間の判断 ユーザが定義した1日間の取引時間に基づいて,現在の価格項が取引時間の内にあるかどうかを判断する.
取引信号を発信する.取引の時間内に,多空条件が満たされた場合にのみ,対応する買出信号を発信する.
逆開場。超トレンドの指標方向が変化したときに,倍数の逆開場を使用する。
平仓の退場。 超トレンドの信号が変わらず取引期が終了したときに,平仓を強制する。
超トレンド指数を使用してトレンドを識別し,偽信号を減らすことができます.
超トレンド指数と閉盤価格を組み合わせて取引するので,腰がされるのを避けます.
逆のポジションを開いて,損失を減らすことができます.
昼間取引は夜間取引のリスクを回避します.
強制的な平仓の仕組みは平仓の危険を回避する.
超トレンド指標のパラメータを正しく設定しない場合,戦略の効果が低下する可能性があります.
逆転ポジションは取引頻度と取引費用を増加させる.
日中の時間帯の終わりに強制的に平仓をすると,損失が生じることがあります.
リスク1は,パラメータ最適化によって最適なパラメータの組み合わせを見つけることができる.
リスク2では,損失をコントロールするために,ストップ・ロスを設定できます.
リスク3は,ストップを設定したり,トレンドフィルターを使用して,強平損失を避けることができます.
異なるトレンド指数 (MA,KDJなど) を試す
ストップダストロジックを追加しました.
価格の上昇を防ぐため,トレンドフィルターを追加します.
倍数とATR周期パラメータの最適化
取引の種類をテストする
この戦略は,超トレンド指標と日内取引時間管理を統合し,短線トレンドの突破を捕捉することを目的としています.反転開設および強制平仓のメカニズムは,リスクを効果的に制御します.その後,パラメータ最適化,ストップ損失およびトレンドフィルタリングにより戦略の効果をさらに改善できます.
/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 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/
// © Pritesh-StocksDeveloper
//@version=4
strategy("Supertrend - Intraday", overlay=true, calc_on_every_tick = true)
// ********** Strategy inputs - Start **********
// Used for intraday handling
// Session value should be from market start to the time you want to square-off
// your intraday strategy
// Important: The end time should be at least 2 minutes before the intraday
// square-off time set by your broker
var i_marketSession = input(title="Market session", type=input.session,
defval="0915-1455", confirm=true)
var float i_multiplier = input(title = "Multiplier", type = input.float,
defval = 4, confirm=true)
var int i_atrPeriod = input(title = "ATR Period", type = input.integer,
defval = 14, confirm=true)
// ********** Strategy inputs - End **********
// ********** Supporting functions - Start **********
// A function to check whether the bar or period is in intraday session
barInSession(sess) => time(timeframe.period, sess) != 0
// ********** Supporting functions - End **********
// ********** Strategy - Start **********
[superTrend, dir] = supertrend(i_multiplier, i_atrPeriod)
colResistance = dir == 1 and dir == dir[1] ? color.new(color.red, 0) : color.new(color.red, 100)
colSupport = dir == -1 and dir == dir[1] ? color.new(color.green, 0) : color.new(color.green, 100)
plot(superTrend, color = colResistance, linewidth=2)
plot(superTrend, color = colSupport, linewidth=2)
// Long/short condition
longCondition = close > superTrend
shortCondition = close < superTrend
// See if intraday session is active
bool intradaySession = barInSession(i_marketSession)
// Trade only if intraday session is active
// Long position
// When longCondition and intradaySession both are true
strategy.entry(id = "Long", long = strategy.long,
when = longCondition and intradaySession)
// Short position
// When shortCondition and intradaySession both are true
strategy.entry(id = "Short", long = strategy.short,
when = shortCondition and intradaySession)
// Square-off position (when session is over and position is open)
squareOff = (not intradaySession) and (strategy.position_size != 0)
strategy.close_all(when = squareOff, comment = "Square-off")
// ********** Strategy - End **********