How to plot arbitrary values?



  • 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

  • administrators

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



  • Thank you. Will give it a try


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.