EMAと累積ボリュームに基づくロングとショートの取引戦略


作成日: 2023-09-20 11:48:34 最終変更日: 2023-09-20 11:48:34
コピー: 0 クリック数: 793
1
フォロー
1617
フォロワー

概要

この戦略は,EMAと累積取引量指標を組み合わせて,両者の交差状況に基づいて市場トレンドを判断し,買入と売却のシグナルを生成する.これは,典型的なトレンド追跡戦略であり,より長い線レベルの市場の方向を追跡する.

戦略原則

50日間のEMA平均線と100日間の累積取引量指標を計算する.EMAが累積取引量を下から上へと突破すると,買い込みシグナルが作られる.EMAが累積取引量を上から下へと突破すると,売り込みシグナルが作られる.

ポジションの維持過程で,固定ストップとストップを exiting 策に設定する. ストップは入場価格の8%以下に設定し,ストップは入場価格の8%以上に設定し,価格がストップポイントに達したときにポジションの一部を平仓する.

優位分析

この戦略は,トレンド指数EMAとキャピタルフロー指数累積取引量と組み合わせて,価格と取引量情報を充分利用し,中長期トレンドを効果的に識別できます.固定ストップ・ストップ・損失戦略は,直接的に高効率で,利潤の一部をロックし,リスクを制御するのに有利です.

EMA周期パラメータを自由に調整し,異なる品種に適応する. 多数の空白を行い,線形取引を実現する. 追跡データによると,トレンド状況で,戦略は良好なパフォーマンスを発揮している.

リスク分析

この戦略は均線指標に過度に依存し,区間振動の状況で誤信号が発生しやすい.固定ストップストップは,早すぎる出場または過大なストップにもなりうる.価格と取引量情報のみを考慮し,他の要因を考慮しない.

適当な平均線パラメータを拡張して誤信号を減らすことができる.また,波動率,RSIなどの指標の補助判断を導入することができる.ストップ・ストップ・メカニズムを最適化する.例えば,追跡ストップ・ストップ,ダイナミック・ストップなどの方法を導入する.

最適化の方向

  1. EMAパラメータの組み合わせをテストして最適パラメータを探します.

  2. 他の技術指標を導入し,指標の組み合わせ戦略を形成する.

  3. 機械学習を用いて価格の動向を予測し,EMAの効果を向上させる.

  4. ストップ・ストップ・ストップ戦略の最適化,ストップ・トラッキング,ダイナミック・ストップなどのメカニズムと組み合わせる.

  5. 資金管理モジュールを導入し,ポジションを動的に調整する.

  6. 品種特性に合わせてパラメータを調整し,戦略の組み合わせを形成する.

要約する

この戦略はEMAと取引量指標を統合し,中長線トレンドの判断方法が明確である.しかし,平均線と固定ストップストロップに過度に依存するのも問題がある.より多くの指標判断を加え,ストップストロップ戦略を最適化することで,戦略の安定性と収益の余地が向上する.全体的に,価格と取引量情報を利用してトレンド追跡するための方法を提供する.

ストラテジーソースコード
/*backtest
start: 2023-08-20 00:00:00
end: 2023-09-19 00:00:00
period: 2h
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("EMA_cumulativeVolume_crossover[Strategy]", overlay=true, pyramiding=1, default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000)


emaLength= input(50, title="EMA Length", minval=1, maxval=200)
cumulativePeriod = input(100,  title="cumulative volume Period", minval=1, maxval=200)


riskCapital = input(title="Risk % of capital", defval=10, minval=1)
stopLoss=input(8,title="Stop Loss",minval=1)
takePartialProfits=input(false, title="take partial profits  (percentage same as stop loss)")

tradeDirection=input(title="Trade Direction", defval="LONG", options=["LONG", "SHORT"])

avgPrice = (high + low + close) / 3
avgPriceVolume = avgPrice * volume

cumulPriceVolume = sum(avgPriceVolume, cumulativePeriod)
cumulVolume = sum(volume, cumulativePeriod)

vwapValue = cumulPriceVolume / cumulVolume

emaVal=ema(close, emaLength)

plot(emaVal, title="EMA", color=color.green,  transp=25)
plot(vwapValue, title="Cumulate Volumne / VWAP", color=color.orange,  linewidth=2, transp=25)

bgcolor(emaVal>vwapValue?color.blue:color.purple)    

//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

strategy.entry(id="LE",comment="LE", long=true, qty=qty1, when=crossover(emaVal, vwapValue)  and (tradeDirection=="LONG") )    //emaVal>vwapValue and crossover(close , emaVal)

//stoploss
stopLossVal=  strategy.position_size>=1 ?  (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00

//draw initil stop loss
plot(strategy.position_size>=1 ? stopLossVal : na, color = color.purple , style=plot.style_linebr,  linewidth = 2, title = "stop loss")

//partial exits
takeProfit=  strategy.position_size>=1 ?  (strategy.position_avg_price * (1+(stopLoss*0.01) )) : ( close[1] * 2 )
if(takePartialProfits==true)
    strategy.close(id="LE", comment="Partial"+tostring(close-strategy.position_avg_price, "###.##") , qty=strategy.position_size/3 , when = (tradeDirection=="LONG" ) and close>takeProfit and crossunder(close, emaVal) )    //close<close[1] and close[1]<close[2] and close[2]<close[3])
    
strategy.close(id="LE" , comment="LE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when=crossunder(emaVal, vwapValue) and (tradeDirection=="LONG") )

strategy.close(id="LE" , comment="SL Exit Loss="+tostring(close-strategy.position_avg_price, "###.##"), when= close < stopLossVal   and (tradeDirection=="LONG") )


//for short  you dont have to wait crossodown of ema, falling is speed , so just check if close crossing down vwapVal
strategy.entry(id="SE",comment="SE", long=false, qty=qty1, when=(close<vwapValue and close<open  and close[1] < vwapValue  and close[1]<open[1] and close<close[1])  and emaVal>=vwapValue and (tradeDirection=="SHORT") )    //emaVal>vwapValue and crossover(close , emaVal)

//stoploss
stopLossValUpside=  abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ?  (strategy.position_avg_price * (1+(stopLoss*0.01) )) : 0.00

//draw initil stop loss
plot(abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ? stopLossValUpside : na, color = color.purple , style=plot.style_linebr,  linewidth = 2, title = "stop loss")

//partial exits
shortTakeProfit=  abs(strategy.position_size)>=1 and tradeDirection=="SHORT" ?  (strategy.position_avg_price * (1-(stopLoss*0.01) )) : 0.00
if(takePartialProfits==true)
    strategy.close(id="SE", comment="Partial" , qty=strategy.position_size/3 , when = (tradeDirection=="SHORT"   ) and  close<shortTakeProfit )  //close<takeProfit and (emaVal - close)>8 )
  
//strategy.close(id="SE" , comment="SE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when=crossover(emaVal, vwapValue) and (tradeDirection=="SHORT") )
strategy.close(id="SE" , comment="SE Exit Points="+tostring(close-strategy.position_avg_price, "###.##"), when= abs(strategy.position_size)>=1 and ( (emaVal<vwapValue and close>vwapValue and open>vwapValue and close>open )   or (crossover(emaVal,vwapValue))  ) and (tradeDirection=="SHORT") )

strategy.close(id="SE" , comment="SL Exit Loss="+tostring(close-strategy.position_avg_price, "###.##"), when= abs(strategy.position_size)>=1 and  close > stopLossValUpside   and (tradeDirection=="SHORT"   ) )