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

Transactions occuring in part increments.



  • My backtest is using ES mini futures which trades in minimum increments of 0.25. All of the historical data is in increments of 0.25.

    However I'm finding trades executing both to buy and sell/close positions that are not at increments of 0.25.

    BUY EXECUTED for ES_Mini, Price: 2886.29, Cost: 2886.29, Comm 0.00
    SELL EXECUTED for ES_Mini, Price: 2888.14, Cost: 2886.29, Comm 0.00
    

    Here are a few more from the transaction indicator.

    20-05-07 11:32	1	2882.79
    20-05-07 11:39	-1	2881.29
    20-05-07 11:43	1	2885.00
    20-05-07 11:56	-1	2889.75
    20-05-07 12:01	1	2894.00
    20-05-07 12:02	-1	2892.00
    20-05-07 12:18	1	2892.63
    20-05-07 12:23	-1	2890.00
    20-05-07 13:33	1	2888.75
    20-05-07 13:36	-1	2886.50
    20-05-07 14:13	1	2885.56
    20-05-07 14:20	-1	2883.16
    

    And a couple from @ab_trader trade list...

    15	ES_Mini	long	2020-05-01 10:50	2,852.72	2020-05-01 10:54	2,849.00	-13%	-4	-4%	1	2,853	-28	4	-1	4%	-16%
    16	ES_Mini	long	2020-05-01 14:20	2,818.47	2020-05-01 14:31	2,821.25	10%	3	3%	1	2,818	-25	11	0	22%	-3%
    

    Is there a reason backtrader is trading in part increments and/or can I set minimum increments for trading?

    Thanks :)



  • Do you use slippage? limit or stop orders?



  • @ab_trader Yes I was using both. I added in these two functions and they solved the problem.

        def round_down(self, x):
            return math.trunc(x * 4) / 4
    
        def round_up(self, x):
            return math.ceil(x * 4) / 4
    
    

    Using like this.

    self.long_buy_order = self.buy(
                        exectype=bt.Order.Stop,
                        price=self.round_up(self.psar[-1]),
                        valid=valid1,
                        transmit=False,
                    )
    
    # and
    self.long_stop_order = self.sell(
                    exectype=bt.Order.Stop,
                    price=self.round_down(stopprice),
                    parent=self.long_buy_order,
                    transmit=True,
                )
    
    


  • That is common for trading tools that end user should maintain the correct price steps and prices for limit and stop orders.


Log in to reply
 

});