For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Plotting 3 [x,y] pairs connected with lines on master plot



  • Hello,

    I hope someone can help me please,

    I am trying to draw groups of points [3] with lines connecting them ( a series of shapes overlayed on main chart for visual purposes).

    Is there anyway to do this with backtrader?

    I found some code for matplotlib to do this:

    https://stackoverflow.com/questions/35363444/plotting-lines-connecting-points

    Is there a way to access the actual matplotlib object for masterplot, as a last resort?



  • I just pulled the link for the plotting documentation for another answer:

    My own experience and a very quick look doesn't seem to indicate that the plotting functionality is (was) conceived to allow random drawing on the chart. It seems to be focused on getting the information from some of different actors in a backtesting run (data feeds, indicators, observers) and displaying it.

    With that in mind it would seem that the most natural way to display your pairs of points is to create an indicator, which has the specific points. But I wouldn't bet on it, since you seem to want to draw a triangle, and my personal guess is that you would end up with an open one (coordinates would be connected from left to right, following the timeline of the backtesting)

    @nrek said in Plotting 3 [x,y] pairs connected with lines on master plot:

    Is there a way to access the actual matplotlib object for masterplot, as a last resort?

    There is apparently not a public interface. But the source might help you in that case.



  • Thanks for your answer,

    an 'Open V' shape is what i am trying to produce, so eg:

    • If I create an indicator with a line for each 'open v' i want to show
    • indicator sets the 3 values for open_v_1 line

    do you know how I tell backtrader to join these 3 points and ignore all other values in that line object?

    I tried to do this already, but backtrader would not draw the line unless each value in line had a value eg. 0 for the points i dont want to plot.

    And, ideally if I could use 1 line object for multiple open v's, that would be nice :)

    Regards



  • @nrek said in Plotting 3 [x,y] pairs connected with lines on master plot:

    do you know how I tell backtrader to join these 3 points and ignore all other values in that line object?

    No.

    @nrek said in Plotting 3 [x,y] pairs connected with lines on master plot:

    I tried to do this already, but backtrader would not draw the line unless each value in line had a value eg. 0 for the points i dont want to plot.

    I imagine the situation can be summarised as in here: https://stackoverflow.com/questions/14399689/matplotlib-drawing-lines-between-points-ignoring-missing-data

    It would seem backtrader is not using masks as described in the answer with isfinite (or any other method). There may be good reasons for it like alignment (it can plot things with different timescales, so it obviously performs a reindexing for each timescale), or it may simply not be implemented.



  • Some time ago I was able to draw lines which don't have all points defined, don't think that I've made any modifications to bt.

    Just in case if you want to check - Stop/Take levels observer I've developed - link.