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/

    Help with starting up

    Indicators/Strategies/Analyzers
    2
    2
    61
    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.
    • S
      Shubham last edited by

      Hello,
      I am new to backtrader as well as python and would really appreciate some help to get started. I have written a strategy that generates signals but I am not able to backtest the same. Can someone help me to convert the logic below to init and next functions?
      Thanks in Advance

      df['44sma'] = df['Close'].rolling(window=44).mean()
      if (df.iloc[-1]['Low'] < df.iloc[-1]['44sma']):
      if (df.iloc[-1]['High'] > df.iloc[-1]['44sma']):
      if (df.iloc[-1]['Close'] > df.iloc[-2]['Close']):
      if (df.iloc[-1]['Close'] > df.iloc[-1]['44sma']):
      for i in range(30):
      if(df.iloc[-i-1]['44sma'] > df.iloc[-i-2]['44sma']):
      flag = 1
      else:
      flag = -1
      break

      run-out 1 Reply Last reply Reply Quote 0
      • run-out
        run-out @Shubham last edited by

        @shubham You need to create indicators and create them in the __init__ of your strategy. You can then use them in next. I would encourage you to read the docs here They are quite useful and have many examples. Once you have taken a stab at writing the code in Backtrader, repost here again if you have any issues.

        RunBacktest.com

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