btplotting icon indicating copy to clipboard operation
btplotting copied to clipboard

Custom indicator - lines connecting candles dont show up (eg zigzag indicator lines)

Open viveksp opened this issue 4 years ago • 6 comments

I am trying to plot a custom indicator. The lines dont show up.. For eg, can you try plotting this zigzag indicator coded by the creator of backtrader (https://community.backtrader.com/topic/773/zigzag-indicator). You will see that the lines show up intermittently. If you plot using the original backtrader plot, they work as expected Here is the screenshot Inkedbtplotting_LI If you see above, only in few places do you see the zigzag lines.. But look at the original plot below.. THis is how it should be Here is the original plot Original_plot_backtrader

I also tried drawing horizontal lines.. They work perfectly.. So the issue is specific to bars connecting highs and lows btplotting_horizontal_lines

viveksp avatar Feb 23 '21 05:02 viveksp

@viveksp were you able to fix it at all? PSAR indicator isn't working at all

Jake0303 avatar May 26 '21 16:05 Jake0303

@Jake0303 I encountered the same issue with PSAR in backtrader-plotting, which this lib is based on

found out it's related to the marker type used. this commit did the trick for me https://github.com/Loopiezlol/backtrader_plotting/commit/67753b9da7233136f253503b3379cc8310dcb054

I assume "point" or "pixel" would've worked as well, but "dot" doesn't seem to be a valid choice https://matplotlib.org/stable/api/markers_api.html

loopiezlol avatar Oct 23 '21 10:10 loopiezlol

@happydasch I'm happy to create a PR trying to fix any invalid matplotlib markers for this repo, but I am curious to learn whether this repo is still maintained beforehand

loopiezlol avatar Oct 23 '21 10:10 loopiezlol

Go ahead with the PR. I replaced lately some markers which did not work, too

happydasch avatar Oct 23 '21 10:10 happydasch

https://github.com/happydasch/btplotting/commit/7ca629762464c2d1b28631c4448975858eb1f7e2

happydasch avatar Oct 23 '21 10:10 happydasch

@happydasch and @Loopiezlol Thanks for proposing the solution. Just happened that I uses the same indicator and hitted the same issue. I gave a try to the solution but the issue still exists. Same as @viveksp, the line plotting looks okay when plotting with the original backtrader plot.

I think the problem is btplotting unable to plot the line / connect the point if the value = NaN The indicator marks the peak / valley with a value and others are set to NaN. The original backtrader plot is able to connect the point at peak & valley and ignore the NaN in between (just like https://user-images.githubusercontent.com/3601042/108806710-731b2580-75c8-11eb-889b-07f1c0bdbf08.PNG))

I checked the implemenation of the indicator plotting in backtrader. There's a lineplotinfo._get(_skipnan, False) check in plot.py (https://github.com/mementum/backtrader/blob/master/backtrader/plot/plot.py#L466) I wonder does the btplotting apply the same check and consider the "_skipnan" attributes when plotting the line?

I am not familiar with the rendering / plotting code so I cannot help much in this case. Hopefully this can point to the correct solution.

tlchan5 avatar Nov 03 '21 16:11 tlchan5

latest code should be able to plot this, reopen if still not plotting corrrectly

happydasch avatar Aug 29 '22 10:08 happydasch