가격 행동 전략

저자:차오장, 날짜: 2023-09-19 11:17:07
태그:

전반적인 설명

이것은 가격 액션에 기반한 거래 전략이며, 동향을 식별하고 진입에 대한 가격 패턴을 사용하는 이동 평균과 결합됩니다.

전략 원칙

이 전략은 주로 다음과 같은 측면에 기반합니다.

  1. 트렌드를 판단하기 위해 EMA를 이용합니다. 89 기간 EMA와 Hull MA가 모두 빨간색이라면, 곰 트렌드로 판단되며 단축됩니다. 둘 다 녹색일 때, 황소 트렌드로 판단되며 단축됩니다. 하나 녹색이고 하나 빨간색일 때, 통합으로 판단됩니다. 길고 짧게 모두 가능합니다.

  2. 가격 패턴을 가진 신호를 식별. 전략은 단일 촛불, 가짜 패턴, 내부 바 등과 같은 다양한 촛불 조합을 인식하여 잠재적 진입 지점을 발견합니다.

  3. 진입을 위한 주요 지지/저항 수준과 결합합니다. 이 전략은 또한 가격 패턴 신호를 추가로 확인하고 잘못된 브레이크를 피하기 위해 주요 S/R 수준을 포함합니다.

  4. MACD는 확인으로 사용된다. MACD 히스토그램 색상은 가격 패턴 신호를 확인하고 확률을 향상시키기 위해 사용됩니다.

  5. 트렌드 추적 메커니즘. 전략은 트렌드 추적 모듈을 포함하여 트렌드 반전을 더 정확하게 감지하고 정상과 바닥을 쫓는 것을 피합니다.

  6. 스톱 로스 및 수익을 설정합니다. ATR에 기반한 고정 스톱 로스 및 수익을 취하는 것은 위험/이익 관리에 포함됩니다.

이점 분석

이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 가격 행동에 기반하고, 지표에 영향을 받지 않습니다. 복잡한 지표 없이 순수한 가격에 기반하고, 시장 성격에 가깝습니다.

  2. 트렌드를 결합하고 추격하는 것을 피합니다. EMA와 Hull MA는 트렌드 방향을 파악하고 트렌드를 따라 작동하며 트렌드 반대 거래를 피합니다.

  3. 패턴 + 지표는 확률을 향상시킵니다. MACD와 결합된 가격 패턴은 신호를 확인하고 잘못된 신호를 필터하여 수익성을 향상시킵니다.

  4. 트렌드를 따르는 모듈은 더 큰 수익 잠재력을 가진 더 큰 시간 프레임 트렌드를 포착합니다.

  5. 스톱 로스/트랙 이윤은 리스크를 제어합니다. 고정 스톱 로스/트랙 이윤 비율은 리스크/리벌을 관리하는 데 도움이 됩니다.

위험 분석

이 전략은 또한 다음과 같은 위험을 가지고 있습니다.

  1. 더 큰 시간 프레임 트렌드 반전 위험. 전략은 명확한 중장기 / 단기 트렌드에서 가장 잘 작동합니다. 더 큰 반전 위험이 중단됩니다. 더 큰 시간 프레임 분석은 피하는 데 도움이 될 수 있습니다.

  2. 가격 패턴 실패 위험. 가격 패턴은 다른 시장 환경에서 다른 효과를 가지고 있습니다. 일부 시장은 패턴이 실패하여 손실로 이어질 수 있습니다. 다양한 시장을 백테스트하면 패턴 선택을 최적화 할 수 있습니다.

  3. 매개 변수 최적화 어려움. 전략에는 여러 매개 변수가 있습니다. 다른 조합은 결과에 크게 영향을 미칩니다. 최적 매개 변수를 찾기 위해 광범위한 백테스팅이 필요합니다. 정적 설정은 시장 정권 변화의 위험을 초래합니다. 동적 매개 변수 최적화 메커니즘은 이를 해결하는 데 도움이 될 수 있습니다.

  4. 개별 거래 위험을 제어 할 수 없습니다. 고정 스톱 손실 / 수익을 취하는 것은 각 거래의 변동에 적응하고 개별 거래 위험 / 보상 비율을 관리 할 수 없습니다. 동적 스톱 손실 알고리즘 또는 위험 관리 모듈이 도움이 될 수 있습니다.

최적화 방향

이 전략은 다음과 같은 측면에서 개선될 수 있습니다.

  1. 더 복잡한 패턴 인식을 위해 기계 학습을 도입합니다. 더 효과적인 패턴을 자동으로 탐지하기 위해 딥 러닝 등을 사용합니다.

  2. 적응력을 높이고 동적 매개 변수 최적화 메커니즘을 구축하여 전략은 정적 설정보다는 실시간 시장 조건에 따라 조정할 수 있습니다.

  3. 신호를 확인하기 위해 더 많은 요소를 포함합니다. 신호를 확인하고 함락 될 위험을 줄이기 위해 볼륨, 하루 간 간격 등과 같은 더 많은 가격 행동 요소를 추가하십시오.

  4. 리스크 관리 및 포지션 크기를 도입합니다. 한 거래 중지 손실을 효과적으로 제어하고 리스크 / 보상 비율을 최적화하기 위해 임계 기준에 따라 자동으로 포지션 크기를 조정합니다.

  5. 입력 메커니즘을 최적화합니다. 트렌드 / 통합 리듬을 더 정확하게 식별하기 위해 트렌드 탐지 모듈을 정제하여 입력 정확도를 향상시킵니다.

결론

전체적으로, 이 전략의 핵심 강점은 가격 행동 기반 판단, 지표에 대한 의존성을 피하고 시장의 성격을 최대한 반영하는 데 있다. 트렌드와 지표를 결합하면 수익성이 향상되며 스톱 로스/익스피스 리스크를 제어한다. 그러나 더 큰 시간 프레임 트렌드 역전, 가격 패턴 실패와 같은 위험은 해결되어야 한다. 미래 개선은 머신 러닝, 동적 매개 변수 최적화, 리스크 관리 모듈 등을 통해 전략이 더 견고하게 될 수 있다.


/*backtest
start: 2023-08-19 00:00:00
end: 2023-09-18 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
args: [["v_input_1",true]]
*/

//@version=2
// strategy(title="Price Action", shorttitle="Price Action", overlay=true,default_qty_value=2000,initial_capital=1000,currency=currency.USD, pyramiding=1,calc_on_every_tick=true)
// EMA //
HiLoLen = 34
pacL = ema(low,HiLoLen)
pacC = ema(close,HiLoLen)
pacH = ema(high,HiLoLen)
signalMA = ema(close,89)
col1=pacC>signalMA?lime:pacC<signalMA?red:yellow
plot(signalMA, color=col1, title="SignalMA")
// Plot the Price Action Channel (PAC) base on EMA high,low and close//
//L=plot(pacL, color=yellow, linewidth=1, title="High PAC EMA",transp=0)
//C=plot(pacC, color=yellow, style = line, linewidth=1, title="Close PAC EMA",transp=0)
//H=plot(pacH, color=yellow, linewidth=1, title="Low PAC EMA",transp=0)
// HullMA //
n=89
//
n2ma=2*wma(close,round(n/2))
nma=wma(close,n)
diff=n2ma-nma
sqn=round(sqrt(n))
//
n2ma1=2*wma(close[1],round(n/2))
nma1=wma(close[1],n)
diff1=n2ma1-nma1
sqn1=round(sqrt(n))
//
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
condDown = n2 >= n1
condUp = condDown != true
col =condUp ? lime : condDown ? red : yellow
plot(n1,title="Hull MA", color=col,linewidth=1)
// Macd Barcolor
fastlength = 12
slowlength = 26
MACDLength = 9
MACD = ema(close, fastlength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
delta = MACD - aMACD
hisup= iff(delta>delta[1] and delta>0, 1,iff(delta<delta[1], -1, nz(hisup[1], 0)))
hisdown = iff(delta<delta[1] and delta<0, 1,iff(delta>delta[1], -1, nz(hisdown[1], 0)))
//Swing high low// 
ktswinghigh=(high<=high[2] and high[1]<=high[2] and high[3]<=high[2] and high[4]<=high[2])// and high<high[1] and high[4]<high[3]) or (high<high[1] and high[1]<high[2] and high[4]<high[2] and high[5]<high[2] and high[3]<high[2]) 
ktswinghigh3=(high<high[1] and high[1]<high[3] and high[5]<high[3] and high[6]<high[5]and high[2]<high[3] and high[4]<high[3]) or(high<high[3] and high[2]<high[3] and high[1]<high[3] and high[4]<high[3] and high[5]<high[4])
sh=ktswinghigh?high[2]:na
swinghigh = fixnan(sh)
colorsh=swinghigh==swinghigh[1]?white:na
plot(swinghigh,color=colorsh,title="Swing High",style=line,offset=-2)

ktswinglow=(low>=low[2] and low[1]>=low[2] and low[3]>=low[2] and low[4]>=low[2])// and low>low[1] and low[4]>low[3]) or (low>low[1] and low[1]>low[2] and low[4]>low[2] and low[5]>low[2] and low[3]>low[2])
ktswinglow3=low>low[1] and low[1]>low[3] and low[5]>low[3] and low[6]>low[5]  and low[2]>low[3] and low[4]>low[3] or (low>low[3] and low[1]>low[3] and low[2]>low[3] and low[4]>low[3] and low[5]>low[4])
sl=ktswinglow?low[2]:na
swinglow = fixnan(sl)
colorsl=swinglow==swinglow[1]?white:na
plot(swinglow,title="Swing Low",color=colorsl,style=line,offset=-2)

// Pinbar FailBreak
ema21=ema(close,13)
beariskpinbar= (close-open<(high-low)/3 and open-close<(high-low)/3)  and ((high>swinghigh and high>high[1] and high>high[2] and high>high[3] and close<swinghigh))// or ((open[2]<ema21[2] or close[2]<ema21[2]) and high>ema21 and low[2]<low[1] and low[3]<low[2] and high>high[1] and high>high[2] and high>high[3]))
bullishpibar=(close-open<(high-low)/3 and open-close<(high-low)/3)  and ((low<swinglow and low<low[1] and low<low[2] and low<low[3] and close>swinglow))// or ((open[2]>ema21[2] or close[2]>ema21[2]) and low<ema21 and high[2]>high[1] and high[3]>high[2] and low<low[1] and low<low[2] and low<low[3]))

//
Inside(position) => high <= high[position] and low >= low[position]
outsidebar = (high >= high[1] and low <= low[1])
barcolor((high <= high[1] and low >= low[1]) ? white : na)
barcolor(hisup==1 and MACD>0 ? lime: hisdown==1 and MACD<0 ? red : hisup==-1 and MACD>0  ? green: orange )
barcolor(bullishpibar or beariskpinbar ?white:na)
secLast = 1
fakey = (high[1] <= high[2] and low[1] >= low[2] and high > high[2] and close >= low[2] and close < high[2]) or (high[2]<=high[3] and low[2]>=low[3] and high[1]>high[2] and close<high[2] and close>low[3] and high-close>0.75*(high-low))// ? red : na
fakey1 = (high[1] <= high[2] and low[1] >= low[2] and low < low[2] and close > low[2] and close <= high[1]) or (high[2]<=high[3] and low[2]>=low[3] and low[1]<low[2] and close>low[2] and close<high[3] and close-low>0.75*(high-low)) //? lime : na
barcolor(fakey or fakey1?white:na)
//plotshape(beariskpinbar and (not fakey or (fakey and outsidebar)) , title= "Pinbar Bearisk", location=location.abovebar, color=white, style=shape.arrowdown, text="Pinbar",size=size.tiny)
//plotshape(bullishpibar  and (not fakey1 or (fakey1 and outsidebar)), title= "Pinbar Bullish", location=location.belowbar, color=white, style=shape.arrowup, text="Pinbar",size=size.tiny)

//insidebar= Inside(secLast)? #FF9800: na
onewhitesoliderbear=  close<open and high[1]-close>0.5*(high[1]-low[1]) and (open-close)>2/3*(high-low) and (high[1]>ema21[1] or high>ema21) and open[1]<ema21[1] and close-low<(high-close)*0.3 and (open[2]<ema21[2] or close[2]<ema21[2]) and close<ema21 and low[2]<low[1] and low[3]<low[2]
onewwhitesoliderbull=  close>open and close-low[1]>0.5*(high[1]-low[1]) and (close-open)>2/3*(high-low) and (low[1]<ema21[1] or low<ema21) and open[1]>ema21[1] and high-close<(close-low)*0.3  and (open[2]>ema21[2] or close[2]>ema21[2]) and close>ema21 and high[2]>high[1] and high[3]>high[2]
onewhitesoliderbear1=  close<open and high[1]-close>0.5*(high[1]-low[1]) and (open-close)>2/3*(high-low) and (high[1]>pacC[1] or high>pacC) and open[1]<pacC[1] and close-low<(high-close)*0.3 and (open[2]<pacC[2] or close[2]<pacC[2]) and close<pacC and low[2]<low[1] and low[3]<low[2]
onewwhitesoliderbull1=  close>open and close-low[1]>0.5*(high[1]-low[1]) and (close-open)>2/3*(high-low) and (low[1]<pacC[1] or low<pacC) and open[1]>pacC[1] and high-close<(close-low)*0.3  and (open[2]>pacC[2] or close[2]>pacC[2]) and close>pacC and high[2]>high[1] and high[3]>high[2]
onewhitesoliderbear2=  close<open and high[1]-close>0.5*(high[1]-low[1]) and (open-close)>2/3*(high-low) and (high[1]>signalMA[1] or high>signalMA) and open[1]<signalMA[1] and close-low<(high-close)*0.3 and (open[2]<signalMA[2] or close[2]<signalMA[2]) and close<signalMA and low[2]<low[1] and low[3]<low[2]
onewwhitesoliderbull2=  close>open and close-low[1]>0.5*(high[1]-low[1]) and (close-open)>2/3*(high-low) and (low[1]<signalMA[1] or low<signalMA) and open[1]>signalMA[1] and high-close<(close-low)*0.3  and (open[2]>signalMA[2] or close[2]>signalMA[2]) and close>signalMA and high[2]>high[1] and high[3]>high[2]

//plotshape(beariskpinbar and (not fakey or (fakey and outsidebar)) and not onewhitesoliderbear and not onewwhitesoliderbull, title= "Pinbar Bearisk", location=location.abovebar, color=white, style=shape.arrowdown, text="Pinbar",size=size.tiny)
//plotshape(bullishpibar  and (not fakey1 or (fakey1 and outsidebar)) and not onewwhitesoliderbull and not onewhitesoliderbear, title= "Pinbar Bullish", location=location.belowbar, color=white, style=shape.arrowup, text="Pinbar",size=size.tiny)

//

//pinbar=(open>ema21 and low<ema21 and close-low>2*(high-close)) or (open[1]>ema21[1] and low[1]<ema21[1] and (close-low[1]>2*(high[1]-close) or close-low>2*(high[1]-close)))? green:na
//pinbar2=(open<ema21 and high>ema21 and high-close>2*(close-low)) or (open[1]<ema21[1] and high[1]>ema21[1] and (high[1]-close>2*(close-low[1]) or high-close>2*(close-low[1])))?orange:na
//plot(ema21)
//bgcolor(insidebar, transp=70)
//bgcolor(fakey, transp=80)
//bgcolor(fakey1, transp=80)
//bgcolor(pinbar, transp=70)
//bgcolor(pinbar2, transp=70)

insidebar = ((high[1] <= high[2] and low[1] >= low[2]) and not(outsidebar))
barcolor(outsidebar and high[1]<=high[2] and low[1]>=low[2]?white:na)
bearishibbf=( insidebar and (high > high[1] and close < high[1]))
//barcolor( bearishibbf ? white : na, 0, true, "Bearish Inside Bar Breakout Failure")
//plotshape(bearishibbf and not fakey, title= "Bearish Inside Bar Breakout Failure", location=location.abovebar, color=white, style=shape.arrowdown, text="InsideBar\nFailBreak",size=size.tiny)

bullishibbf=(insidebar and (low < low[1] and close > low[1]))
//barcolor( bullishibbf ? white : na, 0, true, "Bullish Inside Bar Breakout Failure")
//plotshape(bullishibbf and not fakey1, title= "Bullish Inside Bar Breakout Failure", location=location.belowbar, color=white, style=shape.arrowup, text="InsideBar\nFailBreak",size=size.tiny)
//
barcolor((onewwhitesoliderbull or onewhitesoliderbear) and not insidebar?white:na)
//

// Outsidebar follow Insidebar
///plotshape(outsidebar and ((high[1]<=high[2] and low[1]>=low[2] ) ) and close<ema21 and not beariskpinbar and not bullishpibar, title= "OutsideBar Break InsideBar", location=location.abovebar, color=white, style=shape.arrowdown, text="Outside\nBar",size=size.tiny)
//plotshape(outsidebar and ((high[1]<=high[2] and low[1]>=low[2]) ) and close>ema21 and not beariskpinbar and not bullishpibar, title= "OutsideBar Break InsideBar", location=location.belowbar, color=white, style=shape.arrowup, text="Outside\nBar",size=size.tiny)
//
whitesoldierreversal= ((low[1]<low[2] and low[2]<low[3]) or (high[1]<high[2] and high[2]<high[3])) and low[3]<low[8] and low[8]<ema21[8] and high[2]<ema21[2] and high[1]<ema21[1]  and high[3]<ema21[3] and close-low[1]>(high[1]-close) and (open<close[1] or open<open[1]) and close-open>0.3*(high-low) and high-close<0.5*(close-open)
blackcrowreversal= ((high[1]>high[2] and high[2]>high[3]) or (low[1]>low[2] and low[2]>low[3])) and high[3]>high[8] and high[8]>ema21[8] and low[2]>ema21[2] and low[1]>ema21[1] and low[3]>ema21[3] and close-low[1]<(high[1]-close) and (open>close[1] or open>open[1]) and open-close>0.3*(high-low) and close-low<0.5*(open-close)
// Black Crow and White Soldier Reversal
//plotshape(whitesoldierreversal, title= "Piercing Pattern", location=location.belowbar, color=white, style=shape.arrowup, text="Piercing",size=size.tiny)
//plotshape(blackcrowreversal, title= "Dark Cloud Cover", location=location.abovebar, color=white, style=shape.arrowdown, text="Dark\nCloud",size=size.tiny)
barcolor(blackcrowreversal or whitesoldierreversal?white:na)
//
pinbarreversalbull= ((low[1]<low[2] and low[2]<low[3]) or (high[1]<high[2] and high[2]<high[3])) and low[3]<low[8] and low[8]<ema21[8] and high[2]<ema21[2] and high[1]<ema21[1]  and high[3]<ema21[3] and close-open<(high-low)/3 and open-close<(high-low)/3 and high-close<close-low and low<low[1]
pinbarreversalbear= ((high[1]>high[2] and high[2]>high[3])or (low[1]>low[2] and low[2]>low[3])) and high[3]>high[8] and high[8]>ema21[8] and low[2]>ema21[2] and low[1]>ema21[1] and low[3]>ema21[3] and close-open<(high-low)/3 and open-close<(high-low)/3 and high-close>close-low and high>high[1]
// Pinbar Reversal
//plotshape(pinbarreversalbull and not whitesoldierreversal and not fakey1 and not blackcrowreversal and not whitesoldierreversal and not bullishpibar, title= "Bullish Pinbar Reversal", location=location.belowbar, color=white, style=shape.arrowup, text="Pinbar",size=size.tiny)
//plotshape(pinbarreversalbear and not blackcrowreversal and not fakey and not whitesoldierreversal and not blackcrowreversal and not beariskpinbar, title= "Bearisk Pinbar Reversal", location=location.abovebar, color=white, style=shape.arrowdown, text="Pinbar",size=size.tiny)
barcolor(pinbarreversalbear or pinbarreversalbull?white:na)
// Fakey
plotshape(fakey and (not outsidebar or not (high[1]<=high[2] and low[1]>=low[2]) )  and not blackcrowreversal   , title= "Fakey Bearisk", location=location.abovebar, color=white, style=shape.arrowdown, text="Fakey",size=size.tiny)
plotshape(fakey1 and (not outsidebar or not (high[1]<=high[2] and low[1]>=low[2]) )  and not whitesoldierreversal , title= "Fakey Bullish", location=location.belowbar, color=white, style=shape.arrowup, text="Fakey",size=size.tiny)
// Pinbar Fake Breakout
//plotshape(beariskpinbar and (not fakey or (fakey and outsidebar)) and not onewhitesoliderbear and not onewwhitesoliderbull and not blackcrowreversal and not whitesoldierreversal and not fakey, title= "Pinbar Bearisk", location=location.abovebar, color=white, style=shape.arrowdown, text="FalseBreak\nPinbar",size=size.tiny)
//plotshape(bullishpibar  and (not fakey1 or (fakey1 and outsidebar)) and not onewwhitesoliderbull and not onewhitesoliderbear and not whitesoldierreversal and not blackcrowreversal and not fakey1, title= "Pinbar Bullish", location=location.belowbar, color=white, style=shape.arrowup, text="FalseBreak\nPinbar",size=size.tiny)
// Black Crow and White Soldier Continuation
//plotshape((onewhitesoliderbear or onewhitesoliderbear1 or onewhitesoliderbear2) and not insidebar and not fakey and not fakey1  and not outsidebar, title= "One solider Bearisk", location=location.abovebar, color=white, style=shape.arrowdown, text="Black\nCrow",size=size.tiny)
//plotshape((onewwhitesoliderbull or onewwhitesoliderbull1 or onewwhitesoliderbull2)and not insidebar and not fakey and not fakey1  and not outsidebar, title= "One solider Bullish", location=location.belowbar, color=white, style=shape.arrowup, text="White\nSoldier",size=size.tiny)
// Pinbar Continuation
pinbarresistance= (close-open<(high-low)/3 and open-close<(high-low)/3) and high-close>(close-low) and high-open>(open-low) and  ((open[2]<ema21[2] or close[2]<ema21[2]) and high>ema21 and low[2]<low[1] and low[3]<low[2] and high>high[1] and high>high[2] and high>high[3])
pinbarsupport=(close-open<(high-low)/3 and open-close<(high-low)/3) and close-low>(high-close) and open-low>(high-open) and ((open[2]>ema21[2] or close[2]>ema21[2]) and low<ema21 and high[2]>high[1] and high[3]>high[2] and low<low[1] and low<low[2] and low<low[3])
//plotshape(pinbarresistance and (not fakey or (fakey and outsidebar)) and not onewhitesoliderbear and not onewwhitesoliderbull and not blackcrowreversal and not whitesoldierreversal and not fakey and not beariskpinbar, title= "Pinbar Bearisk", location=location.abovebar, color=white, style=shape.arrowdown, text="Pinbar",size=size.tiny)
//plotshape(pinbarsupport  and (not fakey1 or (fakey1 and outsidebar)) and not onewwhitesoliderbull and not onewhitesoliderbear and not whitesoldierreversal and not blackcrowreversal and not fakey1 and not bullishpibar, title= "Pinbar Bullish", location=location.belowbar, color=white, style=shape.arrowup, text="Pinbar",size=size.tiny)
// barcolor

onlybuy=input(false)
onlysell=input(false)//
conmua= hisup==1 and MACD>0?1: (hisdown[1]==1 and MACD[1]<0 and pacC[1]>signalMA[1]) or (n1[2]<n1[3] and pacC[1]>signalMA[1])?-1:nz(conmua[1],1)
conmua1= conmua==1 and (hisdown==1 and MACD<0 and pacC>signalMA) or (n1[1]<n1[2] and pacC>signalMA)?1:(close[1]>n1[1] and pacC[1]>signalMA[1] and open[1]<n1[1] and close[1]>pacC[1]) or crossunder(pacC,signalMA) ?-1:nz(conmua1[1],1)
conmua2=conmua1==1 and hisup==1 and MACD>0 and close>n1?1: high[1]<high[3] and high[2]<high[3]?-1:nz(conmua2[1],1)
conmua3=conmua2==1 and high<high[2] and high[1]<high[2]?1: (close[1]>swinghigh[1] and hisup[1]==1 and MACD[1]>0) or ( MACD<0)?-1:nz(conmua3[1],1)
mua=conmua3==1 and hisup==1 and MACD>0 and conmua2==-1 and conmua1==-1
mua2= conmua1==1 and ( close>n1 and pacC>signalMA and open<n1 and close>pacC) and conmua[1]==-1
//if(mua2 and onlysell==false)
//    strategy.entry("Buy",strategy.long)
conban=hisdown==1 and MACD<0?1:(hisup[1]==1 and MACD[1]>0 and pacC[1]<signalMA[1]) or (n1[2]>n1[3] and pacC[1]<signalMA[1])?-1:nz(conban[1],1)
conban1= conban==1 and (hisup==1 and MACD>0 and pacC<signalMA) or (n1[1]>n1[2] and pacC<signalMA)?1:( close[1]<n1[1] and pacC[1]<signalMA[1] and open[1]>n1[1] and close[1]<pacC[1]) or crossover(pacC,signalMA)?-1:nz(conban1[1],1)
conban2=conban1==1 and hisdown==1 and MACD<0 and close<n1?1: low[1]>low[3] and low[2]>low[3]?-1:nz(conban2[1],1)
conban3=conban2==1 and low[1]>low[2] and low>low[2]?1: (close[1]<swinglow[1] and hisdown[1]==1 and MACD[1]<0) or ( MACD>0)?-1:nz(conban3[1],1)
ban=conban3==1 and hisdown==1 and MACD<0 and conban2==-1 
ban2=conban1==1 and ( close<n1 and pacC<signalMA and open>n1 and close<pacC) and conban[1]==-1
//if(ban2 and onlybuy==false)
//    strategy.entry("Sell",strategy.short)  
plotshape(conmua1==1 and conmua[1]==-1, style= shape.triangleup, color = lime, location = location.bottom,size=size.tiny)
plotshape(conban1==1 and conban[1]==-1, style= shape.triangledown, color = red, location = location.bottom,size=size.tiny)
plotshape(mua2, style= shape.labelup, color = lime, location = location.bottom,size=size.tiny)
plotshape(ban2, style= shape.labeldown, color = red, location = location.bottom,size=size.tiny)
// TP and SL/
SL = input(defval=50.00, title="Chốt lời (Pip)", type=float, step=1)
rr= input(defval=20.00,title="Cắt lỗ (Pip)",type=float, step=1)
useTPandSL = input(defval = true, title = "Sử dụng chốt lời và cắt lỗ?")
Stop = rr*10
Take=SL*10
Q = 100
if(useTPandSL)
    strategy.exit("ExitBuy", "Buy", qty_percent=Q, profit= Take, loss=Stop)
    strategy.exit("ExitSell", "Sell", qty_percent=Q, profit= Take, loss=Stop)


더 많은