beta version of multiple macd indicator
study(title="MacD_MT", shorttitle="MacD_MT") //@version=2 find_max_bool(s1, s2, s3) => bmax = false if (s2 - s3) > 0.01 and (s2 - s1) > 0.01 bmax := true bmax //@version=2 find_diver(ser, length) => sign = ser[1] / abs(ser[1]) abs_ser = ser * sign max1 = false max2 = false diver_found = false max2_pos = 0 max1 := find_max_bool(abs_ser[0], abs_ser[1], abs_ser[2]) if max1 == true for i = 1 to length - 1 max2 := find_max_bool(abs_ser[i+2], abs_ser[i+3], abs_ser[i+4]) if max2 == true if (abs_ser[i+3] - abs_ser[1]) > 0.1 diver_found := true max2_pos := i+3 break // else case max2 := false allpositive = true if diver_found == true for j = 2 to max2_pos if abs_ser[j] < 0 allpositive := false break res = diver_found == true and allpositive == true res //@version=2 var_macd(tframe) => source = close fastLength = input(12, minval=1) slowLength=input(26,minval=1) signalLength=input(9,minval=1) fastMA = sma(source, fastLength) slowMA = sma(source, slowLength) macd = fastMA - slowMA signal = sma(macd, signalLength) hist = macd - signal outMacD = security(tickerid, tframe, macd) outSignal = security(tickerid, tframe, signal) outHist = security(tickerid, tframe, hist) [outMacD, outSignal, outHist] [m30, s30, h30] = var_macd("30") //plot(s60, color=red, title="SIGNAL") plot(m30, color=#0060ff, title="MACD") is_diver30 = find_diver(m30, 30) plot(is_diver30, color=green) plotshape(is_diver30, color=lime, style=shape.arrowup, text="Diver!") [m240, s240, h240] = var_macd("240") //plot(s240, color=red, title="SIGNAL") plot(m240, color=#0020ff, title="MACD") is_diver240 = find_diver(m240, 200) plot(is_diver240, color=green)