EMAと長期短期間の総量クロスオーバー戦略

作者: リン・ハーンチャオチャン, 日時: 2023-09-20 11:48:34
タグ:

概要

この戦略は,EMAと累積量指標を組み合わせ,トレンドを決定するための交差状況に基づいて購入・売却信号を生成する.これは,より長い時間枠の市場方向性を追跡する典型的なトレンドフォロー戦略に属します.

戦略の論理

50日間のEMAと100日間の累積ボリューム指標が計算される. EMAが下から累積ボリュームを超えると,買い信号が生成され,ロングになる. EMAが上から累積ボリュームを超えると,売り信号が生成され,ショートになる.

ポジションの間,固定ストップ・ロストとテイク・プロフィート戦略が実装される.ストップ・ロスはエントリー価格より8%低く設定される.テイク・プロフィートはエントリー価格より8%高く設定され,価格がテイク・プロフィートレベルに達すると部分的なポジション閉鎖が行われます.

利点分析

この戦略は,トレンドインジケーターEMAと資金流量インジケーター累積ボリュームを組み合わせ,価格とボリュームの両方の情報を活用し,中長期のトレンドを効果的に特定する.固定利益とストップロスは効率的で,リスクを制御しながら部分的利益を固定するのに役立ちます.

EMA期間は,異なる商品に対して自由に調整することができる.長期と短期の両方が線形取引のために実装されている.バックテストはトレンド期間に良いパフォーマンスを示している.

リスク分析

移動平均値への過度な依存は,範囲限定 konsolidiation の際にウィップソーを引き起こす可能性があります.固定利益の取出とストップロスは,早急な退出や超大規模なストップアウトにつながる可能性があります.他の要素なしで価格とボリューム要因のみが考慮されます.

移動平均期間の拡大は誤った信号を減少させる可能性がある. 変動,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"   ) )




もっと