// Detection bullish engulfing
BullishEngulfing= CLOSE[1] < OPEN[1] AND OPEN < CLOSE[1] AND CLOSE > OPEN[1]
// Detection bearish engulfing
bearishengulfing = CLOSE[1] > OPEN[1] AND OPEN > CLOSE[1] AND CLOSE < OPEN[1]
// Detection shooting star
ShootingStar = close>open and low=open and (high-close)>=3*(close-open)
// Detection du marteau
Marteau = close>open and high=close and (open-low)>=3*(close-open)
// Détection des haramis haussiers
HaramiHausse = close[1]<open[1] AND open>close[1] AND close<open[1] AND open<close
// Détection des haramis baissier
HaramiBaisse = close[1]>open[1] AND open<close[1] AND close>open[1] AND close<open
// Detection dark cloud cover (bearish reversal)
darkcloudcover = CLOSE[1] < OPEN[1] AND OPEN < CLOSE[1] AND CLOSE > OPEN[1]
// Detection piercing
piercing = Average[35](Volume) > 250000 AND CLOSE[1]<OPEN[1] AND OPEN< CLOSE[1] AND CLOSE>(CLOSE[1]+(OPEN[1]-CLOSE[1])/2) AND CLOSE < OPEN[1]AND RSI[9](close)<50
//Morning Star
morningstar=(close[2] < open[2] and max(open[1], close[1]) < close[2] and open > max(open[1], close[1]) and close > open )
//Evening Star
EveningStar=(close[2] > open[2] and min(open[1], close[1]) > close[2] and open < min(open[1], close[1]) and close < open )
detection= BullishEngulfing or bearishengulfing or ShootingStar or Marteau or HaramiHausse or HaramiBaisse or darkcloudcover or piercing or morningstar or EveningStar
stoc=Stochastic[14,3](close)
clong=detection and high > highest[2](high[1]) and stoc < 30
if clong then
buy 1 share at market
endif
cshort=detection and low < lowest[2](low[1]) and stoc > 70
if cshort then
sellshort 1 share at market
endif
set stop ploss 60