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?



  • 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!


  • administrators

    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)



  • Oh thank you so much! Obvious mistake haha