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

MACD 양적 전략과 결합된 삼중 이동 평균

저자:차오장, 날짜: 2024-01-17 16:54:15
태그:

img

전반적인 설명

이 전략은 트리플 이동 평균 지표와 MACD 지표의 사용을 결합하여 비교적 안정적이고 신뢰할 수있는 양적 거래 전략을 개발합니다.

전략 원칙

이 전략은 주로 삼중 이동 평균과 MACD 지표의 조합을 기반으로 합니다.

첫째, 전략은 각각 3, 7 및 2의 길이의 삼배 지수적 이동 평균을 사용합니다.이 세 이동 평균은 미래 트렌드의 방향을 결정하기 위해 빠른에서 느린 이동 평균 시스템을 구성합니다. 단기 이동 평균이 장기 이동 평균을 넘으면 긴 신호입니다. 단기 이동 평균이 장기 이동 평균보다 낮을 때 짧은 신호입니다.

둘째, 전략은 또한 매커드 지표를 3 및 7의 매개 변수와 동시에 사용합니다. 매커드 메인 라인이 신호 라인을 넘을 때, 그것은 긴 신호이며, 아래로 넘을 때, 그것은 짧은 신호입니다.

이중 지표의 사용을 결합함으로써 하나의 지표로 인해 발생하는 여러 가지 잘못된 신호를 피할 수 있으며, 따라서 전략의 안정성을 향상시킬 수 있습니다.

전략 의 장점

  1. 이중 표시기 필터링을 사용하여 신호 품질을 향상
  2. 매개 변수 테스트 및 최적화 여러 번, 안정적이고 신뢰할 수 있습니다
  3. 삼중 이동 평균 체계는 시장 소음을 효과적으로 필터링하고 미래의 추세를 결정할 수 있습니다.
  4. MACD 지표 매개 변수는 단기 기회를 빠르게 포착하기 위해 더 빨리 설정됩니다.

전략 의 위험

  1. 소모와 연속 손실의 위험이 있습니다.
  2. 시장이 명백한 추세를 가지고 있지 않을 때,이 전략에서 더 많은 잘못된 거래가있을 것입니다
  3. MACD 지표는 잘못된 신호를 생성하는 경향이 있으며 이동 평균 지표와 결합되어야합니다.

해결책:

  1. 최대 유출을 제어하기 위해 적절한 스톱 로스 전략을 채택
  2. 시장 상태가 분명하게 트렌드 없는 경우 거래 빈도를 줄이십시오.
  3. MACD 매개 변수를 최적화하고 다른 지표와 결합하여 사용

전략 최적화의 방향

  1. 가장 좋은 조합을 찾기 위해 이동 평균과 MACD의 매개 변수를 테스트하고 최적화하십시오.
  2. 거짓 신호를 피하기 위해 KDJ와 VRSI와 같은 보조 지표를 높여
  3. 시장 상태를 판단하고 동적 조정에 도달하기 위해 기계 학습 모델을 도입
  4. 스톱 로스 전략과 결합하고 최적 스톱 로스 포인트를 설정

요약

이 전략은 이동 평균과 MACD의 조합을 통해 안정적인 트렌드 포착을 달성합니다. 이 전략의 장점은 잘못된 신호를 효과적으로 줄이고 더 나은 전략 성능을 얻을 수있는 지표의 조합 사용에 있습니다. 전략을 더욱 개선하기위한 다음 단계에는 매개 변수 최적화, 스톱 로스 전략, 동적 조정 등을 도입하는 것이 포함되며 중장기 기회를 찾는 효과적인 도구가됩니다.


/*backtest
start: 2023-01-10 00:00:00
end: 2024-01-16 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("Matt's MACD Algo v1", shorttitle="Matt's MACD Algo v1", overlay=true, pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital=7000, calc_on_order_fills = true, commission_type=strategy.commission.percent, commission_value=0, currency = currency.USD)
//study("MFI Fresh", shorttitle="MFI Fresh", overlay=true)

//Risk Management Settings
//trategy.risk.max_drawdown(20, strategy.percent_of_equity)
//strategy.risk.max_intraday_loss(10, strategy.percent_of_equity)
//strategy.risk.max_cons_loss_days(3)

/////////////////
ts = input(title="Trailing Stop in cents", defval=50)/100

//Time Inputs
FromMonth = input(defval = 6, title = "From Month", minval = 1)
FromDay   = input(defval = 1, title = "From Day", minval = 1)
FromYear  = input(defval = 2017, title = "From Year", minval = 1)
ToMonth   = input(defval = 1, title = "To Month", minval = 1)
ToDay     = input(defval = 1, title = "To Day", minval = 1)
ToYear    = input(defval = 9999, title = "To Year", minval = 1) 

//Time Variable
testPeriod() =>
    (time > timestamp(FromYear, FromMonth, FromDay, 09, 30)) and (time < timestamp(ToYear, ToMonth, ToDay, 09, 29))

//MA On and MA Colors On? Inputs
switch1=input(false, title="Enable Bar Color?")
switch2=input(true, title="Enable Moving Averages?")
switch3=input(false, title="Enable Background Color?")
switch4=input(false, title="Enable Bolinger Bands?")
switch5=input(false, title="Enable Keltner Channel?")

////////////////////////////////Williams %R
R_length = input(14, minval=1)
R_overBought = input(title="%R Overbought", defval=80)
R_overSold = input(title="%R Oversold", defval=20)
R_upper = highest(R_length)
R_lower = lowest(R_length)
R_out = 100 * (close - R_upper) / (R_upper - R_lower)

WilliamsR_longEntry = crossover(R_out, R_overSold)
WilliamsR_shortEntry = crossunder(R_out, R_overBought)

//plot(R_out)
//R_band1 = hline(R_overSold)
//R_band0 = hline(R_overBought)
//fill(R_band1, R_band0)

////////////////////////////////RSI Variables
rsi_source = close
RSI_Length = input(title="RSI Length", defval=3)
RSI_overBought = input(title="RSI Overbought", defval=80)
RSI_overSold = input(title="RSI Oversold", defval=20)

up = rma(max(change(rsi_source), 0), RSI_Length)
down = rma(-min(change(rsi_source), 0), RSI_Length)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

RSI_longEntry = rsi > 50
//crossover(rsi, RSI_overSold)
RSI_shortEntry = rsi < 50
//crossunder(rsi, RSI_overBought)

//plot(rsi, color=purple)
//band1 = hline(RSI_overBought)
//band0 = hline(RSI_overSold)
//fill(band1, band0, color=purple, transp=90)


//////////////////////Commodity Channel Index
cci_length = input(20, minval=1)
cci_src = input(close, title="Source")
cci_ma = sma(cci_src, cci_length)
cci = (cci_src - cci_ma) / (0.015 * dev(cci_src, cci_length))


cci_longEntry = crossover(cci, -100)
cci_shortEntry = crossunder(cci, 100)

//plot(cci, color=olive)
//cci_band1 = hline(100, color=gray, linestyle=dashed)
//cci_band0 = hline(-100, color=gray, linestyle=dashed)
//fill(cci_band1, cci_band0, color=olive)



//MFI Inputs
MFI_length = input(title="MFI Length", defval=3)
MFI_overBought = input(title="MFI Overbought", defval=80)
MFI_overSold = input(title="MFI Oversold", defval=20)

//MFI Variables
rawMoneyFlow = hlc3 * volume
positiveMoneyFlow = 0.0
positiveMoneyFlow := hlc3 > hlc3[1] ? positiveMoneyFlow + rawMoneyFlow : positiveMoneyFlow
negativeMoneyFlow = 0.0
negativeMoneyFlow :=  hlc3 < hlc3[1] ? negativeMoneyFlow + rawMoneyFlow : negativeMoneyFlow
moneyFlowRatio = sma(positiveMoneyFlow, MFI_length) / sma(negativeMoneyFlow, MFI_length)
moneyFlowIndex = 100 - 100 / (1 + moneyFlowRatio)

MFI_longEntry = (crossover(moneyFlowIndex, MFI_overSold))
MFI_shortEntry = (crossunder(moneyFlowIndex, MFI_overBought))


///// MFI Plot for STUDY
//plot(moneyFlowIndex, color=#459915)
//MFI_OB=hline(MFI_overBought, title="Overbought", color=#c0c0c0)
//MFI_OS=hline(MFI_overSold, title="Oversold", color=#c0c0c0)
//fill(MFI_overBought, MFI_overSold, color=#9915ff, transp=90)


////VERY SLOW SMA
veryslowLength=input(50,minval=1, title="Very slow SMA")
veryslowSMA = sma(close, veryslowLength)


//MACD Inputs
source = input(close, title="MACD source")
fastLength = input(title="MACD Fast Length", defval=12)
fastLength2 = input(title="MACD Fast Length #2", defval=3)
slowLength = input(title="MACD Slow Length", defval=26)
slowLength2 = input(title="MACD Slow Length #2", defval=7)
MACD_fastsignalSmoothing = input(title="Signal Smoothing", defval=7)
MACD_slowsignalSmoothing = input(title="Signal Smoothing", defval=12)
MACD_fastsignalSmoothing2 = input(title="Signal Smoothing #2", defval=5)
MACD_slowsignalSmoothing2 = input(title="Signal Smoothing #2", defval=9)
MACD_percentthreshold = input(title="MACD % Threshold", defval=-0.0030, step=0.0001)

//MACD variables
fastEMA = ema(source, fastLength)
fastEMA2 = ema(source, fastLength2)
slowEMA = ema(source, slowLength)
slowEMA2 = ema(source, slowLength2)
MACD_Line = fastEMA - slowEMA
MACD_Line2 = fastEMA2 - slowEMA2
MACD_fastsignalLine = ema(MACD_Line, MACD_fastsignalSmoothing)
MACD_slowsignalLine = ema(MACD_Line, MACD_slowsignalSmoothing)
MACD_fastsignalLine2 = ema(MACD_Line2, MACD_fastsignalSmoothing2)
MACD_slowsignalLine2 = ema(MACD_Line2, MACD_slowsignalSmoothing2)
fasthist = MACD_Line - MACD_slowsignalLine
MACD_Histogram2 = MACD_Line2 - MACD_fastsignalLine2
minimum = close * MACD_percentthreshold
SMA = sma(MACD_Line, 10)

// MACD and veryslowSMA Plot for STRATEGY
Fast=plot(switch2?fastEMA:na,color=yellow, linewidth=4)
Slow=plot(switch2?slowEMA:na,color=aqua, linewidth=4)
//VerySlow=plot(switch2?veryslowSMA:na,color=purple,linewidth=4)
//fill(Fast,VerySlow,color=gray)

/////// MACD Plots for STUDY
//plot(fasthist, color=fasthist>0 and fasthist[0]>fasthist[1]?#00ff00:fasthist<=0 and fasthist[0]<fasthist[1]?#f72e2e:fasthist>0 and fasthist[0]<fasthist[1]?#008000:fasthist<0 and fasthist[0]>fasthist[1]?#7f0000:white, style=histogram)
//plot(slowhist, color=slowhist>0 and slowhist[0]>slowhist[1]?#00ff00:slowhist<=0 and slowhist[0]<slowhist[1]?#f72e2e:slowhist>0 and slowhist[0]<slowhist[1]?#008000:slowhist<0 and slowhist[0]>slowhist[1]?#7f0000:white, style=histogram)
//plot(MACD_Line, color=yellow, title="MACD Line")
//plot(MACD_fastsignalSmoothing, color=green, title="Fast Signal Line")
//plot(MACD_slowsignalSmoothing, color=red, title="Slow Signal Line")
//plot(MACD_Line2, color=aqua, title="MACD Line 2")
//plot(MACD_fastsignalSmoothing2, color=orange, title="Fast Signal Line 2")
//plot(MACD_slowsignalSmoothing2, color=white, title="Slow Signal Line 2")
//plot(minimum, color=white, title="% Threshold")
//plot(fasthist, color=fasthist>0 and fasthist[0]>fasthist[1]?#00ff00:fasthist<=0 and fasthist[0]<fasthist[1]?#f72e2e:fasthist>0 and fasthist[0]<fasthist[1]?#008000:fasthist<0 and fasthist[0]>fasthist[1]?#7f0000:white, style=histogram)
//plot(MACD_Histogram2, color=MACD_Histogram2>0?blue:MACD_Histogram2<0?orange:white, style=histogram)
//plot(SMA, color=white, title="SMA")

//MACD Entry Conditions
MACD_longEntry2 = (crossover(MACD_Histogram2, 0))
MACD_shortEntry2 = (crossunder(MACD_Histogram2, 0))
MACD_longEntry = (crossover(fasthist, 0))
MACD_shortEntry = (crossunder(fasthist, 0))



// Colors
//MAtrendcolor = change(veryslowSMA) > 0 ? green : red
//trendcolor = fastEMA > slowEMA and change(veryslowSMA) > 0 and close > slowEMA ? green : fastEMA < slowEMA and change(veryslowSMA) < 0 and close < slowEMA ? red : yellow
//bartrendcolor = close > fastEMA and close > slowEMA and close > veryslowSMA and change(slowEMA) > 0 ? green : close < fastEMA and close < slowEMA and close < veryslowSMA and change(slowEMA) < 0 ? red : yellow
//backgroundcolor = slowEMA > veryslowSMA and MACD_longEntry and MACD_Line > 0 and fastEMA > slowEMA and close[slowLength] > veryslowSMA ? green : slowEMA < veryslowSMA and MACD_shortEntry and MACD_Line < 0 and fastEMA < slowEMA and close[slowLength] < veryslowSMA ? red : na
//barcolor(switch1?bartrendcolor:na)

// Conditional Bar Colors
//backgroundcolor = (MACD_longEntry ? green : MACD_shortEntry ? red : na)
//bgcolor(switch3?backgroundcolor:na,transp=80)





////BOLLINGER BAND Conditions
bb_source = close
bb_length = input(20, minval=1)
bb_mult = input(1.86, minval=0.001, maxval=50)

bb_basis = ema(bb_source, bb_length)
bb_dev = bb_mult * stdev(bb_source, bb_length)

bb_upper = bb_basis + bb_dev
bb_lower = bb_basis - bb_dev

bb_longEntry = crossover(bb_source, bb_lower)
bb_shortEntry = crossunder(bb_source, bb_upper)

plot(switch4?bb_basis:na, color=red, linewidth=4)
p1=plot(switch4?bb_upper:na)
p2=plot(switch4?bb_lower:na)
fill(p1,p2, color=aqua, transp=95)

////KELTNER CHANNEL Inputs/Variables/Plots
KC_useTrueRange = input(true)
KC_length = input(20, minval=1)
KC_mult = input(3.0)
KC_source = input(close, title="Source")

KC_ma = ema(KC_source, KC_length)
KC_range = KC_useTrueRange ? tr : high - low
KC_rangema = ema(KC_range, KC_length)
KC_upper = KC_ma + KC_rangema * KC_mult
KC_lower = KC_ma - KC_rangema * KC_mult

KC_longEntry = crossover(KC_source, KC_lower)
KC_shortEntry = crossunder(KC_source, KC_upper)

plot(switch5?KC_ma:na, color=red, title="Basis")
KC_u = plot(switch5?KC_upper:na, color=red, title="Upper")
KC_l = plot(switch5?KC_lower:na, color=red, title="Lower")
fill(KC_u, KC_l, color=red)

///////////////////ADX
//len = input(title="ADX Length", type=integer, defval=14)
//th = input(title="ADX threshold", type=integer, defval=20)

//TrueRange = max(max(high-low, abs(high-nz(close[1]))), abs(low-nz(close[1])))
//DirectionalMovementPlus = high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
//DirectionalMovementMinus = nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0


//SmoothedTrueRange = nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1])/len) + TrueRange
//SmoothedDirectionalMovementPlus = nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1])/len) + DirectionalMovementPlus
//SmoothedDirectionalMovementMinus = nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1])/len) + DirectionalMovementMinus

//DIPlus = sma(SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100, len)
//DIMinus = sma(SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100, len)
//DX = abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100
//ADX = sma(DX, len)


///
//ADX_longEntry = crossover(DIPlus, DIMinus) //or (DIPlus > DIMinus and DIPlus > th and ADX > th)
//ADX_shortEntry = crossover(DIMinus, DIPlus) //or (DIMinus > DIPlus and DIMinus > th and ADX > th)


//DI_long = if DIPlus > DIMinus and ADX > 20 and DIPlus > 20
    
    

//plot(DIPlus, color=green, title="DI+")
//plot(DIMinus, color=red, title="DI-")
//plot(ADX, color=black, title="ADX")
//hline(th, color=black, linestyle=dashed)




//////////////////////////////////Playing with RES


r1 = input("5", "Resolution")
r2 = input("15", "Resolution")
r3 = input("30", "Resolution")
r4 = input("60", "Resolution")

o1 = request.security(heikinashi(syminfo.tickerid), r1, MACD_Line[1])
c1 = request.security(heikinashi(syminfo.tickerid), r1, MACD_slowsignalLine[1])
o2 = request.security(heikinashi(syminfo.tickerid), r2, MACD_Line[1])
c2 = request.security(heikinashi(syminfo.tickerid), r2, MACD_slowsignalLine[1])
o3 = request.security(heikinashi(syminfo.tickerid), r3, MACD_Line[1])
c3 = request.security(heikinashi(syminfo.tickerid), r3, MACD_slowsignalLine[1])
o4 = request.security(heikinashi(syminfo.tickerid), r4, MACD_Line[1])
c4 = request.security(heikinashi(syminfo.tickerid), r4, MACD_slowsignalLine[1])

res_long = (o4 > c4 and o3 > c3 and o2 > c2 and o1 > c1)
res_short = (o4 < c4 and o3 < c3 and o2 < c2 and o1 < c1)

///////////////////// Parabolic SAR (stop and reverse)
start = input(0.02)
increment = input(0.02)
maximum = input(0.2)

psar = sar(start, increment, maximum)
plot(psar, style=circles, color=yellow)

psar_longEntry = close > psar
psar_longExit = crossunder(close, psar)
psar_shortEntry = close < psar//crossunder(close, psar)
psar_shortExit = crossover(close, psar)

mix = (moneyFlowIndex + rsi)/2
RSI_MFI = ema(mix, input(3))
//color = RSI_MFI > 80 ? red :RSI_MFI < 20  ? green : silver
vrsi = RSI_MFI

rsiBuySell = vrsi[1] < 95 and crossover(vrsi, 95) or vrsi[1] < 90 and crossover(vrsi, 90) or vrsi[1] < 85 and crossover(vrsi, 85) or vrsi[1] < 80 and crossover(vrsi, 80)  or vrsi[1] < 75 and crossover(vrsi, 75) or vrsi[1] < 70 and  crossover(vrsi, 70)  or vrsi[1] < 65 and crossover(vrsi, 65) or vrsi[1] < 60 and  crossover(vrsi, 60)  or vrsi[1] < 55 and crossover(vrsi, 55) or vrsi[1] < 50 and crossover(vrsi, 50) or vrsi[1] < 45 and crossover(vrsi, 45) or vrsi[1] < 40 and  crossover(vrsi, 40) or vrsi[1] < 35 and crossover(vrsi, 35) or vrsi[1] < 30 and crossover(vrsi, 30) or vrsi[1] < 25 and crossover(vrsi, 25) or vrsi[1] < 20 and  crossover(vrsi, 20) or vrsi[1] < 15 and crossover(vrsi, 15) or  vrsi[1] < 10 and crossover(vrsi, 10) or  vrsi[1] < 5 and crossover(vrsi, 5)  ? 1 :  vrsi[1] > 95 and  crossunder(vrsi, 95) or vrsi[1] > 90 and  crossunder(vrsi, 90) or  vrsi[1] > 85 and  crossunder(vrsi, 85) or vrsi[1] > 80 and crossunder(vrsi, 80) or  vrsi[1] > 75 and  crossunder(vrsi, 75) or vrsi[1] > 70 and  crossunder(vrsi, 70) or  vrsi[1] > 65 and  crossunder(vrsi, 65) or vrsi[1] > 60 and crossunder(vrsi, 60) or  vrsi[1] > 55 and  crossunder(vrsi, 55) or vrsi[1] > 50 and crossunder(vrsi, 50) or  vrsi[1] > 45 and  crossunder(vrsi, 45) or vrsi[1] > 40 and crossunder(vrsi, 40) or  vrsi[1] > 35 and  crossunder(vrsi, 35) or vrsi[1] > 30 and crossunder(vrsi, 30) or  vrsi[1] > 25 and  crossunder(vrsi, 25) or vrsi[1] > 20 and  crossunder(vrsi, 20) or vrsi[1] > 15 and crossunder(vrsi, 15) or vrsi[1] > 10 and crossunder(vrsi, 10) or  vrsi[1] > 5 and  crossunder(vrsi, 5) ?-1:na 

//////////////////////////////////Entry Conditions
//
MA1 = ema(hlc3, input(3))
MA2 = wma(MA1, input(7))
MA3 = ema(MA2, input(2))
MA4 = wma(MA3, input(1))

buy =  close > MA4 or hlc3[1] < MA4 and hlc3 > MA4 and rsiBuySell == 1
sell = close < MA4 or hlc3[1] > MA4 and hlc3 < MA4 and rsiBuySell == -1

p=14

CO=close-open
HL=high-low

value1 = (CO + 2*CO[1] + 2*CO[2] + CO[3])/6
value2 = (HL + 2*HL[1] + 2*HL[2] + HL[3])/6

num=sum(value1,p)
denom=sum(value2,p)

RVI=denom!=0?num/denom:0

RVIsig=(RVI+ 2*RVI[1] + 2*RVI[2] + RVI[3])/6

//plot(RVI,color=white,style=line,linewidth=1)
//plot(RVIsig,color=orange,style=line,linewidth=1)

Tenkan_periods = input(9, minval=1, title="Conversion Line Periods"),
Kijun_periods = input(26, minval=1, title="Base Line Periods")
Senkou_Span_B_Length = input(50, minval=1, title="Lagging Span 2 Periods"),
Chikou_Span_Length = input(25, minval=1, title="Displacement")

donchian(len) => avg(lowest(len), highest(len))

Tenkan_sen = donchian(Tenkan_periods)
Kijun_sen = donchian(Kijun_periods)
Senkou_Span_A = avg(Tenkan_sen, Kijun_sen)
Senkou_Span_B = donchian(Senkou_Span_B_Length)

plot(Tenkan_sen, color=#0496ff, title="Conversion Line")
plot(Kijun_sen, color=#991515, title="Base Line")
plot(close, offset = -Chikou_Span_Length, color=#459915, title="Lagging Span")

p3 = plot(Senkou_Span_A, offset = Chikou_Span_Length, color=green,
 title="Lead 1")
p4 = plot(Senkou_Span_B, offset = Chikou_Span_Length, color=red, 
 title="Lead 2")
fill(p3, p4, color = Senkou_Span_A > Senkou_Span_B ? green : red, transp=50)

Ichimoku_longEntry = Senkou_Span_B < Senkou_Span_A
Ichimoku_shortEntry = Senkou_Span_A < Senkou_Span_B

len9 = input(9, minval=1, title="Length")
srce = input(hlc3, title="Source")
ema9 = ema(srce, len9)
sma50 = sma(ema9, 80)
sma30 = vwma(sma50, 26)
ema930 = ema(sma30, 9)
//plot(ema930, color=blue, title="MA", linewidth=5, transp=0)

SMA100 = sma(input(ohlc4), input(10))
Lookback = SMA100[input(7)]
sma300 = SMA100 + (SMA100 - Lookback)



//if Ichimoku_longEntry
longEntry = (MACD_longEntry2) //or Stoch_longEntry// or buy //or cci_longEntry  or bb_longEntry or psar_shortExit //or  //// // KC_longEntry// or WilliamsR_longEntry//  // // or RSI_longEntry// // or  or MFI_longEntry// or crossover(close,psar) //(o4 < c4 and o3 < c3 and o2 < c2 and o1 < c1)

//if Ichimoku_shortEntry
shortEntry = (MACD_shortEntry2) //or Stoch_shortEntry// or sell//or cci_shortEntry or bb_shortEntry or psar_longExit//   // //or KC_shortEntry// or WilliamsR_shortEntry//  //or cci_shortEntry //  // or  or MFI_shortEntry// or crossunder(close,psar)// (o4 < c4 and o3 < c3 and o2 < c2 and o1 < c1)



//longExit = shortEntry or psar_longExit // if not (ADX > th and )
//shortExit = longEntry or psar_shortExit // if not (ADX > th and )

////psar for trailing stops or some other measure? we must have a good trailing stop.

///////////////////////////////Strategy Execution

if testPeriod()
    strategy.entry("Long", strategy.long, when=longEntry)
    strategy.close("Long", when=shortEntry)

//if testPeriod()
//    strategy.entry("Long", strategy.long, when=longEntry)
//    strategy.exit("Exit Long", "Long", when=shortEntry)
//else
//    strategy.cancel("Long")
//if testPeriod()
//    strategy.entry("Short", strategy.short, when=shortEntry)
//    strategy.exit("Exit Short", "Short", when=longEntry)
//else
//    strategy.cancel("Long")

//Other Plots and Alerts
plotshape(MACD_longEntry2,  title= "3,7 Long Open", color=green, style=shape.circle)
plotshape(MACD_shortEntry2,  title= "3,7 Short Open", color=red, style=shape.circle)
//plotshape(Stoch_longEntry,  title= "Stoch Long Open", color=aqua, style=shape.circle)
//plotshape(Stoch_shortEntry,  title= "Stoch Short Open", color=orange, style=shape.circle)
//plotshape(buy,  title= "RES Long Open", color=green, location=location.belowbar, style=shape.circle)
///plotshape(sell,  title= "RES Short Open", color=red, location=location.belowbar, style=shape.circle)
//plotshape(MACD_longEntry, title= "12,26 Long Open", color=green, style=shape.arrowup, size=size.normal, location=location.belowbar)
//plotshape(MACD_shortEntry, title= "12,26 Short Open", color=red, style=shape.arrowdown, size=size.normal, location=location.abovebar)
//plotshape(MACD_longEntry, title= "12,26 Long Open", color=green, style=shape.diamond, size=size.tiny, location=location.belowbar)
//plotshape(MACD_shortEntry, title= "12,26 Short Open", color=red, style=shape.diamond, size=size.tiny, location=location.abovebar)

//plotchar(longCondition, location=bottom char="L", color=green)
//plotchar(shortCondition, char="S", color=red)
//alertcondition(longCondition, title="MFI+MACD Long", message="(MFI crossOver 30) or MACD+")
//alertcondition(shortCondition, title="MFI+MACD Short", message="(MFI crossUnder 70) or MACD-")
plot(sma300, color=purple, linewidth=4)

더 많은