title: backtrader how to use analyzer to access data?
body: <p>I am very new to this.
  backtrader have a addwriter can write down some data,<br />
  <code> cerebro.addwriter(bt.WriterFile, csv=True, out='outputfiles3\{}cerebro.csv'.format(ticker))</code>
  but buy and sell price always not match to the execute price.</p>
  <p>so alternatively:</p>
  <p>i did <code>cerebro.addanalyzer(WritingAnalyzer)</code> before <code>cerebro.run() </code></p>
  <p>so I am trying to build the csv file with 'datetime','open','close','cash','value','position size'
  but I don't know how to access those data. I can only point at current day close price with <code>self.data[0]</code></p>
  <p>I don't know how to do it right. I hope someone might able to give me some directions.</p>
  <pre><code>import backtrader as bt
  from backtrader import Analyzer
  import csv
  
  class WritingAnalyzer(Analyzer):
  
      def __init__(self):
  
      def create_analysis(self):
          self.counter = 0
          print(self.counter)
          with open('demo1.csv',mode='w') as csv_file:
              fieldnames=['datetime','open','close','cash','value','position size']
              writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
              writer.writeheader()
  
      def next(self):
          self.counter += 1
          print('close price:',self.data[0], &quot;counter:&quot;,self.counter,)
          #  the following line suppose to write into csv file but i dont know how to get most of the data.
          bt.writer.writerow({'datetime': '??', 'open': '??', 'close': self.data[0],'cash':'??','value':'??','position size':'??'})
  
      def stop(self):
          print(&quot;SSSSSSSSSSSSSTTTTTTOOOOOOOOOOOOPPPPPPPPPP&quot;)
  
          self.rets._close()
  </code></pre>