Based on the code you provided about finding bullish and bearish heikin ashi candlesticks, the code of the strategy would be as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
xClose = (Open + High + Low + Close )/ 4
if (barindex > 2 ) then
xOpen = (xOpen[ 1 ] + xClose[ 1 ] )/ 2
endif
green= xClose> xOpen AND xClose[ 1 ] < xOpen[ 1 ]
red= xClose< xOpen AND xClose[ 1 ] > xOpen[ 1 ]
long = green= 1 and green[ 1 ] = 1 and green[ 2 ] = 0
short = red= 1 and red[ 1 ] = 1 and red[ 2 ] = 0
if long then
buy 1 share at market
endif
if short then
sell 1 share at market
endif
Here, I do not test a “series of red candles” or a “series of green candles” but only 1, you’ll have to define what you consider as a “series”.