리소스 로딩... 로딩...

분량-가격 동력 거래 전략과 함께 멀티 EMA 크로스

저자:차오장, 날짜: 2025-01-06 16:07:59
태그:EMAVWAPSMASLORSIHLC3MOL

img

이 전략은 여러 기하급수적인 이동 평균 (EMA) 크로스오버 및 볼륨 가격 지표에 기반한 포괄적인 모멘텀 거래 전략입니다. 이 전략은 빠른 및 느린 EMA, 볼륨 가중 평균 가격 (VWAP) 및 슈퍼 트렌드 등 다양한 지표를 결합하여 거래 신호를 생성하며, 입점 및 출구 지점을 제어하기 위해 내일 거래 창과 가격 움직임 문턱을 통합합니다.

전략 원칙

이 전략은 5일 및 13일 EMA를 주요 트렌드 지표로 사용합니다. 빠른 EMA가 VWAP 이상의 폐쇄 가격과 느린 EMA를 넘을 때 긴 포지션은 시작되며 빠른 EMA가 VWAP보다 낮은 폐쇄 가격과 느린 EMA를 넘을 때 짧은 포지션은 시작됩니다. 이 전략은 또한 트렌드 확인 및 스톱 로스 결정에 대한 슈퍼 트렌드 지표를 포함합니다. 이전 하루의 종료와 하루의 높은 낮은 범위에 대한 가격 움직임과 같은 다른 거래 날에 대한 다른 입구 조건이 설정됩니다.

전략적 장점

  1. 여러 가지 기술 지표가 거래 신호의 신뢰성을 향상시킵니다.
  2. 다른 거래일에 대한 차별화된 입시 조건은 시장 특성에 더 잘 적응합니다
  3. 역동적 이윤 취득 및 스톱 로스 메커니즘은 위험을 효과적으로 제어합니다.
  4. 일내 거래창 제한은 높은 변동성 기간을 피합니다.
  5. 이전 높은 낮은 점과 가격 움직임의 제약은 높은 점과 낮은 점에 따라가는 위험을 줄입니다.

전략 위험

  1. 빠르게 변동하는 시장에서 잘못된 신호가 발생할 수 있습니다.
  2. 초기 트렌드 반전 중 잠재적인 지연
  3. 매개 변수 최적화는 과도한 부착 위험에 직면 할 수 있습니다.
  4. 거래 비용은 전략 수익에 영향을 줄 수 있습니다.
  5. 매우 변동적인 시장 기간 동안 가능한 상당한 마취

전략 최적화 방향

  1. 추세 강도를 더 확인하기 위해 부피 분석 지표를 통합하는 것을 고려하십시오.
  2. 전략 적응력을 향상시키기 위해 다른 거래일에 대한 매개 변수를 최적화하십시오.
  3. 예측 정확성을 향상시키기 위해 더 많은 시장 감정 지표를 추가하십시오.
  4. 자본 효율성 향상을 위해 수익 및 손실 중지 메커니즘을 개선
  5. 포지션 관리 최적화를 위해 변동성 지표를 추가하는 것을 고려하십시오.

요약

이 전략은 여러 가지 기술적 지표를 종합적으로 사용하여 트렌드 추적 및 모멘텀 트레이딩의 조합을 달성합니다. 전략 설계는 다른 거래 일에 대해 차별화된 거래 규칙을 채택함으로써 시장 다양성을 완전히 고려합니다. 엄격한 위험 통제 및 유연한 수익 취득 및 스톱 로스 메커니즘을 통해 전략은 좋은 실용적 응용 가치를 보여줍니다. 미래 개선은 추가 기술 지표를 도입하고 매개 변수 설정을 최적화함으로써 전략 안정성과 수익성을 향상시킬 수 있습니다.


/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
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/
//@version=6
strategy("S1", overlay=true)
fastEMA = ta.ema(close, 5)
slowEMA = ta.ema(close,13)
ema9 = ta.ema(close, 9)
ema100 = ta.ema(close, 100)
ema5 = ta.ema(close, 5)
ema200 = ta.ema(close, 200)

ma = ta.sma(close, 50)

mult = input.float(defval=3)
len = input.int(defval=11)
[superTrend, dir] = ta.supertrend(mult, len)
vwap1= ta.vwap(hlc3)

plot(slowEMA,color = color.green)
plot(fastEMA,color = color.black)
plot(vwap1, color = color.blue)

var dailyTaskDone = false
var gapdown = false
var gapup = false
var runup = 0.0
var biggapdown = false
var biggapup = false
var prevDayClose = 0.0
var todayLow = 0.0
var todayHigh = 0.0
var noBuyNow = false
var noSellNow = false
var buyPrice = 0.0
var sellPrice = 0.0
var todayBuyDone = false
var todaySellDone = false
var dragonflyDoji = false
var candleCount = 0
var candleCount1 = 0
var lastTrade = 9
var lastFiveCandles = false
var lastSevenCandlesS = false
var fiveEMACC = 0
candleCount := candleCount + 1
candleCount1 := candleCount1 + 1

if fiveEMACC > 0
    fiveEMACC := fiveEMACC + 1

if fiveEMACC == 6
    fiveEMACC := 0

if strategy.openprofit == 0
    candleCount := 0

if hour == 9 and minute ==15
    prevDayClose := close[1]
    todayLow := low
    todayHigh := high
    lastTrade := 9
    
if hour == 9 and minute ==15 and (open - close[1]) >  close*0.01
    gapup := true
    
if hour == 9 and minute ==15 and (open - close[1]) <  close*0.005*-1
    gapdown := true

if hour == 9 and minute ==15 and (close - close[1]) > 200
    biggapup := true
    
if hour == 9 and minute ==15 and (close - close[1]) < 200
    biggapdown := true

if low < todayLow
    todayLow := low
    candleCount1 := 0
if high > todayHigh
    todayHigh := high

if close > todayLow + 200
    noBuyNow := true
    
if close < todayHigh - 200//0.01*close
    noSellNow := false

lastFiveCandles := (close[4]<open[4] or close[3]<open[3] or close[2] < open[2] or close[1]<open[1])
lastSevenCandlesS := (close[6]>open[6] or close[5]>open[5] or close[4]>open[4] or close[3]>open[3] or close[2] > open[2] or close[1]>open[1])
if hour == 15
    dailyTaskDone := false
    gapdown := false
    gapup := false
    biggapup := false
    biggapdown := false
    noBuyNow := false
    noSellNow := false
    todayLow := 0.0
    todayHigh := 0.0
    buyPrice  := 0.0
    sellPrice := 0.0
    todayBuyDone := false
    todaySellDone := false
    dragonflyDoji := false
    lastTrade := 9

// if fastEMA < slowEMA and lastTrade == 1 and strategy.openprofit==0
//     lastTrade := 9


if fastEMA > slowEMA and lastTrade == 0 and strategy.openprofit==0
    lastTrade := 9
    
buy =  (dayofweek==dayofweek.thursday and (fastEMA - slowEMA > close*0.001) and close > vwap1 and close[1] > vwap1[1]) or 
       (dayofweek==dayofweek.monday and (fastEMA - slowEMA > close*0.001) and close > vwap1 and close[1] > vwap1[1] and close-prevDayClose < close*0.011) or 
       (dayofweek==dayofweek.tuesday and (fastEMA - slowEMA > close*0.001) and close > vwap1 and close[1] > vwap1[1] and lastFiveCandles  and close-prevDayClose < close*0.015 and close-todayLow < close*0.012) or
       (dayofweek==dayofweek.wednesday and (fastEMA - slowEMA > close*0.001) and close > vwap1 and close-prevDayClose < close*0.015 and (hour!=9 or minute>=35) and close-todayLow < close*0.012) or
       (dayofweek==dayofweek.friday and ((fastEMA - slowEMA > close*0.001))and close > vwap1 and close[1] > vwap1[1] and (hour!=9 or minute>=35))
       
sell=  (dayofweek==dayofweek.thursday and (hour!=9 or minute>=35) and ((slowEMA - fastEMA > close*0.00089)) and close < vwap1  and lastSevenCandlesS and close[1] < vwap1[1]) or 
       (dayofweek==dayofweek.monday and ((slowEMA - fastEMA > close*0.00089)) and close < vwap1 and close[1] < vwap1[1] and not dragonflyDoji and todayHigh-close < close*0.008 and todayHigh-close[1] < close * 0.01 ) or 
       (dayofweek==dayofweek.tuesday and  (hour!=9 or minute>=35) and (open - low < 2*(high-close)) and (close-open<10)  and not dragonflyDoji  and (slowEMA - fastEMA > close*0.00089) and close < vwap1 and close[1] < vwap1[1]  and prevDayClose-close<close*0.012 and todayHigh-close < close*0.009 and todayHigh-close[1] < close * 0.009) or
       (dayofweek==dayofweek.wednesday  and  (hour!=9 or minute>=40) and close<open and (slowEMA - fastEMA > close*0.00089) and close < vwap1 and close[1] < vwap1[1] and not dragonflyDoji and (close-todayLow>30 or candleCount1<1) ) or 
       (dayofweek==dayofweek.friday and ((slowEMA - fastEMA > close*0.00089)) and close < vwap1 and close[1] < vwap1[1] and not dragonflyDoji and (hour!=9 or minute>=55) ) 

// buy =  (dayofweek==dayofweek.thursday and (fastEMA > slowEMA) and close > vwap1 and close[1] > vwap1[1]) or 
//        (dayofweek==dayofweek.monday and (fastEMA > slowEMA) and close > vwap1 and close[1] > vwap1[1] and close-prevDayClose < close*0.011) or 
//        (dayofweek==dayofweek.tuesday and (fastEMA > slowEMA) and close > vwap1 and close[1] > vwap1[1] and lastFiveCandles  and close-prevDayClose < close*0.015 and close-todayLow < close*0.012) or
//        (dayofweek==dayofweek.wednesday and (fastEMA > slowEMA) and close > vwap1 and close-prevDayClose < close*0.015 and (hour!=9 or minute>=35) and close-todayLow < close*0.012) or
//        (dayofweek==dayofweek.friday and ((fastEMA > slowEMA))and close > vwap1 and close[1] > vwap1[1] and (hour!=9 or minute>=35))
       
// sell=  (dayofweek==dayofweek.thursday and (hour!=9 or minute>=35) and ((slowEMA > fastEMA)) and close < vwap1  and lastSevenCandlesS and close[1] < vwap1[1]) or 
//        (dayofweek==dayofweek.monday and ((slowEMA > fastEMA)) and close < vwap1 and close[1] < vwap1[1] and not dragonflyDoji and todayHigh-close < close*0.008 and todayHigh-close[1] < close * 0.01 ) or 
//        (dayofweek==dayofweek.tuesday and  (hour!=9 or minute>=35) and (open - low < 2*(high-close)) and (close-open<10)  and not dragonflyDoji  and (slowEMA > fastEMA) and close < vwap1 and close[1] < vwap1[1]  and prevDayClose-close<close*0.012 and todayHigh-close < close*0.009 and todayHigh-close[1] < close * 0.009) or
//        (dayofweek==dayofweek.wednesday  and  (hour!=9 or minute>=40) and close<open and (slowEMA > fastEMA) and close < vwap1 and close[1] < vwap1[1] and not dragonflyDoji and (close-todayLow>30 or candleCount1<1) ) or 
//        (dayofweek==dayofweek.friday and ((slowEMA > fastEMA)) and close < vwap1 and close[1] < vwap1[1] and not dragonflyDoji and (hour!=9 or minute>=55) ) 

dragonflyDoji:= false

// (slowEMA - fastEMA > close*0.00089 or (slowEMA-fastEMA>close*0.00049 and (high[2]>vwap or high[1]>vwap)))
if sellPrice != 0 and runup < sellPrice - low
    runup := sellPrice - low


if buyPrice != 0 and runup < high - buyPrice
    //ourlabel = label.new(x=bar_index, y=na, text=tostring(runup), yloc=yloc.belowbar)
    runup := high - buyPrice
    
        
NoBuySellTime = (hour == 15) or ((hour==14 and minute>=25)) or (hour==9 and minute<=35) or hour >= 14
//(fiveEMACC > 0 and low < fastEMA and close < vwap1)
buyexit     =  fastEMA<slowEMA or (close<superTrend and close < vwap1 and close[1] < vwap1[1]) //or strategy.openprofit > 400 or strategy.openprofit < -5000
sellexit =  slowEMA<fastEMA or (close > vwap1 and close[1] > vwap1[1] and close>superTrend) //or strategy.openprofit > 400 or strategy.openprofit < -5000

exitPosition =  (dayofweek==dayofweek.thursday and buyPrice!=0.0 and (high - buyPrice) > 50) or (dayofweek==dayofweek.thursday and sellPrice!=0.0 and (sellPrice - low) > 80) or (dayofweek==dayofweek.monday and buyPrice !=0.0 and high-buyPrice > 30) or (dayofweek==dayofweek.monday and sellPrice!=0.0 and (sellPrice - low) > 30) or (dayofweek!=dayofweek.thursday and dayofweek!=dayofweek.monday  and buyPrice!=0.0 and (high - buyPrice) > 30) or  (dayofweek!=dayofweek.thursday  and dayofweek!=dayofweek.monday and sellPrice!=0.0 and (sellPrice - low) > 30)
//code such that 2 fastema is > than 2 slowema
//exitPosition =  (sellPrice!=0 and runup >21 and strategy.openprofit < -2000) or (candleCount > 18 and strategy.openprofit > 50 and strategy.openprofit < 1000) or (dayofweek==dayofweek.thursday and buyPrice!=0.0 and (high - buyPrice) > buyPrice * 0.007) or (dayofweek==dayofweek.thursday and sellPrice!=0.0 and (sellPrice - low) > sellPrice * 0.007) or (dayofweek==dayofweek.monday and buyPrice !=0.0 and high-buyPrice > 30) or (dayofweek!=dayofweek.thursday and dayofweek!=dayofweek.monday  and buyPrice!=0.0 and (high - buyPrice) > buyPrice * 0.002) or  (dayofweek!=dayofweek.thursday  and sellPrice!=0.0 and (sellPrice - low) > sellPrice * 0.002)
//(runup >21 and strategy.openprofit < -2000) or
if  buy and fastEMA>vwap1 and (not todayBuyDone or lastTrade != 1) and not NoBuySellTime// and not dailyTaskDone //and (dayofweek==dayofweek.friday or (close-prevDayClose)<150)//and not biggapup
    strategy.entry("buy", strategy.long)
    //dailyTaskDone := true
    if buyPrice == 0.0 
        fiveEMACC := 1

    buyPrice := close
    //ourlabel = label.new(x=bar_index, y=na, text=tostring(todayLow + 500), yloc=yloc.belowbar9
    todayBuyDone := true
    lastTrade := 1
    runup := 0.0

if  sell and (not todaySellDone or lastTrade != 0) and not NoBuySellTime// and not dailyTaskDone // and dayofweek!=dayofweek.friday //and (dayofweek==dayofweek.friday or (prevDayClose-close)<150)//and not biggapdown
    strategy.entry("sell", strategy.short)
    //dailyTaskDone := true
    if sellPrice == 0.0 
        fiveEMACC := 1
    sellPrice := close
    todaySellDone := true
    lastTrade := 0
    runup := 0.0

// if ((fastEMA-slowEMA>18 and close>vwap and close[1]>vwap[1] and (not todayBuyDone or candleCount>12)) or (slowEMA-fastEMA>10 and close < vwap and close[1]<vwap[1] and (not todaySellDone or candleCount > 12))) and strategy.openprofit==0
// ourlabel = label.new(x=bar_index, y=na, text=tostring(abs(prevDayClose-close)), yloc=yloc.belowbar)
    
IntraDay_SquareOff = minute >=15 and hour >= 15
if true and (IntraDay_SquareOff or exitPosition)
    strategy.close("buy")
    strategy.close("sell")
    buyPrice := 0
    sellPrice := 0
    runup := 0.0
if  buyexit
    strategy.close("buy")
    buyPrice := 0
if sellexit
    strategy.close("sell")
    sellPrice := 0

buy1 =  ((dayofweek==dayofweek.thursday and (fastEMA - slowEMA > close*0.001) and close > vwap1 and close[1] > vwap1[1]) or 
       (dayofweek==dayofweek.monday and (fastEMA - slowEMA > close*0.0013) and close > vwap1 and close[1] > vwap1[1]) or 
       (dayofweek==dayofweek.tuesday and (fastEMA - slowEMA > close*0.0013) and close > vwap1 and close[1] > vwap1[1] and not gapup) or
       (dayofweek==dayofweek.wednesday and (fastEMA - slowEMA > close*0.0013) and close > vwap1 and close[1] > vwap1[1] and close-prevDayClose < close*0.0085) or
       (dayofweek==dayofweek.friday and (fastEMA - slowEMA > close*0.0013) and close > vwap1 and close[1] > vwap1[1] and close - todayLow < close*0.012))
       and dayofweek!=dayofweek.friday and (not todayBuyDone or lastTrade != 1) and not NoBuySellTime// and not dailyTaskDone //and (dayofweek==dayofweek.friday or (close-prevDayClose)<150)//and not biggapup


       
sell1=  ((dayofweek==dayofweek.thursday and (slowEMA - fastEMA > close*0.00079) and close < vwap1 and close[1] < vwap1[1]) or 
       (dayofweek==dayofweek.monday and (slowEMA - fastEMA > close*0.00079) and close < vwap1 and close[1] < vwap1[1] and not dragonflyDoji and todayHigh-close < close*0.01 and todayHigh-close[1] < close * 0.01) or 
       (dayofweek==dayofweek.tuesday and (slowEMA - fastEMA > close*0.00079) and close < vwap1 and close[1] < vwap1[1] and not gapdown and not dragonflyDoji and todayHigh-close < close*0.009 and todayHigh-close[1] < close * 0.009) or
       (dayofweek==dayofweek.wednesday and (slowEMA - fastEMA > close*0.00079) and close < vwap1 and close[1] < vwap1[1] and not dragonflyDoji and prevDayClose-close < 0.005*close) or 
       (dayofweek==dayofweek.friday and (slowEMA - fastEMA > close*0.00079) and close < vwap1 and close[1] < vwap1[1] and not dragonflyDoji and prevDayClose-close < 0.005*close)) and 
       dayofweek!=dayofweek.friday and (not todaySellDone or lastTrade != 0) and not NoBuySellTime// and not dailyTaskDone
        
// if buy1 and strategy.openprofit==0
//     ourlabel = label.new(x=bar_index, y=na, text=tostring(fastEMA - slowEMA), yloc=yloc.belowbar)
// if sell1 and strategy.openprofit==0
//     ourlabel = label.new(x=bar_index, y=na, text=tostring(slowEMA - fastEMA), yloc=yloc.belowbar)

// buy =  ((fastEMA > slowEMA and fastEMA[1] < slowEMA[1]) and (fastEMA - slowEMA) > 10) or  ((fastEMA > slowEMA and fastEMA[1] > slowEMA[1] and fastEMA[2] < slowEMA[2]) and (fastEMA - slowEMA) > 20) 
// sell=  ((fastEMA < slowEMA and fastEMA[1] > slowEMA[1] ) and (slowEMA - fastEMA) > 10) or ((fastEMA < slowEMA and fastEMA[1] < slowEMA[1] and fastEMA[2] > slowEMA[2]) and (slowEMA - fastEMA) > 20)

// buy =  (fastEMA > slowEMA and fastEMA[1] < slowEMA[1]) 
// sell=  (fastEMA < slowEMA and fastEMA[1] > slowEMA[1] )


// buy =  ((fastEMA > slowEMA and fastEMA[1] < slowEMA[1]) and (fastEMA - slowEMA) > 10) or  ((fastEMA > slowEMA and fastEMA[1] > slowEMA[1] and fastEMA[2] < slowEMA[2]) and (fastEMA - slowEMA) > 1) 
// sell=  ((fastEMA < slowEMA and fastEMA[1] > slowEMA[1] ) and (slowEMA - fastEMA) > 5)


// buy =  fastEMA > slowEMA and fastEMA[1] > slowEMA[1] and fastEMA[2] < slowEMA[2]
// sell=  fastEMA < slowEMA and fastEMA[1] < slowEMA[1] and fastEMA[2] > slowEMA[2]

//Daily chart
// buyexit = (close + 40 < slowEMA)//rsi > 65 and fastEMA > ema9 // fastEMA > ema9// close < fastEMA//(rsi > 65 and close < fastEMA and fastEMA > ema3 and close > ema200)  //strategy.openprofit < -10000 and slowEMA > ema3 and slowEMA[1] < ema3[1] and 1==2
// sellexit = (close - 40  > slowEMA)//rsi < 35 // and close > ema200) or (rsi < 35 and close < ema200 and fastEMA < ema3) //strategy.openprofit < -10000 and fastEMA < ema3 and fastEMA[1] > ema3[1] and 1==2


// buyexit = (close < superTrend)// and (close < vwap1 and close[1] < vwap1[1] and close < close[1])//and close[2] < vwap1[2]//rsi > 65 and close < fastEMA// fastEMA > ema9// close < fastEMA//(rsi > 65 and close < fastEMA and fastEMA > ema3 and close > ema200)  //strategy.openprofit < -10000 and slowEMA > ema3 and slowEMA[1] < ema3[1] and 1==2
// sellexit = (close > superTrend)// and (close > vwap1 and close[1] > vwap1[1] and close > close[1]) //and close[2] > vwap1[2]//rsi < 35// and close > ema200) or (rsi < 35 and close < ema200 and fastEMA < ema3) //strategy.openprofit < -10000 and fastEMA < ema3 and fastEMA[1] > ema3[1] and 1==2

// buyexit = (close < superTrend and close < vwap1 and close[1] < vwap1[1] and close[1] < superTrend[1]) //or strategy.openprofit > 400 or strategy.openprofit < -5000
// sellexit =  (close > superTrend and close > vwap1 and close[1] > vwap1[1] and close[1] > superTrend[1]) //or strategy.openprofit > 400 or strategy.openprofit < -5000



관련

더 많은