ChillarAnand / stocktrends

A python package to calculate trends in stocks, derivates(Futures & Options) using Renko, PnF, LineBreak etc
GNU General Public License v3.0
240 stars 74 forks source link

How to get the chart to work? #17

Closed chranga closed 2 years ago

chranga commented 3 years ago

Hi mate, i've been reading through your code for a few days now. Im not a full fledged python developer (just getting started). I cant seem to get the chart to work.

Could you please explain this piece of code?

I assume that this definition :

What is for delta in data though?.. or how does it translate to for delta in bricks array? Is it just a count or does delta get the value from the bricks array?

Also, using variable explorer, I see that bricks array is "Array of float64"

def plot_renko(data, brick_size):
    fig = plt.figure(1)
    fig.clf()
    axes = fig.gca()
    y_max = max(data)

    prev_num = 0

    bricks = []

    for delta in data:
        if delta > 0:
            bricks.extend([1]*delta)
        else:
            bricks.extend([-1]*abs(delta))

    for index, number in enumerate(bricks):
        if number == 1:
            facecolor='green'
        else:
            facecolor='red'

        prev_num += number

        renko = Rectangle(
            (index, prev_num * brick_size), 1, brick_size,
            facecolor=facecolor, alpha=0.5
        )
        axes.add_patch(renko)

    plt.show()
Baappii commented 3 years ago

hello when i tried to execute this code i get this error: ---specifically on this line : bricks.extend([1]*delta) ---typeerror: can't multiply sequence by non-int of type 'numpy.float64' any suggestions? thanks...

ChillarAnand commented 3 years ago

@chranga Delta depends on your needs. You can configure this via brick size as shown here. https://github.com/ChillarAnand/stocktrends#usage