Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Dvenzi
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    D
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 5
    • Best 0
    • Groups 0

    Dvenzi

    @Dvenzi

    0
    Reputation
    370
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Dvenzi Unfollow Follow

    Latest posts made by Dvenzi

    • How to check candle highest value

      Hello,

      i'm already able to check a specific candle opening and closing value:

                      self.datas[0].open
                      self.datas[0].close
      

      but i didn't find a similar way to see the candle highest and lowest value, can someone give me hint?

      Sorry for the noob question! =S

      Thanks!

      posted in General Code/Help
      D
      Dvenzi
    • RE: Trying to check 3 consecutive candles in the same direction

      Hello,

      sorry for the ilegible code =s .
      You are correct, i was setting the cash as a string. Already fixed it.

      Thanks !

      posted in Indicators/Strategies/Analyzers
      D
      Dvenzi
    • Trying to check 3 consecutive candles in the same direction

      Hello,

      i'm trying to check for for consecutive candles in the same direction in my CSV, here is how im doign it:

      Strategy file:
      #------------------------------------------------------------------------------------------------------------------------------------------------
      import backtrader as bt

      class ThreeCandles(bt.Strategy):

      #def log(self, txt, dt=None):
      #    dt= dt or self.datas[0].datetime.date(0)
       #   print("{}, {}".format(dt.isoformat(),txt))
      
      def __init__(self):
          self.dataclose = self.datas[0].close
          self.dataopen = self.datas[0].open
      
      def next(self):
          #self.log('Close, {}'.format(self.dataclose[0]))
      
          if self.dataclose[0] > self.dataopen[0]:
      
              if self.dataclose[-1] > self.dataopen[-1]:
      
                  if self.dataclose[-2] > self.dataopen[-2]:
      
                      print("Três linhas de crescimento consecutivas !")
          
          elif self.dataclose[0] < self.dataopen[0]:
      
              if self.dataclose[-1] < self.dataopen[-1]:
      
                  if self.dataclose[-2] < self.dataopen[-2]:
      
                      print("Três linhas de decrescimeto consecutivas !")
      

      #-------------------------------------------------------------------------------------------------------------------------------------------
      Main file:
      #------------------------------------------------------------------------------------------------------------------------------------------------
      from future import (absolute_import, division, print_function, unicode_literals)

      import datetime
      import os.path
      import sys
      import strategies

      if name == 'main':
      cerebro = strategies.bt.Cerebro()

      cerebro.addstrategy(strategies.ThreeCandles)
      
      modpath = os.path.dirname(os.path.abspath(sys.argv[0]))
      datapath = os.path.join(modpath, '/home/daniel/Documentos/FOREX/data/values.txt') 
      data = strategies.bt.feeds.YahooFinanceCSVData(dataname=datapath, fromdate=datetime.datetime(2002, 1, 1), todate=datetime.datetime(2002,12,31), reverse=False)
      
      cerebro.adddata(data)
      
      cerebro.broker.setcash(sys.argv[1])
      
      print("Begin with com: {0}".format(cerebro.broker.get_value()))
      
      cerebro.run()
      
      print("Finish with com: {0}".format(cerebro.broker.get_value()))
      

      when i run it im getting this error:

      Begin with com: 1000
      Traceback (most recent call last):
      File "main.py", line 24, in <module>
      cerebro.run()
      File "/usr/local/lib/python3.5/dist-packages/backtrader/cerebro.py", line 1127, in run
      runstrat = self.runstrategies(iterstrat)
      File "/usr/local/lib/python3.5/dist-packages/backtrader/cerebro.py", line 1187, in runstrategies
      self._broker.start()
      File "/usr/local/lib/python3.5/dist-packages/backtrader/broker.py", line 64, in start
      self.init()
      File "/usr/local/lib/python3.5/dist-packages/backtrader/brokers/bbroker.py", line 287, in init
      self._fundshares = self.p.cash / self._fundval
      TypeError: unsupported operand type(s) for /: 'str' and 'float'

      what am i doing wrong? could it be something wrong with my csv file?

      posted in Indicators/Strategies/Analyzers
      D
      Dvenzi
    • Real time Noob - CSV files

      Hello,

      as i'm writing this i've noticed that this is a really noob question haha, but nevertheless i dont know where to find csv files so i can add them to cerebro.
      Where do i download them from? Is there a way to get real time data?

      Thanks in advance !

      posted in General Code/Help
      D
      Dvenzi
    • How to get line opening value

      Hello,

      first of all i'm new to backtrader, as i was reading the quickstart guide i noticed that lines have values such as "open" and "close", and the way to access the current close value is : datas[0].close . Am i correct to assume that to check the opening value for the same line i would use datas[0].open ?

      Thanks in advance (sorry for the silly question, and also sorry if i posted this question on the wrong category).

      posted in General Code/Help
      D
      Dvenzi