
この戦略は,2つの異なる周期のEMA平均線の交差を計算して市場のトレンドを判断し,それに基づいて取引シグナルを生成する.短期のEMAが長期のEMAを突破すると,市場が上昇傾向に入ると考えれば,この戦略は多額のポジションを開く.短期のEMAが長期のEMAを突破すると,市場が下降傾向に入ると考えれば,この戦略は平仓を退出する.
この戦略は主に双EMA平均線の金叉死叉理論を適用する.双EMA平均線は長線EMAと短線EMAに分けられる.短線EMAのパラメータは10日,長線EMAのパラメータは21日と設定されている.
短線EMA上での長線EMAを突破すると,買入シグナルが生じ,短線EMA下での長線EMAを突破すると,売り出せシグナルが生じます.この策略は,同時に成長率の値を設定し,成長率が値を超えた場合にのみ多額のポジションを開き,下落が値を超えた場合にのみ平仓する.
具体的には,購入条件は,ショートラインEMAがロングラインEMAより高く,株価の成長率は設定された正の値を超えていること;平仓条件は,ショートラインEMAがロングラインEMAより低く,株価の成長率は設定された負の値より低いこと.
この戦略は,全体的に比較的シンプルで,双EMA交差によって価格トレンドを判断し,成長率の値を設定して取引信号を発信する.単一の平均線交差と比較して,部分的な偽信号をフィルターすることができる.しかし,EMA平均線自体は,遅滞性の問題があり,他の指標または動態調節と組み合わせて,戦略の効果をさらに向上させることができる.
/*backtest
start: 2022-11-14 00:00:00
end: 2023-11-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy(title="ema(ema10-21)", overlay=true, pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital = 15000, commission_type = strategy.commission.percent, commission_value = 0.2)
useTimeLimit = input(defval = false, title = "Use Start Time Limiter?")
startYear = input(defval = 2016, title = "Start From Year", minval = 0, step = 1)
startMonth = input(defval = 05, title = "Start From Month", minval = 0,step = 1)
startDay = input(defval = 01, title = "Start From Day", minval = 0,step = 1)
startHour = input(defval = 00, title = "Start From Hour", minval = 0,step = 1)
startMinute = input(defval = 00, title = "Start From Minute", minval = 0,step = 1)
startTimeOk() => true
lenght0 = input(10)
lenght1 = input(21)
source = close
EmaShort = ema(ema(source, lenght0), lenght0)
EmaLong = ema(ema(source, lenght1),lenght1)
plot(EmaShort, color=red)
plot(EmaLong, color=purple)
growth = ((EmaShort-EmaLong)*100)/((EmaShort+EmaLong)/2)
thresholdUp = input(defval=0.05, title="Threshold Up", type=float, step=0.01)
thresholdDown = input(defval=-0.165, title="Threshold Down", type=float, step=0.001)
if( startTimeOk() )
buy_condition = EmaShort > EmaLong and growth > thresholdUp
buy_exit_condition = EmaShort < EmaLong and growth < thresholdDown
strategy.entry("buy", strategy.long, comment="buy", when=buy_condition)
strategy.close(id='buy', when=buy_exit_condition)