I would like to exchange ideas on how to program Steve Nison’s candlestick pattern.
// YS-CandlesPatternV1.0
//(choose 0=No Trend check, 1=MACD, 2=SAR, 3=Directional Movement, 4=Moving Averages crossing [default], 5=Stochastic)
TDS=4
//text color
// white = 255,255,255 ; black = 0,0,0
r = 0
g = 0
b = 0
atr = averagetruerange[10](close)*0.5
body=close-open
abody=abs(body)
if range>0 then
ratio=abody/range
else
ratio=0
endif
middle=(open+close)/2
if body>0 then
bodytop=close
bodybottom=open
else
bodytop=open
bodybottom=close
endif
shadowtop=high-bodytop
shadowbottom=bodybottom-low
longcandle= (ratio>0.6)
DojiSize = 0.05
data=(abs(open - close) <= (high - low) * DojiSize)
if data then
DRAWTEXT("Dji", barindex, high+atr*dis1, Dialog, Standard, 12) COLOURED(R,G,B, fade1)
endif
if close[1]<close and close<open[1] and close[1]<open and open<open[1] then
Hara=3
else
Nohara=4
endif
//Trend Detection
if TDS=0 then
TrendUp=1
TrendDown=1
else
if TDS=1 then
TrendUp=(MACDline[12,26,9](close)>0 AND MACD[12,26,9](close)>0)
TrendDown=(MACDline[12,26,9](close)<0 AND MACD[12,26,9](close)<0)
else
if TDS=2 then
TrendUp=(SAR[0.02,0.02,0.2]<low)
TrendDown=(SAR[0.02,0.02,0.2]>high)
else
if TDS=3 then
TrendUp=(ADX[14]>23 AND DI[14](close)>0)
TrendDown=(ADX[14]>23 AND DI[14](close)<0)
else
if TDS=4 then
TrendUp=(ExponentialAverage[2](close)>ExponentialAverage[4](close))
TrendDown=(ExponentialAverage[2](close)<ExponentialAverage[4](close))
else
if TDS=5 then
TrendUp=(Stochastic[14,3](close)>Average[5](Stochastic[14,3](close)))
TrendDown=(Stochastic[14,3](close)<Average[5](Stochastic[14,3](close)))
endif
endif
endif
endif
endif
endif
size1=10
y=20
size3=30
fade1=10
fade2=100
fade3=200
dis1=1
dis15=1.5
dis2=2
dis3=5
dis4=10
////Bearish Signal Falling3Method2 p142
if (open[5]>close[5] AND close[5]<open[4] and open[4]<open[3] and open[3]<open[2] and open[2]<open[1] and close[1]<open AND open>close) or (open[4]>close[4] AND close[4]<open[3] and open[3]>open[2] and open[2]>open[1] and close[1]<open AND open>close) or (open[3]>close[3] AND close[3]<open[2] and open[2]>open[1] and close[1]<open AND open>close)then
DRAWTEXT("Falling3Method1",barindex,high[1]+atr*dis1, Dialog, Standard, 10) COLOURED(255,0,0,fade2)
DRAWARROWdown(barindex,high[1]) COLOURED(255,0,0,fade3)
endif
Return
The those three middle white candles (open[3]<close[3] AND close[3]>open[2] and open[2]<open[1] and close[1]>open AND open<close) can possibly continue not only 3 but also 7, 8, 9… middle candles. Then, the code will be too long to express it.
Alternatively, I have re-coded it using the while loop as the below.
//Bearish Signal Falling3Method2 p126//////////////////////////////////////////////////////////////////////
i=1
while (open[i+4]>close[i+3] AND close[i+3]<open[i+2] and open[i+2]>open[i+1] and close[i+1]<open AND open>close) and i < 30 DO
i=i+1
DRAWTEXT("Falling3Method2", barindex,low[1]-atr*dis2, Dialog, Standard, 10) COLOURED(0,155,10,fade2)
DRAWARROWUP(barindex,low[1]-atr*dis1) COLOURED(0,155,10,fade2)
Wend
But it has been unsuccessful. I would appreciate it very much if there is any advice to make it shorter code. Thank you.