移動平均入口最適化戦略

作者: リン・ハーンチャオチャン, 日付: 2023-09-14 16:52:30
タグ:

戦略の論理

この戦略は,基本的な移動平均システムからの信号の後にエントリーポイントを最適化します.

主な論理は

  1. 期間中の移動平均を計算する (例えば20日)

  2. クロスオーバーは長/短信号を生成します

  3. シグナルが出た後,すぐに入らないで,より高いレベルまで待って

  4. 指定された日 (例えば3日) 内により良いレベルが発生した場合,取引を入力します.

  5. 5日目の閉店価格で入力してください.

これは,すぐにシグナルに入るのではなく,統合後のトレンドの再開をキャピタリングすることを目指し,改善されたレベルでのポジションを確立することができます.

利点

  • より良いエントリーレベルのためのエントリー最適化

  • 最大待機日数は,完全に欠けている取引を回避します

  • シンプルで明快なルール 実行が簡単

リスク

  • 待機時間と限界値は最適化が必要です

  • 短期的なトレンドの機会を逃すかもしれない

  • 時間と価格の両方の状況を監視する必要性

概要

この戦略は,シンプルなエントリー最適化によって,より良いエントリーレベルを得ることを目指し,同時にトレンドを見逃さないようにしています.しかし,待ち時間とエントリー基準の最適化は重要です.


/*backtest
start: 2023-08-14 00:00:00
end: 2023-09-13 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/
// © dongyun

//@version=4
strategy("等待一个更好的入场机会", overlay=true)

period = input(20,'')
maxwait = input(3,'')
threshold = input(0.01,'')

signal = 0
trend = 0.0
newtrend = 0.0
wait = 0.0
initialentry = 0.0

trend := sma(close,period)
signal := nz(signal[1])
if trend > nz(trend[1])
	signal := 1
else
	if trend < nz(trend[1])
		signal := -1

wait := nz(wait[1])
initialentry := nz(initialentry[1])

if signal != signal[1]
	if strategy.position_size > 0
		strategy.close('long',comment='trend sell')
		signal := -1
	else
		if strategy.position_size < 0
    		strategy.close('short',comment='trend buy')
    		signal := 1
	wait := 0
	initialentry := close
else
	if signal != 0 and strategy.position_size == 0
		wait := wait + 1

// test for better entry
if strategy.position_size == 0
	if wait >= maxwait
		if signal > 0
			strategy.entry('long',strategy.long, comment='maxtime Long')
		else
			if signal < 0
				strategy.entry('short',strategy.short, comment='maxtime Short')
	else
		if signal > 0 and close < initialentry - threshold
			strategy.entry('long',strategy.long, comment='delayed Long')
		else
			if signal < 0 and close > initialentry + threshold
				strategy.entry('short',strategy.short, comment='delayed short')


もっと