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

How to draw point on the chart without using indicator?



  • Hey guys,
    When I am backtesting, i wanna make sure the programming is doing the correct thing.
    So I would like to mark a small dot on the chart once the algo think it is a critical point, is there a easy way to do that?

    Two ways i know to mark a dot is through triggering buy() or make a indicator.
    Is there some straight forward API so i can just mark a point on the chart without the hussle of creating an indicator?



  • It is an interesting feature. Sometimes I want to visualize critical points such as "stop loss".



  • I think that the most convenient way is to write an observer. It will be shown by bt's standard plotting mechanics, and strategy variables can be accessed from the observer.

    This script I wrote some time ago to plot stop loss and take profit price levels:

    class SLTPTracking(bt.Observer):
    
        lines = ('stop', 'take')
    
        plotinfo = dict(plot=True, subplot=False)
    
        plotlines = dict(stop=dict(ls=':', linewidth=1.5),
                         take=dict(ls=':', linewidth=1.5))
    
        def next(self):
    
            if self._owner.sl_price != 0.0:
                self.lines.stop[0] = self._owner.sl_price
    
            if self._owner.tp_price != 0.0:
                self.lines.take[0] = self._owner.tp_price
    

    Variables sl_price and tp_price are defined each next() within the strategy and used for order processing.


  • administrators

    @dzz007 said in How to draw point on the chart without using indicator?:

    Is there some straight forward API so i can just mark a point on the chart without the hussle of creating an indicator?

    @rodrigo-brito said in How to draw point on the chart without using indicator?:

    It is an interesting feature. Sometimes I want to visualize critical points such as "stop loss".

    Interesting, but a chart is composed of n points along a timeline and if you want to mark point x for timestamp t, unfortunately all other timestamps which aren't t need a value, even if the value is NaN (filled automatically by the platform) to have nothing displayed.

    Either an Indicator or an Observer.


Log in to reply
 

});