206 1 6
beta version of multiple macd indicator
Remove from Favorite Scripts Add to Favorite Scripts
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)


Hi, speculants!
Can anyone help me with issues?
1.Seems there is a bug in 240 timeframe counting, the script does not indicate divergence
2. If I set bigger length value to find_diver(m240, 200) it says "out of depth at index"
3. I can't undestand why plotshape() does not plot label "Diber!" on graph. May be I have to set any more parameters?
4. How can I call "plot" functions in cycle? I want to write something like this:
for timeframe in
count_and_plot_diver(timeframe)

Thanks!
Ответить
RU Русский
EN English
EN English (UK)
EN English (IN)
DE Deutsch
FR Français
ES Español
IT Italiano
PL Polski
TR Türkçe
PT Português
ID Bahasa Indonesia
MS Bahasa Melayu
TH ภาษาไทย
VI Tiếng Việt
JA 日本語
KO 한국어
ZH 简体中文
ZH 繁體中文
Домой Скринер акций Сигналы для Форекс пар Сигналы для криптовалют Экономический календарь О проекте Особенности Правила поведения Модераторы Решения для сайтов и брокеров Виджеты Компонент графиков Отзывы и предложения Блог и новости ЧаВо Справка и Wiki Твиттер
Профиль Настройки профиля Счёт и оплата Мои запросы в поддержку Связаться с поддержкой Опубликовано идей Подписчики Подписки Личные сообщения Чат Выйти