For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Cancel Repeated Order When Multiple DataFeed



  • I am using two datafeed one of minute basis and one of daily basis. I am generating signals(buy-sell) using only minute data feed and daily data feed is for other analysis.
    So when my model generates signal at the starting time of day or at the closing time of day same signal gets generated twice with different Order Ref.(Because at the starting time or closing time of day it account the information of daily data as well and thus it generates same signal twice).
    I want to avoid this. How can I do it ?

    Example:
    I am using two data feeds like this:

               data0 = bt.feeds.GenericCSVData(dataname=inFilePath0,
                                               fromdate=self.startDate,
                                               todate=self.endDate,
                                               datetime=0,
                                               open=1,
                                               high=2,
                                               low=3,
                                               close=4,
                                               volume=5,
                                               openinterest=-1,
                                               timeframe=bt.TimeFrame.Ticks,
                                               dtformat="%m/%d/%Y %H:%M",  
                                               tmformat='%H:%M'
                                               )
    
               # Resample the data
               backtester.resampledata(
                   dataname=data0,
                   timeframe=timeFrameInfo.tframes[timeframe],
                   compression=compression)
    
               # Add Daily Data
               data1 = bt.feeds.GenericCSVData(dataname=inFilePath0,
                                               fromdate=self.startDate,
                                               todate=self.endDate,
                                               datetime=0,
                                               open=1,
                                               high=2,
                                               low=3,
                                               close=4,
                                               volume=5,
                                               openinterest=-1,
                                               timeframe=bt.TimeFrame.Ticks,
                                               dtformat="%m/%d/%Y %H:%M",  
                                               tmformat='%H:%M',
                                               )
    
               # Resample the data
               backtester.resampledata(
                   dataname=data1,
                   timeframe=timeFrameInfo.tframes["daily"],
                   compression=1)
    

    After run i got this:

    Starting Portfolio Value: 100000000.00
    2010-03-16 - 15:30:00, BUY CREATE, Market Order, Price: 5210.00
    2010-03-16 - 15:30:00, BUY CREATE, Market Order, Price: 5210.00
    2010-03-17 - 09:10:00, REF : 1  PRICE : 5229.000  SIZE : 75.00  COMM : 187.50
    2010-03-17 - 09:10:00, REF : 2  PRICE : 5229.000  SIZE : 75.00  COMM : 187.50
    

    So same order is generating twice. But when I remove the daily data feed there is no problem
    @backtrader


  • administrators

    The orders have different Ref numbers, and the log shows two (2) orders being generated.

    How you add the data feeds is irrelevant. What's relevant is what you do to generate the orders, which is your problem.



  • @backtrader
    I am using this way to generate order:

                  def next(self):
                           if self.p.exectype == 'Market':
                               self.buy(exectype=bt.Order.Market, valid=valid) 
                               self.log('BUY CREATE, Market Order, Price: %.2f' % self.data0.close[0])
    

  • administrators

    Sincerely: do you really expect anyone to understand why you generate two orders with those 3 lines?

    But let's give it a go

    • You don't understand that when using multiple timeframes your next will tick multiple times for the same asset in the larger timeframe and you blindly generate multiple orders.


  • @backtrader Is there any way that next method will only run for a particular timeframe, or more specifically can I create order only for a specific timeframe data.
    Actually I found this in the def that we can mention data in data=None option. But still it issues order for other timeframes as well.

    def buy(self, data=None,
              size=None, price=None, plimit=None,
              exectype=None, valid=None, tradeid=0, oco=None,
              trailamount=None, trailpercent=None,
              parent=None, transmit=True,
              **kwargs)
    

  • administrators

    @ry-93 said in Cancel Repeated Order When Multiple DataFeed:

    Is there any way that next method will only run for a particular timeframe

    No. You can decide to which ticks to listen to by checking the length of the data (if it has changed from the last time you saw it)

    @ry-93 said in Cancel Repeated Order When Multiple DataFeed:

    can I create order only for a specific timeframe data

    The orders (and the methods that create them) don't know about timeframes. The system doesn't care if the data feeds with different timeframes actually originate from another data in the system which happens to have a different timeframe.

    You create orders from specific data targets with the data=x parameter.

    @ry-93 said in Cancel Repeated Order When Multiple DataFeed:

    Actually I found this in the def that we can mention data in data=None option. But still it issues order for other timeframes as well.

    Not it doesn't issue orders for other timeframes as well. It issues an order for the specific data feed you specify. If you don't specify any (i.e.: data=None), it will use the 1st data added to the system, where the rationale is: most people do actually only use one feed and don't have to waste time specifying a target.

    The buy and sell methods are documented.



  • @backtrader Thanks.
    You are right @backtrader , multiple orders were coming for the same timeframe data. Actually I haven't added the session end time during dataread , so when any order created at the end-time of the trading day it gets created twice.