Navigation

    Backtrader Community

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

    Ahmed Sobhy

    @Ahmed Sobhy

    0
    Reputation
    181
    Profile views
    7
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Ahmed Sobhy Unfollow Follow

    Latest posts made by Ahmed Sobhy

    • Can I backtest or do live paper trading using real spread values using Interactive Broker?

      I need to do backtesting and live paper trading using real spread values. Is that possible?

      posted in General Code/Help
      Ahmed Sobhy
      Ahmed Sobhy
    • What is a reliable way to deploy a trading strategy?

      So I reached a satisfying strategy that I need to deploy. Running it on my computer is not reliable because of unstable internet connection and that it may be turned off. What are your suggestion for deployment?

      posted in General Code/Help
      Ahmed Sobhy
      Ahmed Sobhy
    • How to close a previous order then open a new one in the same tick?
      def next(self):
          if not self.position:
               self.order = self.buy()
          else:
                self.order = self.close()
                # I need here to open a sell position in the same tick
      

      As in the previous code, I need to close the previous buy position then open a new sell one immediately.

      posted in General Code/Help
      Ahmed Sobhy
      Ahmed Sobhy
    • RE: IB Backtesting stuck at status Delayed

      I am requesting history data not real time, shouldn't it work even if the market is closed?

      posted in General Code/Help
      Ahmed Sobhy
      Ahmed Sobhy
    • IB Backtesting stuck at status Delayed

      I get status Delayed and keep stuck, even thought the same code was working a day ago. What could be the cause of this?

      console output:
      Server Version: 76
      TWS Time at connection:20180901 14:19:00 EET
      ***** DATA NOTIF: DELAYED

      from __future__ import (absolute_import, division, print_function,
                              unicode_literals)
      import backtrader as bt
      import datetime
      
      class St(bt.Strategy):
          def logdata(self):
              txt = []
              txt.append('{}'.format(len(self)))
      
              txt.append('{}'.format(
                  self.data.datetime.datetime(0).isoformat())
              )
              txt.append('{:.5f}'.format(self.data.open[0]))
              txt.append('{:.5f}'.format(self.data.high[0]))
              txt.append('{:.5f}'.format(self.data.low[0]))
              txt.append('{:.5f}'.format(self.data.close[0]))
              txt.append('{:.5f}'.format(self.data.volume[0]))
              print(','.join(txt))
      
          def next(self):
              print("here")
              self.logdata()
      
          data_live = False
      
          def notify_data(self, data, status, *args, **kwargs):
              print('*' * 5, 'DATA NOTIF:', data._getstatusname(status),
                    *args)
              if status == data.LIVE:
                  self.data_live = True
      
      
      def run(args=None):
          cerebro = bt.Cerebro(stdstats=False)
          store = bt.stores.IBStore(host='127.0.0.1', port=7497)
          data = store.getdata(dataname='EUR.USD-CASH-IDEALPRO',
                               timeframe=bt.TimeFrame.Ticks, fromdate= datetime.datetime(2017, 1, 1), todate=datetime.datetime(2018, 1, 1))
          cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes,
                               compression=1)
          cerebro.addstrategy(St)
          cerebro.run()
      
      
      if __name__ == '__main__':
          run()
      
      
      posted in General Code/Help
      Ahmed Sobhy
      Ahmed Sobhy
    • RE: NOTSUBSCRIBED Issue

      Is there a way to create an account that is not v20, so it would be compatible?
      Also, what is the status of this repo? Is it still in development or something that I can use?

      posted in General Code/Help
      Ahmed Sobhy
      Ahmed Sobhy
    • NOTSUBSCRIBED Issue

      Hello,

      I am using the sample code below. I get the following output.

      Started
      Account Cash = 0.0
      Account Value = 0.0
      ***** DATA NOTIF: NOTSUBSCRIBED

      made sure that the balance has funds. The api token and account number are correct as I double checked them. What could be the problem?

      
      import argparse
      import datetime
      import backtrader as bt
      
      apikey = 'xxxxxxxx'
      acc = 'yyyyyyyyy'
      
      # Create a Stratey
      class TestStrategy(bt.Strategy):
      
         def __init__(self):
             pass
      
         #Provides any noticficaitons about the data.
         def notify_data(self, data, status, *args, **kwargs):
             print('*' * 5, 'DATA NOTIF:', data._getstatusname(status), *args)
      
         def notify_store(self, msg, *args, **kwargs):
             print('*' * 5, 'STORE NOTIF:', msg)
      
         def next(self):
             # Simply log the closing price of the series from the reference
             print('O: {} H: {} L: {} C: {}'.format(
                     self.data.open[0],
                     self.data.high[0],
                     self.data.low[0],
                     self.data.close[0],
                     ))
      
      
         def start(self):
             if self.data0.contractdetails is not None:
                 print('-- Contract Details:')
                 print(self.data0.contractdetails)
             print('Started')
             acc_cash = cerebro.broker.getcash()
             acc_val = cerebro.broker.getvalue()
             print('Account Cash = {}'.format(acc_cash))
             print('Account Value = {}'.format(acc_val))
      
      
      if __name__ == '__main__':
         cerebro = bt.Cerebro()
         print("apikey", apikey)
         print("acc", acc)
         oandastore = bt.stores.OandaStore(token=apikey, account=acc, practice=True)
         cerebro.broker = oandastore.getbroker()
      
         data0 = oandastore.getdata(dataname="GBP_USD", timeframe=bt.TimeFrame.Ticks, compression=1, backfill_start=False, backfill=False)
      
         #This is setting what timeframe we want to use.
         cerebro.resampledata(data0, timeframe=bt.TimeFrame.Minutes, compression=5)
      
         cerebro.addstrategy(TestStrategy)
         cerebro.run()
      
      posted in General Code/Help
      Ahmed Sobhy
      Ahmed Sobhy