
この戦略は,VWMA指標を用いてトレンドの方向を判断し,ATR指標を用いてストップ・ローンを設定してトレンドを追跡する.この戦略は,明らかなトレンドがある市場環境に適用される.
VWMA指数を使用してトレンドの方向を判断する.価格がVWMAより高いとき,上昇傾向として判断し,多額の取引を行う.価格がVWMAより低いとき,下降傾向として判断し,空白を行う.
偽突破をフィルターするために,RSIオシレータの判断に加える.RSIが30を超えるとのみ多信号を発する.
ATR指標を使用してストップラインを計算する. ATRの長さはVWMAと同じで,倍数は3.5に設定されている. ストップラインは価格に応じてリアルタイムで更新される.
ATR倍数の設定は,ストップラインの収縮幅に影響する.倍数が大きいほど,ストップラインの更新頻度は低く,トレンドを追跡する効果はよりよい.
戦略内のストップ・ロスパーセントとアカウントの利権に基づいてポジションの大きさを計算する.
価格がストップ・ロスの線を下回ると,ストップ・ロスの退出を多項とする.
VWMAの指数は,トレンドの方向を判断し,トレンドの機会を継続的に捉えることができます.
RSI filterを追加し,偽突破信号をフィルターする.
ATRのストップラインはトレンドを追跡し,逆転を回避する.
アカウントの利子率と止損率に基づいてポジションを計算し,リスク管理に有利である.
トレンドの転換点では損失のリスクがある. ポジションを適切に縮小し,単一の損失を減らすべきである.
ATRパラメータの設定が不適切で,止損線が過度に敏感または鈍くなる可能性があります.適切なパラメータをテストして決定する必要があります.
ストップラインの更新が遅れて,損失が拡大する可能性があります.
低波動の市場では,ポジションを下げ,ストップラインの収縮頻度を増やすべきである.
異なるVWMAパラメータの組み合わせをテストして,シグナルを最適に生成するパラメータを選択できます.
RSIオシレータの他のパラメータ設定はテストできます.例えば,超買い超売りラインなどです.
ATRの倍数パラメータをテストして,撤回と追跡の間のトレードオフの最適なポイントを見つけることができます.
MACD,KDなどの他の指標のフィルタリングシグナルと組み合わせて信号の質を向上させることができる.
市場変動に応じてポジション管理とストップ損失パーセントを最適化できます.
この戦略は全体的に偏向的で,明らかな価格トレンドを捕捉するのに適しています. この戦略は,トレンド判断,シグナルフィルタリング,ストップ損失追跡などの優位性がありますが,トレンドの逆転のリスクもあります.最適化パラメータ設定とポジション管理により,より良い戦略効果を得ることができます.
/*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 )