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

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



  • I'm no expert and currently learning bt myself but your entry price is equal to your close price, so something up there, and its closing out the same day as entry



  • @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



  • yep see it now you
    print correct

     print('[ORDER_SEND] SELL >> entry: %.5f tp: %.5f sl: %.5f' %
                      (entry, short_tp, short_sl))
    

    but you pass the buy as

    self.order = self.buy_bracket(
                    price=entry, stopprice=long_tp, limitprice=long_sl)
    

    and the same reverse on your sell and so stop or limit getting hit instantly

    thanks for the code though will help with my understanding of order management