Strategi Dagangan Golden Cross Ganda EMA

Penulis:ChaoZhang, Tarikh: 2023-12-07 15:08:57
Tag:

img

Ringkasan

Strategi ini menggabungkan dua salib emas EMA, penapis bunyi bising ATR yang normal, dan penunjuk trend ADX untuk menyediakan isyarat beli yang lebih boleh dipercayai untuk peniaga.

Prinsip Strategi

Strategi ini menggunakan EMA 8 tempoh dan 20 tempoh untuk membina sistem silang emas EMA berganda. Ia menjana isyarat beli apabila EMA tempoh yang lebih pendek melintasi di atas EMA tempoh yang lebih lama.

Di samping itu, strategi telah menubuhkan beberapa penunjuk tambahan untuk penapisan:

  1. 14 tempoh ATR, yang di normalize untuk menapis turun naik harga kecil di pasaran.

  2. ADX 14 tempoh untuk mengenal pasti kekuatan trend.

  3. SMA 14 tempoh jumlah untuk menapis titik masa dengan jumlah dagangan yang kecil.

  4. Indikator Super Trend 4/14 untuk menilai arah pasaran menaik atau menurun.

Hanya apabila arah trend, nilai ATR normal, tahap ADX dan syarat jumlah dipenuhi, salib emas EMA akhirnya akan mencetuskan isyarat beli.

Kelebihan Strategi

  1. Kebolehpercayaan daripada gabungan pelbagai penunjuk

    Mengintegrasikan penunjuk seperti EMA, ATR, ADX dan Super Trend membentuk sistem penapisan isyarat yang kuat, kebolehpercayaan yang lebih tinggi.

  2. Lebih fleksibel dalam penyesuaian parameter

    Nilai ambang ATR, ADX, tempoh penahan dan lain-lain yang normal boleh dioptimumkan, fleksibiliti yang lebih tinggi.

  3. Membezakan pasaran lembu dan lembu

    Mengenali pasaran lembu dan lembu menggunakan Super Trend, mengelakkan peluang yang hilang.

Risiko Strategi

  1. Kesukaran dalam pengoptimuman parameter

    Terlalu banyak parameter, kesukaran dalam mencari kombinasi yang optimum.

  2. Risiko kegagalan penunjuk

    Masih ada risiko isyarat palsu kerana sifat indikator yang tertinggal. Teori stop loss yang betul perlu dipertimbangkan.

  3. Frekuensi perdagangan yang rendah

    Frekuensi cenderung rendah kerana pelbagai penapis, tempoh tidak berdagang yang panjang mungkin.

Arahan pengoptimuman

  1. Mengoptimumkan kombinasi parameter

    Mencari kombinasi optimum memerlukan sejumlah besar data backtesting.

  2. Menggabungkan pembelajaran mesin

    Gunakan algoritma ML untuk mengoptimumkan parameter secara automatik dari masa ke masa.

  3. Pertimbangkan lebih banyak faktor pasaran

    Menggabungkan penunjuk struktur pasaran, emosi dan sebagainya meningkatkan kepelbagaian.

Kesimpulan

Strategi ini secara komprehensif mempertimbangkan trend, turun naik dan faktor harga jumlah. Melalui penapisan pelbagai penunjuk dan penyesuaian parameter, ia membentuk sistem dagangan yang boleh dipercayai. Kebolehpercayaan tinggi dan boleh ditingkatkan lagi melalui pengoptimuman.


/*backtest
start: 2023-11-29 00:00:00
end: 2023-12-06 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/


//Description:
//This strategy is a refactored version of an EMA cross strategy with a normalized ATR filter and ADX control. 
//It aims to provide traders with signals for long positions based on market conditions defined by various indicators.

//How it Works:
//1. EMA: Uses short (8 periods) and long (20 periods) EMAs to identify crossovers.
//2. ATR: Uses a 14-period ATR, normalized to its 20-period historical range, to filter out noise.
//3. ADX: Uses a 14-period RMA to identify strong trends.
//4. Volume: Filters trades based on a 14-period SMA of volume.
//5. Super Trend: Uses a Super Trend indicator to identify the market direction.

//How to Use:
//- Buy Signal: Generated when EMA short crosses above EMA long, and other conditions like ATR and market direction are met.
//- Sell Signal: Generated based on EMA crossunder and high ADX value.

//Originality and Usefulness:
//This script combines EMA, ATR, ADX, and Super Trend indicators to filter out false signals and identify more reliable trading opportunities. 
//USD Strength is not working, just simulated it as PSEUDO CODE: [close>EMA(50)]

//Strategy Results:
//- Account Size: $1000
//- Commission: Not considered
//- Slippage: Not considered
//- Risk: Less than 5% per trade
//- Dataset: Aim for more than 100 trades for sufficient sample size

//Note: This script should be used for educational purposes and should not be considered as financial advice.

//Chart:
//- The script's output is plotted as Buy and Sell signals on the chart.
//- No other scripts are included for clarity.
//- Have tested with 30mins period
//- You are encouraged to play with parameters, let me know if you 

//@version=5
strategy("Advanced EMA Cross with Normalized ATR Filter, Controlling ADX", shorttitle="ALP V5", overlay=true )

// Initialize variables
var bool hasBought = false
var int barCountSinceBuy = 0

// Define EMA periods
emaShort = ta.ema(close, 8)
emaLong = ta.ema(close, 20)

// Define ATR parameters
atrLength = 14
atrValue = ta.atr(atrLength)
maxHistoricalATR = ta.highest(atrValue, 20)
minHistoricalATR = ta.lowest(atrValue, 20)
normalizedATR = (atrValue - minHistoricalATR) / (maxHistoricalATR - minHistoricalATR)

// Define ADX parameters
adxValue = ta.rma(close, 14)
adxHighLevel = 30
isADXHigh = adxValue > adxHighLevel

// Initialize risk management variables
var float stopLossPercent = na
var float takeProfitPercent = na

// Calculate USD strength
// That's not working as usd strenght, since I couldn't manage to get usd strength 
//I've just simulated it as if the current close price is above 50 days average (it's likely a bullish trend), usd is strong (usd_strenth variable is positive)
usd_strength = close / ta.ema(close, 50) - 1

// Adjust risk parameters based on USD strength
if (usd_strength > 0)
    stopLossPercent := 3
    takeProfitPercent := 6
else
    stopLossPercent := 4
    takeProfitPercent := 8

// Initialize position variable
var float positionPrice = na

// Volume filter
minVolume = ta.sma(volume, 14) * 1.5
isVolumeHigh = volume > minVolume

// Market direction using Super Trend indicator
[supertrendValue, supertrendDirection] = ta.supertrend(4, 14)
bool isBullMarket = supertrendDirection < 0
bool isBearMarket = supertrendDirection > 0

// Buy conditions for Bull and Bear markets
buyConditionBull = isBullMarket and ta.crossover(emaShort, emaLong) and normalizedATR > 0.2
buyConditionBear = isBearMarket and ta.crossover(emaShort, emaLong) and normalizedATR > 0.5
buyCondition = buyConditionBull or buyConditionBear

// Sell conditions for Bull and Bear markets
sellConditionBull = isBullMarket and (ta.crossunder(emaShort, emaLong) or isADXHigh)
sellConditionBear = isBearMarket and (ta.crossunder(emaShort, emaLong) or isADXHigh)
sellCondition = sellConditionBull or sellConditionBear

// Final Buy and Sell conditions
if (buyCondition)
    strategy.entry("Buy", strategy.long)
    positionPrice := close
    hasBought := true
    barCountSinceBuy := 0

if (hasBought)
    barCountSinceBuy := barCountSinceBuy + 1

// Stop-loss and take-profit levels
longStopLoss = positionPrice * (1 - stopLossPercent / 100)
longTakeProfit = positionPrice * (1 + takeProfitPercent / 100)

// Final Sell condition
finalSellCondition = sellCondition and hasBought and barCountSinceBuy >= 3 and isVolumeHigh

if (finalSellCondition)
    strategy.close("Buy")
    positionPrice := na
    hasBought := false
    barCountSinceBuy := 0

// Implement stop-loss and take-profit
strategy.exit("Stop Loss", "Buy", stop=longStopLoss)
strategy.exit("Take Profit", "Buy", limit=longTakeProfit)

// Plot signals
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(series=finalSellCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")


Lebih lanjut