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/

    Custom indicator disappears during live trading

    General Discussion
    1
    2
    66
    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.
    • F
      FredYellow last edited by

      Hi all,

      I'm starting to try live trading with my startegy which has up to now only been backtested.
      I have a custom indicator and a custom analyzer which both run fine during backtesting, however now I'm trying to run the same strat live (using the ccxtbt store for Binance) and this is what happens:

      class customIndicator(bt.Indicator):
           	lines = ('someLine')	
           	params = (('dataClose', 		0))
           	plotlines = dict(someLine =    dict(_name='someLine', 	color='green',  linewidth = 1, 	alpha=0.9))		
           	def __init__(self):
           			self.l.someLine = ...
      
           class customAnalyzer(Analyzer):    
           	def __init__(self):    
           		self.var 			= 0                         
           	def start(self):
           		pass
           	def next(self):												
           		if (self.strategy.customIndicator.l.someLine[0] > 10):	
           			self.var += 1										
           		...
           	def stop(self):
           		...
           	def get_analysis(self):
           		return dict(var = self.var) 
      

      Obviously I simplified the example code to it's essence.
      This is the error I get:

        File "...main.py", line 221, in next
          if (self.strategy.customIndicator.l.someLine[0] > 10):
        File "...\lib\site-packages\backtrader\lineseries.py", line 461, in __getattr__
          return getattr(self.lines, name)
      AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Strateg' object has no attribute 'customIndicator'
      

      So for some reason the customIndicator has not yet been initialised, but the

      def next(self):
      

      In the analyzer is already being called. Is this normal? Why is this different during Live trading than backtesting?

      Kind regards,
      Fred

      1 Reply Last reply Reply Quote 0
      • F
        FredYellow last edited by

        Apparantly I had simply forgotten to add the strategy when live trading using

        cerebro.addstrategy(    TestStrategy)
        

        This also meant none of the indicators were initialized...

        Hope this helps someone!

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