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/

    Beginner Question: No trades executed with CSV data?

    General Code/Help
    crypto csv data data feed data feeds
    2
    3
    767
    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
      tradingnoob last edited by

      Hey all
      I'm new to backtrader and I'm really excited about it! But I have a problem:

      Im trying to work with my csv Data wich I have fetched from a crypto exchange. When I plot it evrything looks fine, but it executes no trades. I think the problem is somewhere in my Data.

      The Candlesticks are daily.

      0_1526405242896_backtestpicture.png

      So this is how I'm trying to set de data:

      def data():
          data = btfeeds.GenericCSVData(
              dataname="data.csv",
              nullvalue=0.0,
              dtformat=('%Y-%m-%d'),
              tmformat=('%H:%M:%S'),
              timeframe = bt.TimeFrame.Days,
              compression=1,
              datetime=1,
              time = 12,
              open=2,
              high=3,
              low=4,
              close=5,
              volume=6,
              openinterest = -1)
          return data
      

      and this is my strategy:

      class firstStrategy(bt.Strategy):

      def __init__(self):
          self.rsi = bt.indicators.RSI_SMA(self.data.close, period=21)
      
      def next(self):
          if not self.position:
              if self.rsi < 30:
                  self.buy(size=100)
          else:
              if self.rsi > 70:
                  self.sell(size=100)
      

      Has anyone an idea what I need to fix? Thank you so much in advance!

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

        You have a thing whose value is over 6000 (six thousand) at the end of the chart. You want to buy 100 units of it.

        Basic math: 100 * 6000 = 600000 (six hundred thousand monetary units are needed)

        Your cash (from the top part of the chart): 1000 (one thousand monetary units are available)

        1 Reply Last reply Reply Quote 2
        • T
          tradingnoob last edited by

          Oh thank you so much! Obvious mistake haha

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
          $(document).ready(function () { app.coldLoad(); }); }