Hi
I’ve been trying to write an indicator to highlight breakouts above 20 period highs but only those that have happened within 20 days after the cross of the MACD (highlight the start of a new trend). I can code the individual parameters but can’t work out how to combine them together.
y=highest[20](high)[1]
mymacd = macdline[12,26,9]
crossup = mymacd crosses over 0
signal=high crosses over y
return signal, crossup
I was thinking that a loop looking back over the prior 20 days after each new 20 day high to check for a MACD cross would be a potential solution but I can’t work out how to code it.
I would be grateful if someone could assist.
Thanks
Andrew
Do you want that at least 20 bars have elapsed after the Macd crossover?
Or, if only say 12 bars have elapsed, then you want to retrieve the highest high of those 12 bars instead of 20?
Use SUMMATION.
y=highest[20](high)[1]
mymacd = macdline[12,26,9]
crossup = summation[20](mymacd crosses over 0) <> 0
signal=high crosses over y
return signal, crossup
There you go:
y = highest[20](high)[1]
mymacd = macdline[12,26,9]
crossup = mymacd crosses over 0
signal = high crosses over y
For i = 0 to BarIndex
If crossup[i] then
Break
Endif
Endif
If i > 20 then //clear signals if more than 20 bars
signal = 0
crossup = 0
Endif
return signal, crossup
This should do for 20- bars.
Vonasi’s code is much simpler!
That’s exactly what I was looking for!
Thanks for the help.