AbzParticipant
Veteran
Hello,trying out an simple macd strategy. If someone coud help , much appreciated.
for Long:
- once macd crosses over 0 and the next 3 bars on macd line is green
- then place and buy order “x”pips below the close price of the 3rd bar
For short:
- once macd crosses under 0 and the next 3 bars are red
- then place a short order “x”pips over the close price of the 3rd bar
see also attached screen
// Definition of code parameters
DEFPARAM Preloadbars = 10000
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// indicators
mac = MACDline[12,26,9](close)
Positions = 10
IF not onmarket and mac crosses over 0 THEN
buy Positions SHARES AT MARKET
ENDIF
IF not onmarket and mac crosses under 0 THEN
sellshort Positions SHARES AT MARKET
ENDIF
Set target pprofit 50
set stop ploss 50
3 red / green candles:
redcandle1 = close < open
redcandle2 = close[1] < open[1]
redcandle3 = close[2] < open[2]
threeredcandle = redcandle1 and redcandle2 and redcandle3
greencandle1 = close > open
greencandle2 = close[1] > open[1]
greencandle3 = close[2] > open[2]
threegreencandle = greencandle1 and greeencandle2 and greencandle3
And heres the “place an order below/above closed candle:
y2 = close - (10*pointsize)
if buytime then
buy 1 contract at y limit
endif
y1 = close + (10*pointsize)
if shorttime then
sellshort 1 contract at y2 limit
endif
So your entire code would look like this:
// Definition of code parameters
DEFPARAM Preloadbars = 10000
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// indicators
mac = MACDline[12,26,9](close)
redcandle1 = close < open
redcandle2 = close[1] < open[1]
redcandle3 = close[2] < open[2]
threeredcandle = redcandle1 and redcandle2 and redcandle3
greencandle1 = close > open
greencandle2 = close[1] > open[1]
greencandle3 = close[2] > open[2]
threegreencandle = greencandle1 and greeencandle2 and greencandle3
Positions = 10
macbuy = mac crosses over 0
macshort = mac crosses under 0
buytime = macbuy[2] and threegreencandle
shorttime = macshort[2] and threeredcandle
y1 = close + (10*pointsize)
y2 = close - (10*pointsize)
IF not onmarket and buytime THEN
buy Positions SHARES AT y2 limit
ENDIF
IF not onmarket and shorttime THEN
sellshort Positions SHARES AT y1 limit
ENDIF
Set target pprofit 50
set stop ploss 50
Just noticed you might have asked for 3 red macd bars and not 3 red candles in photo. Do you want the 3 bars to be lower/higher then the last one? or does it only matter that they are red/green?
This is for 3 red macd histogram bars that goes lower and lower: (just do the “>” for higher and higher for long trades)
indicator1 = MACD[12,26,9](close)
c1 = (indicator1 < 0)
indicator2 = MACD[12,26,9](close)
c2 = (indicator2[1] < 0)
indicator3 = MACD[12,26,9](close)
c3 = (indicator3[2] < 0)
indicator4 = MACD[12,26,9](close)
c4 = (indicator4 < indicator4[1])
indicator5 = MACD[12,26,9](close)
c5 = (indicator5[1] < indicator5[2])
If you only want 3 red bars and it dosnt matter which is bar is lower then the other then just remove c4 and c5
I’m watching with interest … please post curve and stats on here Abz and thanks goes to jebus89 for the coding!
AbzParticipant
Veteran
Thanks Jebus , i will do some backtests and report back
Good post. How about to filter signals of sideways market? Thx