Search code examples
pine-scriptstockpine-script-v4pine-script-v5

How To Get Pinescript To Count?


I'm currently trying to make a script that will essentially count the amount of bullish signals in your chart, then plot the number of bullish signs above each candlestick that has them.

I already have my patterns, variables, and signals, defined.

Just need help making the plot. I can't figure out how to make it correctly count the signals, then display that number over the candlesticks.

Thank you for answers!!!

(prefer V4 but any answers would be great!)


Solution

  • //@version=4
    study("", overlay = true, max_labels_count = 500)
    
    bull_cond1 = crossover(ema(close,13), ema(close,20))
    bull_cond2 = close > open
    bull_cond3 = close > close[2]
    
    
    bool global_bull_cond = bull_cond1 or bull_cond2 or bull_cond3 
    
    int bull_count = 0
    
    
    if global_bull_cond
        if bull_cond1
            bull_count += 1
        if bull_cond2
            bull_count += 1
        if bull_cond3
            bull_count += 1
        label.new(x = bar_index, y = high, style = label.style_label_down, size = size.tiny, color = color.lime, textcolor = color.black, text = tostring(bull_count))