Navigation

    Backtrader Community

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

    asservir

    @asservir

    0
    Reputation
    159
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    asservir Unfollow Follow

    Latest posts made by asservir

    • Not Enough Memory for Optimization

      I am optimizing a simple SMA crossover strategy in M30 timeframe for one year. When I set moving average period parameters 10 to 30 and 20 to 60, my code work fine.

      But it will out of memory when the parameter is large, e.g. 10 to 200 and 20 to 400.

      Can I reduce the memory cost on backtrader optimization?

      posted in General Discussion
      A
      asservir
    • RE: beginner question about bracket order

      @nicktids thx for reply. I found the problem and it should be a typing mistake lol.

      for bracket order function:
      limitprice <- should be take profit
      stopprice <- should be stop loss

      posted in General Code/Help
      A
      asservir
    • beginner question about bracket order

      Hey everyone, I am confused about using bracket order. As I know, the expectation of result should be similar profit and loss in every trades. The following is my code snippet and result. Any advises?

      def next(self):
          if not self.position:
              if self.sma_fast[-1] > self.sma_slow[-1] and self.sma_fast[-2] < self.sma_slow[-2]:
                  # self.log('BUY CREATE, %.5f' % self.dataclose[0])
                  # self.order = self.buy()
                  entry = self.data.close[0]
                  long_tp = entry + 1000 * self.vpoint
                  long_sl = entry - 1000 * self.vpoint
                  print('[ORDER_SEND] BUY >> entry_price: %.5f tp: %.5f sl: %.5f' %
                        (entry, long_tp, long_sl))
                  self.order = self.buy_bracket(
                      price=entry, stopprice=long_tp, limitprice=long_sl)
                  pass
      
              elif self.sma_fast[-1] < self.sma_slow[-1] and self.sma_fast[-2] > self.sma_slow[-2]:
                  # self.log('SELL CREATE, %.5f' % self.dataclose[0])
                  # self.order = self.sell()
                  entry = self.data.close[0]
                  short_tp = entry - 1000 * self.vpoint
                  short_sl = entry + 1000 * self.vpoint
                  print('[ORDER_SEND] SELL >> entry: %.5f tp: %.5f sl: %.5f' %
                        (entry, short_tp, short_sl))
                  self.order = self.sell_bracket(
                      price=entry, stopprice=short_tp, limitprice=short_sl)
                  pass
      

      RESULT:

      [ORDER_SEND] SELL >> entry: 1.16470 tp: 1.15470 sl: 1.17470
      [NOTIFY_ORDER] 2017-10-27: Order ref: 31 / Type Sell / Status Submitted
      [NOTIFY_ORDER] 2017-10-27: Order ref: 32 / Type Buy / Status Submitted
      [NOTIFY_ORDER] 2017-10-27: Order ref: 33 / Type Buy / Status Submitted
      [NOTIFY_ORDER] 2017-10-27: Order ref: 31 / Type Sell / Status Accepted
      [NOTIFY_ORDER] 2017-10-27: Order ref: 32 / Type Buy / Status Accepted
      [NOTIFY_ORDER] 2017-10-27: Order ref: 33 / Type Buy / Status Accepted
      [NOTIFY_ORDER] 2017-10-27: Order ref: 31 / Type Sell / Status Completed
      [NOTIFY_ORDER] 2017-10-27: Order ref: 32 / Type Buy / Status Completed
      [NOTIFY_ORDER] 2017-10-27: Order ref: 33 / Type Buy / Status Canceled
      [NOTIFY_TRADE] 2017-10-27 23:59:59.999989, Close Price: 1.1647, Profit, Gross 9.3, Net 9.3

      [ORDER_SEND] BUY >> entry_price: 1.17653 tp: 1.18653 sl: 1.16653
      [NOTIFY_ORDER] 2017-11-17: Order ref: 34 / Type Buy / Status Submitted
      [NOTIFY_ORDER] 2017-11-17: Order ref: 35 / Type Sell / Status Submitted
      [NOTIFY_ORDER] 2017-11-17: Order ref: 36 / Type Sell / Status Submitted
      [NOTIFY_ORDER] 2017-11-17: Order ref: 34 / Type Buy / Status Accepted
      [NOTIFY_ORDER] 2017-11-17: Order ref: 35 / Type Sell / Status Accepted
      [NOTIFY_ORDER] 2017-11-17: Order ref: 36 / Type Sell / Status Accepted
      [NOTIFY_ORDER] 2017-11-17: Order ref: 34 / Type Buy / Status Completed
      [NOTIFY_ORDER] 2017-11-17: Order ref: 35 / Type Sell / Status Completed
      [NOTIFY_ORDER] 2017-11-17: Order ref: 36 / Type Sell / Status Canceled
      [NOTIFY_TRADE] 2017-11-17 23:59:59.999989, Close Price: 1.17653, Profit, Gross 13.0, Net 13.0

      [ORDER_SEND] SELL >> entry: 1.17751 tp: 1.16751 sl: 1.18751
      [NOTIFY_ORDER] 2017-12-12: Order ref: 37 / Type Sell / Status Submitted
      [NOTIFY_ORDER] 2017-12-12: Order ref: 38 / Type Buy / Status Submitted
      [NOTIFY_ORDER] 2017-12-12: Order ref: 39 / Type Buy / Status Submitted
      [NOTIFY_ORDER] 2017-12-12: Order ref: 37 / Type Sell / Status Accepted
      [NOTIFY_ORDER] 2017-12-12: Order ref: 38 / Type Buy / Status Accepted
      [NOTIFY_ORDER] 2017-12-12: Order ref: 39 / Type Buy / Status Accepted
      [NOTIFY_ORDER] 2017-12-12: Order ref: 37 / Type Sell / Status Completed
      [NOTIFY_ORDER] 2017-12-12: Order ref: 38 / Type Buy / Status Completed
      [NOTIFY_ORDER] 2017-12-12: Order ref: 39 / Type Buy / Status Canceled
      [NOTIFY_TRADE] 2017-12-12 23:59:59.999989, Close Price: 1.17752, Profit, Gross 45.7, Net 45.7

      [ORDER_SEND] BUY >> entry_price: 1.18710 tp: 1.19710 sl: 1.17710
      [NOTIFY_ORDER] 2017-12-26: Order ref: 40 / Type Buy / Status Submitted
      [NOTIFY_ORDER] 2017-12-26: Order ref: 41 / Type Sell / Status Submitted
      [NOTIFY_ORDER] 2017-12-26: Order ref: 42 / Type Sell / Status Submitted
      [NOTIFY_ORDER] 2017-12-26: Order ref: 40 / Type Buy / Status Accepted
      [NOTIFY_ORDER] 2017-12-26: Order ref: 41 / Type Sell / Status Accepted
      [NOTIFY_ORDER] 2017-12-26: Order ref: 42 / Type Sell / Status Accepted
      [NOTIFY_ORDER] 2017-12-26: Order ref: 40 / Type Buy / Status Completed
      [NOTIFY_ORDER] 2017-12-26: Order ref: 41 / Type Sell / Status Completed
      [NOTIFY_ORDER] 2017-12-26: Order ref: 42 / Type Sell / Status Canceled
      [NOTIFY_TRADE] 2017-12-26 23:59:59.999989, Close Price: 1.1871, Profit, Gross -0.1, Net -0.1

      posted in General Code/Help
      A
      asservir