取引戦略の相対的な量傾向

作者: リン・ハーンチャオチャン,日付: 2023年10月17日 16:19:59
タグ:

img

概要

この戦略は,相対ボリューム指標と価格アクショントレンド判断を組み合わせ,トレンドフォローとブレイクアウトを統合した自動化取引システムを構築する.ボリューム増加と変動が低いときに購入し,ストップ損失と価格アクションに基づいて販売する.

機能 する 方法

  1. 価格波動性が低いかどうかを判断するためにボリンガー帯を使用します.特にATRとBOLL帯幅を比較します.

  2. 過去N日間の平均容量を計算し,現在の容量と比較して,容量が増加したかどうかを確認します.

  3. 価格が低くなって 売上高が上がり 変動が低いときに買います

  4. ストップ・ロスを設定して 最低価格を追います

  5. 価格がストップ・ロスの下に落ちると売る.

  6. 価格が上昇傾向のパターンになると売る.

利点

  1. ボリュームと波動性を組み合わせることで 誤ったブレイクを効果的にフィルタリングできます

  2. ストップ・ロスは最大利益になる

  3. 傾向が早急に逆転する

  4. 直感的で 簡単です

  5. ストップ・ロストとテイク・プロフィートの 明確なルールは 不確実性を軽減します

リスク

  1. ボリュームインジケーターが遅れて 最良のエントリーポイントを見逃すかもしれない

  2. 飲み込まれるような出口信号は信頼性がなく 早期出口のリスクがあります

  3. 単一の取引で大きな損失を伴うリスクが広がります

  4. ATR期とボリューム期などのパラメータを調整する必要があります 過剰な取引を避けるために

  5. 退路ルールを最適化して 不必要な退路を避ける必要があります

増進 の 機会

  1. MACDのような追加フィルターを試して 入力信号を改善してください

  2. ATRとボリューム期間を最適化し,過剰取引を減らす.

  3. 価格が下位帯を突破するなど 他の出口信号を探してください

  4. 研究は損失を止め より多くの利益を得るために

  5. 最良の性能のために 異なる保持期間をテストします

  6. 最適品を見つけるために 異なる製品でバックテストします

概要

この戦略は比較的シンプルで,トレンドをフォローするためにボリュームと価格アクションを使用する.明確な信号と簡単な追跡があります.しかし,フィルターと出口ルールの品質はより信頼性の高いパフォーマンスのためにさらに改善することができます.パラメータチューニングとエントリー/出口デザインの継続的な努力により,優れた結果が得られます.


/*backtest
start: 2022-10-10 00:00:00
end: 2023-10-16 00:00:00
period: 1d
basePeriod: 1h
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/
// © DojiEmoji (kevinhhl)

//@version=4
strategy("[KL] Relative Volume Strategy",overlay=true,pyramiding=1)
ENUM_LONG = "Long"
VERBOSE_MODE = false
opened_position = false

// Timeframe {
backtest_timeframe_start = input(defval = timestamp("01 Apr 2016 13:30 +0000"), title = "Backtest Start Time", type = input.time)
USE_ENDTIME = input(false,title="Define backtest end-time (If false, will test up to most recent candle)")
backtest_timeframe_end = input(defval = timestamp("01 May 2021 19:30 +0000"), title = "Backtest End Time (if checked above)", type = input.time)
within_timeframe = true
// }

// Volatility Indicators {
// BOLL:
BOLL_length = 20, BOLL_src = close, SMA20 = sma(BOLL_src, BOLL_length), BOLL_sDEV_x2 = 2 * stdev(BOLL_src, BOLL_length)
BOLL_upper = SMA20 + BOLL_sDEV_x2, BOLL_lower = SMA20 - BOLL_sDEV_x2
plot(SMA20, "Basis", color=#872323, offset = 0)
BOLL_p1 = plot(BOLL_upper, "BOLL Upper", color=color.navy, offset = 0, transp=50)
BOLL_p2 = plot(BOLL_lower, "BOLL Lower", color=color.navy, offset = 0, transp=50)
//fill(BOLL_p1, BOLL_p2, title = "Background", color=#198787, transp=85)
// ATR v. sDev of prices
ATR_x2 = atr(input(10,title="Length of ATR [Trailing Stop Loss] (x2)"))*2
//plot(SMA20+ATR_x2, "SMA20 + ATR_x2", color=color.gray, offset = 0, transp=50)
//plot(SMA20-ATR_x2, "SMA20 - ATR_x2", color=color.gray, offset = 0, transp=50)
//plotchar(ATR_x2, "ATR_x2", "", location = location.bottom)
is_low_volat = ATR_x2 > BOLL_sDEV_x2
// }

// Trailing stop loss {
TSL_source = low

var entry_price = float(0), var stop_loss_price = float(0)

TSL_line_color = color.green
if strategy.position_size == 0 or not within_timeframe
    TSL_line_color := color.black
    stop_loss_price := TSL_source - ATR_x2 
else if strategy.position_size > 0
    stop_loss_price := max(stop_loss_price, TSL_source - ATR_x2)
plot(stop_loss_price, color=TSL_line_color)

// }

// Relative volume indicator {
LEN_RELATIVE_VOL = input(5, title="SMA(volume) length (for relative comparison)")
relative_vol = sma(volume,LEN_RELATIVE_VOL)
// }

// price actions {
bar_range_ratio = abs(close-open)/(high-low)
engulfing = low < low[1] and high > high[1] and abs(close-open) > abs(close-open)[1]
// }

// MAIN:
if within_timeframe
	entry_msg = "", exit_msg = close <= entry_price ? "stop loss" : "take profit"

    // ENTRY :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	if close > open and volume > relative_vol and is_low_volat
		if strategy.position_size > 0
			entry_msg := "adding"
		else if strategy.position_size == 0
			entry_msg := "initial"

		if strategy.position_size == 0
			entry_price := close
			stop_loss_price := TSL_source - ATR_x2
			ATR_x2 := ATR_x2

		strategy.entry(ENUM_LONG, strategy.long, comment=entry_msg)

    // EXIT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	if strategy.position_size > 0
		bExit = false		
		// EXIT: Case (A) touches trailing stop loss
		if TSL_source <= stop_loss_price
			exit_msg := exit_msg + "[TSL]"
			bExit := true
		// EXIT: Case (B)
		else if close < open and not is_low_volat and engulfing and (high-low) > ATR_x2
			exit_msg := VERBOSE_MODE ? exit_msg + "[engulfing bearish]" : exit_msg
			bExit := true
        strategy.close(ENUM_LONG, when=bExit, comment=exit_msg)

// CLEAN UP:
if strategy.position_size == 0
	entry_price := 0
	stop_loss_price := float(0)


もっと