I have one more little job for a coder. There is a code snippet 1 trade per day… is it possible to write a similar function on an indicator? I need this function for the MACD:
Long: MACD crosses over 0, if MACDLINE > 0 Short vice versa
But only for the 1st cross of the MACD, ideally the following crosses can be counted/optimized. The counter is then reset as soon as the MACDLINE generates a new signal/new swing. Is this doable?
Explanation in the picture (sorry smartphone) green bar: counter start,
1-4: possible entries,
5: reset the counter.
There you go:
DEFPARAM DrawOnLastBarOnly = true
ONCE Count = 0
IF IntraDayBarIndex = 0 THEN
Count = 0
ENDIF
IF Macd[12,26,9] CROSSES OVER 0 THEN
Count = Count + 1
ENDIF
x = Count
IF Count = Count[1] THEN
x = 0
ENDIF
RETURN x AS "Crossover Count"
Thanks, but I meant it as coding for a strategy. Counting condition Long/Counting start is Cross MACDLINE above 0. Counter reset is Cross MACDLINE below 0 and at the same time counting start for Short. The crosses of the MACD itself are counted, each long and short. I want to find out how many MACD crosses can be lucrative within a swing of the MACDLINE.
Bob’s your uncle:
ONCE ShortTallyMACD = 0
ONCE LongTallyMACD = 0
ONCE ShortTallyMACDline = 0
ONCE LongTallyMACDline = 0
//
MyHISTO = MACD[12,26,9](close)
//MySIGNAL = MACDSignal[12,26,9](close)
MyLINE = MACDline[12,26,9](close)
//
IF MyHisto CROSSES OVER 0 THEN
LongTallyMACD = LongTallyMACD + 1
ShortTallyMACD = 0
ENDIF
IF MyHisto CROSSES UNDER 0 THEN
LongTallyMACD = 0
ShortTallyMACD = ShortTallyMACD + 1
ENDIF
//
IF MyLINE CROSSES OVER 0 THEN
LongTallyMACDline = LongTallyMACDline + 1
ShortTallyMACDline = 0
ENDIF
IF MyLINE CROSSES UNDER 0 THEN
LongTallyMACDline = 0
ShortTallyMACDline = ShortTallyMACDline + 1
ENDIF
//
buy at -close limit
//
Graph ShortTallyMACD
Graph LongTallyMACD
Graph ShortTallyMACDline
Graph LongTallyMACDline