Что касается гистограммы MACD Pine Script - PullRequest
1 голос
/ 07 мая 2020

Контрольное изображение В течение последних нескольких дней я пытался нанести на график конкретную c информацию, но это не go хорошо .. Буду признателен, если кто-нибудь сможет помогите мне с этим ...

Я пытаюсь определить самый высокий столбец в завершенной гистограмме MACD (выше 0) и самый низкий столбец в завершенной гистограмме MACD (ниже 0). Я приложил скриншот для справки. После определения двух последних самых высоких (или самых низких) я бы нарисовал из них линию тренда ..

///////// Код здесь. Я разделил гистограмму +, - и поставил точки выше и ниже гистограммы +, - ./////////////////////////////// ////////////////

//@version=4
study(title="My MACD", shorttitle="My MACD", overlay=true)

// Getting inputs
fast_length = input(title="Fast Length", 
type=input.integer, defval=12)
slow_length = input(title="Slow Length", 
type=input.integer, defval=26)
src = input(title="Source", type=input.source, 
defval=close)
signal_length = input(title="Signal Smoothing", 
type=input.integer, defval = 9)

// Calculating
fast_ma = ema(src, fast_length)
slow_ma = ema(src, slow_length)
macd = fast_ma - slow_ma
signal =  ema(macd, signal_length)
hist = macd - signal

// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00

////////////////////////////////////////   Plot   ////////////////////////////////////////////////////

// Dots(+histogram and -histogram) 
plotshape(hist>=0, "Dots histogram +", color=color.green, style=shape.cross, location=location.top)
plotshape(hist<=0, "Dots histogram -", color=color.red, style=shape.cross, location=location.bottom)

// +Histogram and -histogram
plot(hist, title="Histogram +", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : na), transp=0 )
plot(hist, title="Histogram -", style=plot.style_columns, color=(hist<=0 ? (hist[1] < hist ? col_grow_below : col_fall_below) : na), transp=0 )

1 Ответ

0 голосов
/ 07 мая 2020

См. Комментарии в коде:

//@version=4
study(title="My MACD", shorttitle="My MACD", overlay=true)

// Getting inputs
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
src = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, defval = 9)
hiSrc = input(high)
loSrc = input(low)

// Calculating
fast_ma = ema(src, fast_length)
slow_ma = ema(src, slow_length)
macd = fast_ma - slow_ma
signal =  ema(macd, signal_length)
hist = macd - signal

xUp = crossover(hist, 0)
xDn = crossunder(hist, 0)
// Will save the bar_index from the bar where the highest src is found when MACD is bull.
var int barOfLastHi = na
var int barOfLastLo = na
var int barOfHi = na
var int barOfLo = na
// Current hi/lo in bull/bear segment.
var float hi = na
var float lo = na
var macdBull = false
if xUp
    // Entering a bull segment; mark state.
    macdBull := true
    // Reset current hi.
    barOfHi := bar_index
    hi := hiSrc
    // Draw bear line.
    line.new(barOfLastLo, loSrc[bar_index - barOfLastLo], barOfLo, loSrc[bar_index - barOfLo])
    // Save last lo info from previous bear segment.
    barOfLastLo := barOfLo
else
    if xDn
        macdBull := false
        // Reset current lo.
        barOfLo := bar_index
        lo := loSrc
        // Draw bull line.
        line.new(barOfLastHi, hiSrc[bar_index - barOfLastHi], barOfHi, hiSrc[bar_index - barOfHi])
        // Save last hi info from previous bull segment.
        barOfLastHi := barOfHi
    else
        if macdBull and hiSrc > hi
            // New hi found.
            barOfHi := bar_index
            hi := hiSrc
        else
            if not macdBull and loSrc < lo
                // New lo found.
                barOfLo := bar_index
                lo := loSrc

// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00

////////////////////////////////////////   Plot   ////////////////////////////////////////////////////

// Dots(+histogram and -histogram) 
plotshape(hist>=0, "Dots histogram +", color=color.green, style=shape.cross, location=location.top)
plotshape(hist<=0, "Dots histogram -", color=color.red, style=shape.cross, location=location.bottom)

// +Histogram and -histogram
// plot(hist, title="Histogram +", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : na), transp=0 )
// plot(hist, title="Histogram -", style=plot.style_columns, color=(hist<=0 ? (hist[1] < hist ? col_grow_below : col_fall_below) : na), transp=0 )

enter image description here

...