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
andtp_price
are defined eachnext()
within the strategy and used for order processing. -
@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 pointx
for timestampt
, unfortunately all other timestamps which aren'tt
need a value, even if the value isNaN
(filled automatically by the platform) to have nothing displayed.Either an Indicator or an Observer.