EMA dan Strategy Crossover Volume Kumulatif untuk Pendek Panjang

Penulis:ChaoZhang, Tarikh: 2023-09-20 11:48:34
Tag:

Ringkasan

Strategi ini menggabungkan penunjuk EMA dan jumlah kumulatif, menghasilkan isyarat beli dan jual berdasarkan situasi silang mereka untuk menentukan trend.

Logika Strategi

EMA 50 hari dan penunjuk jumlah kumulatif 100 hari dikira. Apabila EMA melintasi di atas jumlah kumulatif dari bawah, isyarat beli dihasilkan untuk pergi panjang. Apabila EMA melintasi di bawah jumlah kumulatif dari atas, isyarat jual dihasilkan untuk pergi pendek.

Semasa kedudukan, strategi stop loss dan mengambil keuntungan tetap dilaksanakan. Stop loss ditetapkan pada 8% di bawah harga masuk. Ambil keuntungan ditetapkan pada 8% di atas harga masuk, dengan penutupan kedudukan separa apabila harga mencapai tahap mengambil keuntungan.

Analisis Kelebihan

Strategi ini menggabungkan penunjuk trend EMA dan jumlah kumulatif penunjuk aliran dana, memanfaatkan kedua-dua maklumat harga dan jumlah untuk mengenal pasti trend jangka menengah dan panjang dengan berkesan.

Tempoh EMA boleh diselaraskan secara bebas untuk produk yang berbeza. Kedua-dua perdagangan panjang dan pendek dilaksanakan untuk perdagangan linear.

Analisis Risiko

Kepercayaan yang berlebihan terhadap purata bergerak boleh menyebabkan whipsaws semasa penyatuan terhad julat. Mengambil keuntungan tetap dan menghentikan kerugian juga boleh menyebabkan keluar awal atau berhenti terlalu besar. Hanya faktor harga dan jumlah yang dipertimbangkan tanpa elemen lain.

Peningkatan tempoh purata bergerak boleh mengurangkan isyarat palsu. Penunjuk tambahan seperti turun naik, RSI juga boleh membantu penghakiman. Mengoptimumkan mekanisme mengambil keuntungan dan menghentikan kerugian, melalui hentian jejak, keluar dinamik dan lain-lain boleh menjadi bermanfaat.

Arahan pengoptimuman

  1. Uji dan optimumkan kombinasi parameter EMA untuk mencari tetapan optimum.

  2. Menggabungkan penunjuk teknikal lain untuk membentuk sistem ensemble.

  3. Menggunakan pembelajaran mesin untuk meramalkan trend dan meningkatkan prestasi EMA.

  4. Mengoptimumkan strategi mengambil keuntungan dan menghentikan kerugian dengan menggabungkan hentian jejak, keluar dinamik dll.

  5. Memperkenalkan modul pengurusan modal untuk saiz kedudukan dinamik.

  6. Sesuaikan parameter berdasarkan ciri produk untuk membentuk keseluruhan strategi.

Ringkasan

Idea strategi menggabungkan EMA dan jumlah untuk pengenalan trend adalah jelas. Tetapi terlalu bergantung pada purata bergerak dan keluar tetap mempunyai kelemahan. Menambah lebih banyak penunjuk penilaian dan mengoptimumkan keluar boleh meningkatkan ketahanan. Secara keseluruhan ia memberikan idea menggunakan data harga dan jumlah untuk penjejakan trend.


/*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"   ) )




Lebih lanjut