Backtrader Community

    • 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 plot arbitrary values?

    General Discussion
    3
    3
    2281
    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.
    • T
      Taewoo Kim last edited by Taewoo Kim

      I'm calculating support/resistance on X period close prices.

      I'd like to plot this on the output chart and i saw the code from here, but I believe backtrader is looking for time series data for this to work.

      import backtrader as bt
      import backtrader.indicators as btind
      
      class SR_Indicator(bt.Indicator):
          lines = ('sr',)
      
      def __init__(self):
          self.lines.sr = self.data
      

      In strategy init:

      self.tf_0_sr = [ 0.15112, 0.15332, .....]
      self.lower_tf_sr = SR_Indicator(self.tf_0_sr)
      

      (Doesn't work)

      1. How would I plot arbitrary horizontal lines on the output chart?

      2. If i have two supports and resistances (one for each time frame I'm analyzing), how do I indicate the right indicator for the right time frame? This is how I added /resampled the data

        df = csv_to_pandas(args.data, timeframe=bt.TimeFrame.Minutes) #convert bid / ask to OHLC
        base_data = bt.feeds.PandasData(dataname=df, timeframe= bt.TimeFrame.Minutes) #1 minute
        cerebro.adddata(base_data )

        cerebro.resampledata(base_data, timeframe=bt.TimeFrame.Minutes, compression=15) #15 minutes

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @Taewoo Kim last edited by

        @Taewoo-Kim said in How to plot arbitrary values?:

        1. How would I plot arbitrary horizontal lines on the output chart?

        See Docs - Plotting and plothlines and/or plotyticks under Object-wide plotting options. You can find examples in the Stochastic and RSI indicators.

        1. If i have two supports and resistances (one for each time frame I'm analyzing), how do I indicate the right indicator for the right time frame? This is how I added /resampled the data

        There is context (sample code) missing for a real answer, but the guess if you have to specifically tell the indicator with which data it has to work, either data0 or data1 (seems you only have 2 data feeds)

        1 Reply Last reply Reply Quote 0
        • T
          Taewoo Kim last edited by

          Thank you. Will give it a try

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