VWMAとATRは戦略をフォローする傾向

作者: リン・ハーンチャオチャン,日付: 2023年11月7日 16:39:47
タグ:

img

概要

この戦略は,トレンドの方向性を決定するためにVWMAを使用し,トレンドをフォローするためにATRでストップロスを設定します.これは明らかなトレンドを持つ市場に適しています.

戦略の論理

  1. トレンド方向を判断するには VWMA を使います.価格が VWMA よりも高くなったときにロング,価格が VWMA よりも低いときにショート.

  2. 誤ったブレイクシグナルを避けるため,RSIオシレーターフィルターを追加します.RSIが30を超える場合にのみ,ロングシグナルを取ります.

  3. ストップ損失ラインを計算するためにATRを使用します. ATRの長さはVWMAと同じに設定され,倍数は3.5です.ストップ損失ラインはリアルタイムで更新されます.

  4. ATR倍数はストップ・ロスの線の緊度を制御する.より大きい倍数は更新頻度が少なく,トレンドをフォローするのに良いことを意味します.

  5. ポジションの大きさは,口座の自己資本とストップロスの割合に基づいて計算されます.

  6. 価格がストップ・ロスの線を下回るとロングポジションを終了する.

利点

  1. VWMA を使ってトレンドを特定すると 傾向の機会を持続的に捉えるのです

  2. RSIフィルターは 誤った信号を回避します

  3. ATRの遅延停止は,トレンドをたどり,逆転によって停止されない.

  4. 口座の自己資本とストップ損失に基づくポジションのサイズ化はリスク管理を好む.

リスク

  1. トレンドターニングポイントでの損失の可能性は 損失を制限するために ポジションサイズを減らすべきです

  2. ATR パラメータの設定が正しくない場合,ストップ・ロストラインが狭すぎたり緩やかになる.パラメータをテストする必要があります.

  3. 急速なトレンド逆転は,ストップ・ロスの更新が遅れて損失を増やす可能性があります.

  4. 変動が低い環境では,ポジションのサイズを小さくし,ストップロスの更新頻度を増やす.

強化

  1. VWMA パラメータの組み合わせをテストし,最適な信号 パラメータを見つけます.

  2. RSIの他の設定をテストします 例えば,買い過ぎ/売り過ぎのラインです

  3. ATR マルチプリキュアをテストして,引き上げと追跡能力の最適なバランスを探す.

  4. MACD,KDなどのフィルターを追加して信号の質を向上させます

  5. ポジションのサイズとストップロスの割合を市場変動に基づいて最適化する.

概要

この戦略は,全体的なトレンドフォローバイアスを有し,明らかな価格傾向をうまく捉える.トレンド決定,シグナルフィルタリング,ストップロストトラッキングなどにおいて利点がある.トレンド逆転におけるリスクも有する.微調整パラメータとポジションサイジングによりより良いパフォーマンスが得られる.


/*backtest
start: 2023-10-07 00:00:00
end: 2023-10-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/
// © mohanee

//@version=4
//strategy("", overlay=true)
strategy(title="VWMA_withATRstops_strategy V2", overlay=true, pyramiding=1,     default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000, currency=currency.USD)  //default_qty_value=10, default_qty_type=strategy.fixed,

float xATRTrailingStop=na
int pos=na

vwmalength = input(33, title="VWMA Length", minval=1, maxval=365)
//vwmalength2 = input(9, title="VWAM Short Term Length", minval=1, maxval=365)
nATRPeriod = input(33, title="ATR length", minval=1, maxval=365)
nATRMultip = input(3.5, title="ATR Multiplier")

rsiofVwmaLength=input(14, title="RSI of VWMA Length")

riskCapital = input(title="Risk % of capital", defval=10, minval=1)
stopLoss=input(5,title="Stop Loss",minval=1)

vwmaVal=vwma(close, vwmalength)
//vwmaVal2=vwma(close, vwmalength2)
//maVal=sma(close, vwmalength)

plot(vwmaVal, color=color.orange, linewidth=2,  title="VWMA")
//plot(vwmaVal2, color=color.blue, title="VWMA Short Term")
//plot(maVal, color=color.blue, title="MA")

//rsi of vwma Longterm
rsiofVwmaVal=rsi(vwmaVal,rsiofVwmaLength)

xATR = atr(nATRPeriod)
nLoss = nATRMultip * xATR

xATRTrailingStop:= iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss), iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))

pos:=	iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1, 	    iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) 

color1 = pos == -1 ? color.red: pos == 1 ? color.green : color.blue 

//plot(xATRTrailingStop, color=color1, title="ATR Trailing Stop")

//Entry--
//Echeck how many units can be purchased based on risk manage ment and stop loss
qty1 = (strategy.equity  * riskCapital / 100 ) /  (close*stopLoss/100)  

//check if cash is sufficient  to buy qty1  , if capital not available use the available capital only
qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1


//Long Entry
//strategy.entry(id="VWMA LE", long=true, qty=qty1, when= close >vwmaVal and open>vwmaVal and close>open and close > xATRTrailingStop and xATRTrailingStop>  vwmaVal)

strategy.entry(id="VWMA LE", long=true, qty=qty1, when= rsiofVwmaVal>=30 and  close>open and close>vwmaVal and pos == 1 )    ///pos == 1 means ATRStop line is green    
//vwmaVal2>vwmaVal and

plot(strategy.position_size>=1  ? xATRTrailingStop : na, color=color1, style=plot.style_linebr, title="ATR Trailing Stop")
bgcolor(strategy.position_size>=1 ? color.blue : na )

//Exit
strategy.close(id="VWMA LE",  when= strategy.position_size>=1 and crossunder(close, xATRTrailingStop)  )
//strategy.close(id="VWMA LE",  when= strategy.position_size>=1 and close<vwmaVal and open<vwmaVal and close<open )

もっと