Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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?

    General Code/Help
    4
    4
    718
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dzz007 last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • Rodrigo Brito
        Rodrigo Brito last edited by

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

        1 Reply Last reply Reply Quote 1
        • A
          ab_trader last edited by ab_trader

          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.

          • If my answer helped, hit reputation up arrow at lower right corner of the post.
          • Python Debugging With Pdb
          • New to python and bt - check this out
          1 Reply Last reply Reply Quote 2
          • B
            backtrader administrators last edited by backtrader

            @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.

            1 Reply Last reply Reply Quote 1
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors