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

Multiple consecutive buy signals implementation and issue of profit with only buys



    1. Consecutive buys - In all posts and code snippets I have seen in the documentation I have seen the check 'if not self.position' before buying. But is it possible to make consecutive buy orders if strategy says to. Then I would like to sell all them at once, when the strategy says so. For now I am storing all 'buy' orders in a queue and then calling multiple times sell(), on 'sell' signal. But it doesn't seem right since it wouldn't know at what price it was bought.
    2. Also I noticed profits when there is no transaction at all or even with only buys - I have a Deep Learning model which trains on 5 yrs data and predicts on next 1 yr data. I send this array of prediction and data to 'Strategy' class and call buy or sell or no action (hold) based on predictions. But I have noticed that even if my model predicts only hold through out 1 year and there is no buy/sell as per logs (or even if there is only buy execution), I see profits at the end!
      Let me know if you any further clarity.

    Below are code snippets:

    # initialization
        cerebro = bt.Cerebro()
        cerebro.addstrategy(BackTestStrategy, y_pred_class=y_pred_class, timestamps=timestamps, logger=logger)
        data = bt.feeds.PandasData(dataname=df,
                        datetime=0,
                        open=1,
                        high=2,
                        low=3,
                        close=4
                        # volume=-1
                        )
        cerebro.adddata(data)
        cerebro.broker.setcash(10000.0)
        # Add a FixedSize sizer according to the stake
        # cerebro.addsizer(bt.sizers.FixedSize, stake=1)
        cerebro.broker.setcommission(commission=0.1/100)
        return cerebro
    
    def __init__(self):
            self.dataclose = self.datas[0].close  # data added to cerebro
            self.orders_buy = deque([])
            self.orders_sell = deque([])
            self.buyprice = None
            self.buycomm = None
            self.y_pred_class = self.params.y_pred_class
            self.logger = self.params.logger
            self.timestamps = self.params.timestamps 
            self.count = 0
            self.log("size of test data {}".format(len(self.y_pred_class)))
            self.dates_ = self.datas[0].datetime
            self.order_skip_count = 0
            self.order = None
    
    def next(self):
            # self.log('Close, %.2f' % self.dataclose[0])
            self.log("count: {}, date: {}, {}, close_price: {}".format(self.count, self.dates_.date(0) , self.timestamps.iloc[self.count], self.dataclose[0]))
    
            # Check if an order is pending ... if yes, we cannot send a 2nd one
            if self.order:
                self.order_skip_count = self.order_skip_count + 1
                self.log("Pending order. skipping.. {}".format(self.order_skip_count))
                self.count = self.count + 1
                return
    
            # Check if we are in the market
            # if not self.position:
            if self.y_pred_class[self.count] == 1:
                self.log('BUY CREATE, %.2f' % self.dataclose[0])
                self.orders_buy.append(self.buy())
                self.order = self.orders_buy[-1]
            # else:
            elif self.y_pred_class[self.count] == 0:
                if self.position:
                    self.log('SELL CREATE, %.2f' % self.dataclose[0])
                    while len(self.orders_buy) > 0:
                        self.orders_buy.popleft()
                        self.order = self.sell()
                        # self.orders_sell.append(self.sell())
                    # self.order = self.orders_sell[-1]
                else:
                    self.logger.append_log("No shares bought to sell. skipping SELL")
            # else:
                # hold
            self.count = self.count + 1
    

  • administrators

    @trader911 said in Multiple consecutive buy signals implementation and issue of profit with only buys:

    In all posts and code snippets I have seen in the documentation I have seen the check 'if not self.position' before buying.

    That's for sure not in all samples. It is simply that most people once in the market will look to exit and not to increase the position. Nothing prevents you from removing that and controlling your entry/exit points in a different manner.

    @trader911 said in Multiple consecutive buy signals implementation and issue of profit with only buys:

    But is it possible to make consecutive buy orders if strategy says to

    Why shouldn't it be possible? Do it. If you have $1M you can for sure issue 1 million consecutive buy for $1 each (you will of course need data with at least 1 million data points)

    @trader911 said in Multiple consecutive buy signals implementation and issue of profit with only buys:

    then calling multiple times sell(), on 'sell' signal. But it doesn't seem right since it wouldn't know at what price it was bought.

    I don't know what you mean, but in any case the actual matching price for earch order is notified in notify_order when the order is executed.

    @trader911 said in Multiple consecutive buy signals implementation and issue of profit with only buys:

    Also I noticed profits when there is no transaction at all or even with only buys

    You have then wrongly noticed.

    @trader911 said in Multiple consecutive buy signals implementation and issue of profit with only buys:

    But I have noticed that even if my model predicts only hold through out 1 year and there is no buy/sell as per logs (or even if there is only buy execution), I see profits at the end!

    Easy. Load data, let it run through an empty strategy and let us know if you notice any profits. If the profits show up when adding your code, you know the drill.



  • @backtrader

    1. Glad to get a confirmation from you that consecutive buys are possible on your platform. Idea is to test my model's decision as much as possible, instead of skipping just because I have already bought shares. That said, I was expecting some guidance as to how can one implement it. Let's say I have bought twice. Now when I call self.sell() what happens? Does the system sell all the orders or the last order? To get around that I thought I would store all the buy orders and sell them all at once but "order" object has no sell function.. right? So what would be the ideal way that you would suggest? Also you said "That's for sure not in all samples", do you have any links where this requirement has been achieved?

    2. Below is the log that was printed. Which showed profit with one buy.

    25-08-2019 20_03_44 MainThread DEBUG\ Starting Portfolio Value: 10000.00
    25-08-2019 20_03_44 MainThread DEBUG\ size of test data 225
    25-08-2019 20_03_44 MainThread DEBUG\ count: 0, date: 2018-10-02, 2018-10-02 00:00:00, close_price: 1207.64
    25-08-2019 20_03_44 MainThread DEBUG\ count: 1, date: 2018-10-03, 2018-10-03 00:00:00, close_price: 1211.53
    25-08-2019 20_03_44 MainThread DEBUG\ count: 2, date: 2018-10-04, 2018-10-04 00:00:00, close_price: 1177.07
    25-08-2019 20_03_44 MainThread DEBUG\ count: 3, date: 2018-10-05, 2018-10-05 00:00:00, close_price: 1167.83
    25-08-2019 20_03_44 MainThread DEBUG\ count: 4, date: 2018-10-08, 2018-10-08 00:00:00, close_price: 1155.92
    25-08-2019 20_03_44 MainThread DEBUG\ count: 5, date: 2018-10-09, 2018-10-09 00:00:00, close_price: 1145.17
    25-08-2019 20_03_44 MainThread DEBUG\ count: 6, date: 2018-10-10, 2018-10-10 00:00:00, close_price: 1092.16
    25-08-2019 20_03_44 MainThread DEBUG\ count: 7, date: 2018-10-11, 2018-10-11 00:00:00, close_price: 1090.74
    25-08-2019 20_03_44 MainThread DEBUG\ count: 8, date: 2018-10-12, 2018-10-12 00:00:00, close_price: 1120.54
    25-08-2019 20_03_44 MainThread DEBUG\ count: 9, date: 2018-10-15, 2018-10-15 00:00:00, close_price: 1102.44
    25-08-2019 20_03_44 MainThread DEBUG\ count: 10, date: 2018-10-16, 2018-10-16 00:00:00, close_price: 1133.08
    25-08-2019 20_03_44 MainThread DEBUG\ count: 11, date: 2018-10-17, 2018-10-17 00:00:00, close_price: 1127.59
    25-08-2019 20_03_44 MainThread DEBUG\ count: 12, date: 2018-10-18, 2018-10-18 00:00:00, close_price: 1097.91
    25-08-2019 20_03_44 MainThread DEBUG\ count: 13, date: 2018-10-19, 2018-10-19 00:00:00, close_price: 1105.18
    25-08-2019 20_03_44 MainThread DEBUG\ count: 14, date: 2018-10-22, 2018-10-22 00:00:00, close_price: 1111.37
    25-08-2019 20_03_44 MainThread DEBUG\ count: 15, date: 2018-10-23, 2018-10-23 00:00:00, close_price: 1114.91
    25-08-2019 20_03_44 MainThread DEBUG\ count: 16, date: 2018-10-24, 2018-10-24 00:00:00, close_price: 1057.12
    25-08-2019 20_03_44 MainThread DEBUG\ count: 17, date: 2018-10-25, 2018-10-25 00:00:00, close_price: 1103.59
    25-08-2019 20_03_44 MainThread DEBUG\ count: 18, date: 2018-10-26, 2018-10-26 00:00:00, close_price: 1083.75
    25-08-2019 20_03_44 MainThread DEBUG\ count: 19, date: 2018-10-29, 2018-10-29 00:00:00, close_price: 1034.73
    25-08-2019 20_03_44 MainThread DEBUG\ count: 20, date: 2018-10-30, 2018-10-30 00:00:00, close_price: 1049.51
    25-08-2019 20_03_44 MainThread DEBUG\ count: 21, date: 2018-10-31, 2018-10-31 00:00:00, close_price: 1090.58
    25-08-2019 20_03_44 MainThread DEBUG\ count: 22, date: 2018-11-01, 2018-11-01 00:00:00, close_price: 1085.98
    25-08-2019 20_03_44 MainThread DEBUG\ count: 23, date: 2018-11-02, 2018-11-02 00:00:00, close_price: 1071.49
    25-08-2019 20_03_44 MainThread DEBUG\ count: 24, date: 2018-11-05, 2018-11-05 00:00:00, close_price: 1055.73
    25-08-2019 20_03_44 MainThread DEBUG\ count: 25, date: 2018-11-06, 2018-11-06 00:00:00, close_price: 1069.57
    25-08-2019 20_03_44 MainThread DEBUG\ count: 26, date: 2018-11-07, 2018-11-07 00:00:00, close_price: 1108.24
    25-08-2019 20_03_44 MainThread DEBUG\ count: 27, date: 2018-11-08, 2018-11-08 00:00:00, close_price: 1094.63
    25-08-2019 20_03_44 MainThread DEBUG\ count: 28, date: 2018-11-09, 2018-11-09 00:00:00, close_price: 1077.02
    25-08-2019 20_03_44 MainThread DEBUG\ count: 29, date: 2018-11-12, 2018-11-12 00:00:00, close_price: 1049.36
    25-08-2019 20_03_44 MainThread DEBUG\ count: 30, date: 2018-11-13, 2018-11-13 00:00:00, close_price: 1047.97
    25-08-2019 20_03_44 MainThread DEBUG\ count: 31, date: 2018-11-14, 2018-11-14 00:00:00, close_price: 1054.58
    25-08-2019 20_03_44 MainThread DEBUG\ count: 32, date: 2018-11-15, 2018-11-15 00:00:00, close_price: 1071.05
    25-08-2019 20_03_44 MainThread DEBUG\ count: 33, date: 2018-11-16, 2018-11-16 00:00:00, close_price: 1068.27
    25-08-2019 20_03_44 MainThread DEBUG\ count: 34, date: 2018-11-19, 2018-11-19 00:00:00, close_price: 1027.42
    25-08-2019 20_03_44 MainThread DEBUG\ count: 35, date: 2018-11-20, 2018-11-20 00:00:00, close_price: 1030.45
    25-08-2019 20_03_44 MainThread DEBUG\ count: 36, date: 2018-11-21, 2018-11-21 00:00:00, close_price: 1043.43
    25-08-2019 20_03_44 MainThread DEBUG\ count: 37, date: 2018-11-23, 2018-11-23 00:00:00, close_price: 1030.1
    25-08-2019 20_03_44 MainThread DEBUG\ count: 38, date: 2018-11-26, 2018-11-26 00:00:00, close_price: 1055.94
    25-08-2019 20_03_44 MainThread DEBUG\ count: 39, date: 2018-11-27, 2018-11-27 00:00:00, close_price: 1052.28
    25-08-2019 20_03_44 MainThread DEBUG\ count: 40, date: 2018-11-28, 2018-11-28 00:00:00, close_price: 1091.79
    25-08-2019 20_03_44 MainThread DEBUG\ count: 41, date: 2018-11-29, 2018-11-29 00:00:00, close_price: 1094.58
    25-08-2019 20_03_44 MainThread DEBUG\ count: 42, date: 2018-11-30, 2018-11-30 00:00:00, close_price: 1109.65
    25-08-2019 20_03_44 MainThread DEBUG\ count: 43, date: 2018-12-03, 2018-12-03 00:00:00, close_price: 1116.36
    25-08-2019 20_03_44 MainThread DEBUG\ count: 44, date: 2018-12-04, 2018-12-04 00:00:00, close_price: 1062.47
    25-08-2019 20_03_44 MainThread DEBUG\ count: 45, date: 2018-12-06, 2018-12-06 00:00:00, close_price: 1078.08
    25-08-2019 20_03_44 MainThread DEBUG\ count: 46, date: 2018-12-07, 2018-12-07 00:00:00, close_price: 1046.58
    25-08-2019 20_03_44 MainThread DEBUG\ count: 47, date: 2018-12-10, 2018-12-10 00:00:00, close_price: 1053.18
    25-08-2019 20_03_44 MainThread DEBUG\ count: 48, date: 2018-12-11, 2018-12-11 00:00:00, close_price: 1061.65
    25-08-2019 20_03_44 MainThread DEBUG\ count: 49, date: 2018-12-12, 2018-12-12 00:00:00, close_price: 1073.73
    25-08-2019 20_03_44 MainThread DEBUG\ count: 50, date: 2018-12-13, 2018-12-13 00:00:00, close_price: 1073.54
    25-08-2019 20_03_44 MainThread DEBUG\ count: 51, date: 2018-12-14, 2018-12-14 00:00:00, close_price: 1051.71
    25-08-2019 20_03_44 MainThread DEBUG\ count: 52, date: 2018-12-17, 2018-12-17 00:00:00, close_price: 1025.65
    25-08-2019 20_03_44 MainThread DEBUG\ count: 53, date: 2018-12-18, 2018-12-18 00:00:00, close_price: 1043.41
    25-08-2019 20_03_44 MainThread DEBUG\ count: 54, date: 2018-12-19, 2018-12-19 00:00:00, close_price: 1035.46
    25-08-2019 20_03_44 MainThread DEBUG\ count: 55, date: 2018-12-20, 2018-12-20 00:00:00, close_price: 1023.58
    25-08-2019 20_03_44 MainThread DEBUG\ count: 56, date: 2018-12-21, 2018-12-21 00:00:00, close_price: 991.25
    25-08-2019 20_03_44 MainThread DEBUG\ count: 57, date: 2018-12-24, 2018-12-24 00:00:00, close_price: 984.67
    25-08-2019 20_03_44 MainThread DEBUG\ count: 58, date: 2018-12-26, 2018-12-26 00:00:00, close_price: 1047.85
    25-08-2019 20_03_44 MainThread DEBUG\ count: 59, date: 2018-12-27, 2018-12-27 00:00:00, close_price: 1052.9
    25-08-2019 20_03_44 MainThread DEBUG\ count: 60, date: 2018-12-28, 2018-12-28 00:00:00, close_price: 1046.68
    25-08-2019 20_03_44 MainThread DEBUG\ count: 61, date: 2018-12-31, 2018-12-31 00:00:00, close_price: 1044.96
    25-08-2019 20_03_44 MainThread DEBUG\ BUY CREATE, 1044.96
    25-08-2019 20_03_44 MainThread DEBUG\ BUY EXECUTED, Price: 1027.20, Cost: 1027.20, Comm 1.03
    25-08-2019 20_03_44 MainThread DEBUG\ count: 62, date: 2019-01-02, 2019-01-02 00:00:00, close_price: 1054.68
    25-08-2019 20_03_44 MainThread DEBUG\ count: 63, date: 2019-01-03, 2019-01-03 00:00:00, close_price: 1025.47
    25-08-2019 20_03_44 MainThread DEBUG\ count: 64, date: 2019-01-04, 2019-01-04 00:00:00, close_price: 1078.07
    25-08-2019 20_03_44 MainThread DEBUG\ count: 65, date: 2019-01-07, 2019-01-07 00:00:00, close_price: 1075.92
    25-08-2019 20_03_44 MainThread DEBUG\ count: 66, date: 2019-01-08, 2019-01-08 00:00:00, close_price: 1085.37
    25-08-2019 20_03_44 MainThread DEBUG\ count: 67, date: 2019-01-09, 2019-01-09 00:00:00, close_price: 1081.65
    25-08-2019 20_03_44 MainThread DEBUG\ count: 68, date: 2019-01-10, 2019-01-10 00:00:00, close_price: 1078.83
    25-08-2019 20_03_44 MainThread DEBUG\ count: 69, date: 2019-01-11, 2019-01-11 00:00:00, close_price: 1064.47
    25-08-2019 20_03_44 MainThread DEBUG\ count: 70, date: 2019-01-14, 2019-01-14 00:00:00, close_price: 1051.51
    25-08-2019 20_03_44 MainThread DEBUG\ count: 71, date: 2019-01-15, 2019-01-15 00:00:00, close_price: 1086.51
    25-08-2019 20_03_44 MainThread DEBUG\ count: 72, date: 2019-01-16, 2019-01-16 00:00:00, close_price: 1089.51
    25-08-2019 20_03_44 MainThread DEBUG\ count: 73, date: 2019-01-17, 2019-01-17 00:00:00, close_price: 1099.12
    25-08-2019 20_03_44 MainThread DEBUG\ count: 74, date: 2019-01-18, 2019-01-18 00:00:00, close_price: 1107.3
    25-08-2019 20_03_44 MainThread DEBUG\ count: 75, date: 2019-01-22, 2019-01-22 00:00:00, close_price: 1078.63
    25-08-2019 20_03_44 MainThread DEBUG\ count: 76, date: 2019-01-23, 2019-01-23 00:00:00, close_price: 1084.41
    25-08-2019 20_03_44 MainThread DEBUG\ count: 77, date: 2019-01-24, 2019-01-24 00:00:00, close_price: 1084.0
    25-08-2019 20_03_44 MainThread DEBUG\ count: 78, date: 2019-01-25, 2019-01-25 00:00:00, close_price: 1101.51
    25-08-2019 20_03_44 MainThread DEBUG\ count: 79, date: 2019-01-28, 2019-01-28 00:00:00, close_price: 1079.86
    25-08-2019 20_03_44 MainThread DEBUG\ count: 80, date: 2019-01-29, 2019-01-29 00:00:00, close_price: 1070.06
    25-08-2019 20_03_44 MainThread DEBUG\ count: 81, date: 2019-01-30, 2019-01-30 00:00:00, close_price: 1097.99
    25-08-2019 20_03_44 MainThread DEBUG\ count: 82, date: 2019-01-31, 2019-01-31 00:00:00, close_price: 1125.89
    25-08-2019 20_03_44 MainThread DEBUG\ count: 83, date: 2019-02-01, 2019-02-01 00:00:00, close_price: 1118.62
    25-08-2019 20_03_44 MainThread DEBUG\ count: 84, date: 2019-02-04, 2019-02-04 00:00:00, close_price: 1141.42
    25-08-2019 20_03_44 MainThread DEBUG\ count: 85, date: 2019-02-05, 2019-02-05 00:00:00, close_price: 1151.87
    25-08-2019 20_03_44 MainThread DEBUG\ count: 86, date: 2019-02-06, 2019-02-06 00:00:00, close_price: 1122.89
    25-08-2019 20_03_44 MainThread DEBUG\ count: 87, date: 2019-02-07, 2019-02-07 00:00:00, close_price: 1105.91
    25-08-2019 20_03_44 MainThread DEBUG\ count: 88, date: 2019-02-08, 2019-02-08 00:00:00, close_price: 1102.38
    25-08-2019 20_03_44 MainThread DEBUG\ count: 89, date: 2019-02-11, 2019-02-11 00:00:00, close_price: 1102.12
    25-08-2019 20_03_44 MainThread DEBUG\ count: 90, date: 2019-02-12, 2019-02-12 00:00:00, close_price: 1127.58
    25-08-2019 20_03_44 MainThread DEBUG\ count: 91, date: 2019-02-13, 2019-02-13 00:00:00, close_price: 1128.63
    25-08-2019 20_03_44 MainThread DEBUG\ count: 92, date: 2019-02-14, 2019-02-14 00:00:00, close_price: 1129.2
    25-08-2019 20_03_44 MainThread DEBUG\ count: 93, date: 2019-02-15, 2019-02-15 00:00:00, close_price: 1119.63
    25-08-2019 20_03_44 MainThread DEBUG\ count: 94, date: 2019-02-19, 2019-02-19 00:00:00, close_price: 1126.51
    25-08-2019 20_03_44 MainThread DEBUG\ count: 95, date: 2019-02-20, 2019-02-20 00:00:00, close_price: 1120.59
    25-08-2019 20_03_44 MainThread DEBUG\ count: 96, date: 2019-02-21, 2019-02-21 00:00:00, close_price: 1104.21
    25-08-2019 20_03_44 MainThread DEBUG\ count: 97, date: 2019-02-22, 2019-02-22 00:00:00, close_price: 1116.56
    25-08-2019 20_03_44 MainThread DEBUG\ count: 98, date: 2019-02-25, 2019-02-25 00:00:00, close_price: 1117.33
    25-08-2019 20_03_44 MainThread DEBUG\ count: 99, date: 2019-02-26, 2019-02-26 00:00:00, close_price: 1122.01
    25-08-2019 20_03_44 MainThread DEBUG\ count: 100, date: 2019-02-27, 2019-02-27 00:00:00, close_price: 1122.89
    25-08-2019 20_03_44 MainThread DEBUG\ count: 101, date: 2019-02-28, 2019-02-28 00:00:00, close_price: 1126.55
    25-08-2019 20_03_44 MainThread DEBUG\ count: 102, date: 2019-03-01, 2019-03-01 00:00:00, close_price: 1148.52
    25-08-2019 20_03_44 MainThread DEBUG\ count: 103, date: 2019-03-04, 2019-03-04 00:00:00, close_price: 1153.42
    25-08-2019 20_03_44 MainThread DEBUG\ count: 104, date: 2019-03-05, 2019-03-05 00:00:00, close_price: 1169.19
    25-08-2019 20_03_44 MainThread DEBUG\ count: 105, date: 2019-03-06, 2019-03-06 00:00:00, close_price: 1164.94
    25-08-2019 20_03_44 MainThread DEBUG\ count: 106, date: 2019-03-07, 2019-03-07 00:00:00, close_price: 1150.85
    25-08-2019 20_03_44 MainThread DEBUG\ count: 107, date: 2019-03-08, 2019-03-08 00:00:00, close_price: 1149.97
    25-08-2019 20_03_44 MainThread DEBUG\ count: 108, date: 2019-03-11, 2019-03-11 00:00:00, close_price: 1179.26
    25-08-2019 20_03_44 MainThread DEBUG\ count: 109, date: 2019-03-12, 2019-03-12 00:00:00, close_price: 1197.25
    25-08-2019 20_03_44 MainThread DEBUG\ count: 110, date: 2019-03-13, 2019-03-13 00:00:00, close_price: 1199.06
    25-08-2019 20_03_44 MainThread DEBUG\ count: 111, date: 2019-03-14, 2019-03-14 00:00:00, close_price: 1192.53
    25-08-2019 20_03_44 MainThread DEBUG\ count: 112, date: 2019-03-15, 2019-03-15 00:00:00, close_price: 1190.3
    25-08-2019 20_03_44 MainThread DEBUG\ count: 113, date: 2019-03-18, 2019-03-18 00:00:00, close_price: 1188.55
    25-08-2019 20_03_44 MainThread DEBUG\ count: 114, date: 2019-03-19, 2019-03-19 00:00:00, close_price: 1202.46
    25-08-2019 20_03_44 MainThread DEBUG\ count: 115, date: 2019-03-20, 2019-03-20 00:00:00, close_price: 1226.43
    25-08-2019 20_03_44 MainThread DEBUG\ count: 116, date: 2019-03-21, 2019-03-21 00:00:00, close_price: 1236.13
    25-08-2019 20_03_44 MainThread DEBUG\ count: 117, date: 2019-03-22, 2019-03-22 00:00:00, close_price: 1207.65
    25-08-2019 20_03_44 MainThread DEBUG\ count: 118, date: 2019-03-25, 2019-03-25 00:00:00, close_price: 1197.38
    25-08-2019 20_03_44 MainThread DEBUG\ count: 119, date: 2019-03-26, 2019-03-26 00:00:00, close_price: 1189.84
    25-08-2019 20_03_44 MainThread DEBUG\ count: 120, date: 2019-03-27, 2019-03-27 00:00:00, close_price: 1178.01
    25-08-2019 20_03_44 MainThread DEBUG\ count: 121, date: 2019-03-28, 2019-03-28 00:00:00, close_price: 1172.27
    25-08-2019 20_03_44 MainThread DEBUG\ count: 122, date: 2019-03-29, 2019-03-29 00:00:00, close_price: 1176.89
    25-08-2019 20_03_44 MainThread DEBUG\ count: 123, date: 2019-04-01, 2019-04-01 00:00:00, close_price: 1198.98
    25-08-2019 20_03_44 MainThread DEBUG\ count: 124, date: 2019-04-02, 2019-04-02 00:00:00, close_price: 1205.54
    25-08-2019 20_03_44 MainThread DEBUG\ count: 125, date: 2019-04-03, 2019-04-03 00:00:00, close_price: 1210.81
    25-08-2019 20_03_44 MainThread DEBUG\ count: 126, date: 2019-04-04, 2019-04-04 00:00:00, close_price: 1219.45
    25-08-2019 20_03_44 MainThread DEBUG\ count: 127, date: 2019-04-05, 2019-04-05 00:00:00, close_price: 1211.45
    25-08-2019 20_03_44 MainThread DEBUG\ count: 128, date: 2019-04-08, 2019-04-08 00:00:00, close_price: 1208.28
    25-08-2019 20_03_44 MainThread DEBUG\ count: 129, date: 2019-04-09, 2019-04-09 00:00:00, close_price: 1202.69
    25-08-2019 20_03_44 MainThread DEBUG\ count: 130, date: 2019-04-10, 2019-04-10 00:00:00, close_price: 1206.45
    25-08-2019 20_03_44 MainThread DEBUG\ count: 131, date: 2019-04-11, 2019-04-11 00:00:00, close_price: 1209.59
    25-08-2019 20_03_44 MainThread DEBUG\ count: 132, date: 2019-04-12, 2019-04-12 00:00:00, close_price: 1222.73
    25-08-2019 20_03_44 MainThread DEBUG\ count: 133, date: 2019-04-15, 2019-04-15 00:00:00, close_price: 1226.53
    25-08-2019 20_03_44 MainThread DEBUG\ count: 134, date: 2019-04-16, 2019-04-16 00:00:00, close_price: 1231.91
    25-08-2019 20_03_44 MainThread DEBUG\ count: 135, date: 2019-04-17, 2019-04-17 00:00:00, close_price: 1240.14
    25-08-2019 20_03_44 MainThread DEBUG\ count: 136, date: 2019-04-18, 2019-04-18 00:00:00, close_price: 1241.47
    25-08-2019 20_03_44 MainThread DEBUG\ count: 137, date: 2019-04-22, 2019-04-22 00:00:00, close_price: 1253.76
    25-08-2019 20_03_44 MainThread DEBUG\ count: 138, date: 2019-04-23, 2019-04-23 00:00:00, close_price: 1270.59
    25-08-2019 20_03_44 MainThread DEBUG\ count: 139, date: 2019-04-24, 2019-04-24 00:00:00, close_price: 1260.05
    25-08-2019 20_03_44 MainThread DEBUG\ count: 140, date: 2019-04-25, 2019-04-25 00:00:00, close_price: 1267.34
    25-08-2019 20_03_44 MainThread DEBUG\ count: 141, date: 2019-04-26, 2019-04-26 00:00:00, close_price: 1277.42
    25-08-2019 20_03_44 MainThread DEBUG\ count: 142, date: 2019-04-29, 2019-04-29 00:00:00, close_price: 1296.2
    25-08-2019 20_03_44 MainThread DEBUG\ count: 143, date: 2019-04-30, 2019-04-30 00:00:00, close_price: 1198.96
    25-08-2019 20_03_44 MainThread DEBUG\ count: 144, date: 2019-05-01, 2019-05-01 00:00:00, close_price: 1173.32
    25-08-2019 20_03_44 MainThread DEBUG\ count: 145, date: 2019-05-02, 2019-05-02 00:00:00, close_price: 1166.51
    25-08-2019 20_03_44 MainThread DEBUG\ count: 146, date: 2019-05-03, 2019-05-03 00:00:00, close_price: 1189.55
    25-08-2019 20_03_44 MainThread DEBUG\ count: 147, date: 2019-05-06, 2019-05-06 00:00:00, close_price: 1193.46
    25-08-2019 20_03_44 MainThread DEBUG\ count: 148, date: 2019-05-07, 2019-05-07 00:00:00, close_price: 1178.86
    25-08-2019 20_03_44 MainThread DEBUG\ count: 149, date: 2019-05-08, 2019-05-08 00:00:00, close_price: 1170.78
    25-08-2019 20_03_44 MainThread DEBUG\ count: 150, date: 2019-05-09, 2019-05-09 00:00:00, close_price: 1167.97
    25-08-2019 20_03_44 MainThread DEBUG\ count: 151, date: 2019-05-10, 2019-05-10 00:00:00, close_price: 1167.64
    25-08-2019 20_03_44 MainThread DEBUG\ count: 152, date: 2019-05-13, 2019-05-13 00:00:00, close_price: 1136.59
    25-08-2019 20_03_44 MainThread DEBUG\ count: 153, date: 2019-05-14, 2019-05-14 00:00:00, close_price: 1124.86
    25-08-2019 20_03_44 MainThread DEBUG\ count: 154, date: 2019-05-15, 2019-05-15 00:00:00, close_price: 1170.8
    25-08-2019 20_03_44 MainThread DEBUG\ count: 155, date: 2019-05-16, 2019-05-16 00:00:00, close_price: 1184.5
    25-08-2019 20_03_44 MainThread DEBUG\ count: 156, date: 2019-05-17, 2019-05-17 00:00:00, close_price: 1168.78
    25-08-2019 20_03_44 MainThread DEBUG\ count: 157, date: 2019-05-20, 2019-05-20 00:00:00, close_price: 1144.66
    25-08-2019 20_03_44 MainThread DEBUG\ count: 158, date: 2019-05-21, 2019-05-21 00:00:00, close_price: 1154.44
    25-08-2019 20_03_44 MainThread DEBUG\ count: 159, date: 2019-05-22, 2019-05-22 00:00:00, close_price: 1155.85
    25-08-2019 20_03_44 MainThread DEBUG\ count: 160, date: 2019-05-23, 2019-05-23 00:00:00, close_price: 1145.34
    25-08-2019 20_03_44 MainThread DEBUG\ count: 161, date: 2019-05-24, 2019-05-24 00:00:00, close_price: 1138.61
    25-08-2019 20_03_44 MainThread DEBUG\ count: 162, date: 2019-05-28, 2019-05-28 00:00:00, close_price: 1139.56
    25-08-2019 20_03_44 MainThread DEBUG\ count: 163, date: 2019-05-29, 2019-05-29 00:00:00, close_price: 1119.94
    25-08-2019 20_03_44 MainThread DEBUG\ count: 164, date: 2019-05-30, 2019-05-30 00:00:00, close_price: 1121.41
    25-08-2019 20_03_44 MainThread DEBUG\ count: 165, date: 2019-05-31, 2019-05-31 00:00:00, close_price: 1106.5
    25-08-2019 20_03_44 MainThread DEBUG\ count: 166, date: 2019-06-03, 2019-06-03 00:00:00, close_price: 1038.74
    25-08-2019 20_03_44 MainThread DEBUG\ count: 167, date: 2019-06-04, 2019-06-04 00:00:00, close_price: 1054.49
    25-08-2019 20_03_44 MainThread DEBUG\ count: 168, date: 2019-06-05, 2019-06-05 00:00:00, close_price: 1044.64
    25-08-2019 20_03_44 MainThread DEBUG\ count: 169, date: 2019-06-06, 2019-06-06 00:00:00, close_price: 1047.76
    25-08-2019 20_03_44 MainThread DEBUG\ count: 170, date: 2019-06-07, 2019-06-07 00:00:00, close_price: 1068.37
    25-08-2019 20_03_44 MainThread DEBUG\ count: 171, date: 2019-06-10, 2019-06-10 00:00:00, close_price: 1082.76
    25-08-2019 20_03_44 MainThread DEBUG\ count: 172, date: 2019-06-11, 2019-06-11 00:00:00, close_price: 1081.04
    25-08-2019 20_03_44 MainThread DEBUG\ count: 173, date: 2019-06-12, 2019-06-12 00:00:00, close_price: 1079.1
    25-08-2019 20_03_44 MainThread DEBUG\ count: 174, date: 2019-06-13, 2019-06-13 00:00:00, close_price: 1091.01
    25-08-2019 20_03_44 MainThread DEBUG\ count: 175, date: 2019-06-14, 2019-06-14 00:00:00, close_price: 1086.3
    25-08-2019 20_03_44 MainThread DEBUG\ count: 176, date: 2019-06-17, 2019-06-17 00:00:00, close_price: 1093.89
    25-08-2019 20_03_44 MainThread DEBUG\ count: 177, date: 2019-06-18, 2019-06-18 00:00:00, close_price: 1105.24
    25-08-2019 20_03_44 MainThread DEBUG\ count: 178, date: 2019-06-19, 2019-06-19 00:00:00, close_price: 1104.51
    25-08-2019 20_03_44 MainThread DEBUG\ count: 179, date: 2019-06-20, 2019-06-20 00:00:00, close_price: 1113.2
    25-08-2019 20_03_44 MainThread DEBUG\ count: 180, date: 2019-06-21, 2019-06-21 00:00:00, close_price: 1125.37
    25-08-2019 20_03_44 MainThread DEBUG\ count: 181, date: 2019-06-24, 2019-06-24 00:00:00, close_price: 1116.7
    25-08-2019 20_03_44 MainThread DEBUG\ count: 182, date: 2019-06-25, 2019-06-25 00:00:00, close_price: 1087.58
    25-08-2019 20_03_44 MainThread DEBUG\ count: 183, date: 2019-06-26, 2019-06-26 00:00:00, close_price: 1080.32
    25-08-2019 20_03_44 MainThread DEBUG\ count: 184, date: 2019-06-27, 2019-06-27 00:00:00, close_price: 1076.63
    25-08-2019 20_03_44 MainThread DEBUG\ count: 185, date: 2019-06-28, 2019-06-28 00:00:00, close_price: 1082.8
    25-08-2019 20_03_44 MainThread DEBUG\ count: 186, date: 2019-07-01, 2019-07-01 00:00:00, close_price: 1100.0
    25-08-2019 20_03_44 MainThread DEBUG\ count: 187, date: 2019-07-02, 2019-07-02 00:00:00, close_price: 1112.6
    25-08-2019 20_03_44 MainThread DEBUG\ count: 188, date: 2019-07-03, 2019-07-03 00:00:00, close_price: 1122.99
    25-08-2019 20_03_44 MainThread DEBUG\ count: 189, date: 2019-07-05, 2019-07-05 00:00:00, close_price: 1132.665
    25-08-2019 20_03_44 MainThread DEBUG\ count: 190, date: 2019-07-08, 2019-07-08 00:00:00, close_price: 1116.79
    25-08-2019 20_03_44 MainThread DEBUG\ count: 191, date: 2019-07-09, 2019-07-09 00:00:00, close_price: 1124.29
    25-08-2019 20_03_44 MainThread DEBUG\ count: 192, date: 2019-07-10, 2019-07-10 00:00:00, close_price: 1140.91
    25-08-2019 20_03_44 MainThread DEBUG\ count: 193, date: 2019-07-11, 2019-07-11 00:00:00, close_price: 1144.08
    25-08-2019 20_03_44 MainThread DEBUG\ count: 194, date: 2019-07-12, 2019-07-12 00:00:00, close_price: 1145.34
    25-08-2019 20_03_44 MainThread DEBUG\ count: 195, date: 2019-07-15, 2019-07-15 00:00:00, close_price: 1150.51
    25-08-2019 20_03_44 MainThread DEBUG\ count: 196, date: 2019-07-16, 2019-07-16 00:00:00, close_price: 1153.46
    25-08-2019 20_03_44 MainThread DEBUG\ count: 197, date: 2019-07-17, 2019-07-17 00:00:00, close_price: 1146.74
    25-08-2019 20_03_44 MainThread DEBUG\ count: 198, date: 2019-07-18, 2019-07-18 00:00:00, close_price: 1147.24
    25-08-2019 20_03_44 MainThread DEBUG\ count: 199, date: 2019-07-19, 2019-07-19 00:00:00, close_price: 1131.55
    25-08-2019 20_03_44 MainThread DEBUG\ count: 200, date: 2019-07-22, 2019-07-22 00:00:00, close_price: 1139.21
    25-08-2019 20_03_44 MainThread DEBUG\ count: 201, date: 2019-07-23, 2019-07-23 00:00:00, close_price: 1148.05
    25-08-2019 20_03_44 MainThread DEBUG\ count: 202, date: 2019-07-24, 2019-07-24 00:00:00, close_price: 1139.73
    25-08-2019 20_03_44 MainThread DEBUG\ count: 203, date: 2019-07-25, 2019-07-25 00:00:00, close_price: 1135.94
    25-08-2019 20_03_44 MainThread DEBUG\ count: 204, date: 2019-07-26, 2019-07-26 00:00:00, close_price: 1245.22
    25-08-2019 20_03_44 MainThread DEBUG\ count: 205, date: 2019-07-29, 2019-07-29 00:00:00, close_price: 1241.84
    25-08-2019 20_03_44 MainThread DEBUG\ count: 206, date: 2019-07-30, 2019-07-30 00:00:00, close_price: 1228.0
    25-08-2019 20_03_44 MainThread DEBUG\ count: 207, date: 2019-07-31, 2019-07-31 00:00:00, close_price: 1218.2
    25-08-2019 20_03_44 MainThread DEBUG\ count: 208, date: 2019-08-01, 2019-08-01 00:00:00, close_price: 1211.78
    25-08-2019 20_03_44 MainThread DEBUG\ count: 209, date: 2019-08-02, 2019-08-02 00:00:00, close_price: 1196.32
    25-08-2019 20_03_44 MainThread DEBUG\ count: 210, date: 2019-08-05, 2019-08-05 00:00:00, close_price: 1154.75
    25-08-2019 20_03_44 MainThread DEBUG\ count: 211, date: 2019-08-06, 2019-08-06 00:00:00, close_price: 1171.08
    25-08-2019 20_03_44 MainThread DEBUG\ count: 212, date: 2019-08-07, 2019-08-07 00:00:00, close_price: 1175.91
    25-08-2019 20_03_44 MainThread DEBUG\ count: 213, date: 2019-08-08, 2019-08-08 00:00:00, close_price: 1206.19
    25-08-2019 20_03_44 MainThread DEBUG\ count: 214, date: 2019-08-09, 2019-08-09 00:00:00, close_price: 1188.9
    25-08-2019 20_03_44 MainThread DEBUG\ count: 215, date: 2019-08-12, 2019-08-12 00:00:00, close_price: 1174.5
    25-08-2019 20_03_44 MainThread DEBUG\ count: 216, date: 2019-08-13, 2019-08-13 00:00:00, close_price: 1196.73
    25-08-2019 20_03_44 MainThread DEBUG\ count: 217, date: 2019-08-14, 2019-08-14 00:00:00, close_price: 1164.25
    25-08-2019 20_03_44 MainThread DEBUG\ count: 218, date: 2019-08-15, 2019-08-15 00:00:00, close_price: 1169.32
    25-08-2019 20_03_44 MainThread DEBUG\ count: 219, date: 2019-08-16, 2019-08-16 00:00:00, close_price: 1179.21
    25-08-2019 20_03_44 MainThread DEBUG\ count: 220, date: 2019-08-19, 2019-08-19 00:00:00, close_price: 1200.4399
    25-08-2019 20_03_44 MainThread DEBUG\ count: 221, date: 2019-08-20, 2019-08-20 00:00:00, close_price: 1183.53
    25-08-2019 20_03_44 MainThread DEBUG\ count: 222, date: 2019-08-21, 2019-08-21 00:00:00, close_price: 1191.58
    25-08-2019 20_03_44 MainThread DEBUG\ count: 223, date: 2019-08-22, 2019-08-22 00:00:00, close_price: 1191.52
    25-08-2019 20_03_44 MainThread DEBUG\ count: 224, date: 2019-08-23, 2019-08-23 00:00:00, close_price: 1153.58
    25-08-2019 20_03_44 MainThread DEBUG\ Final Portfolio Value: 10125.35
    

    Am I missing something here? NOTE: this log is for alternate buy/sell like shown in documentation. Same happens for code shared in original post as well.
    Thanks.


  • administrators

    @trader911 said in Multiple consecutive buy signals implementation and issue of profit with only buys:

    Glad to get a confirmation from you that consecutive buys are possible on your platform.

    You don't need a confirmation from me. You need to write the code. The platform only does what is possible in the market.

    @trader911 said in Multiple consecutive buy signals implementation and issue of profit with only buys:

    Let's say I have bought twice. Now when I call self.sell() what happens? Does the system sell all the orders or the last order?

    See, you may be a master of ML, AI, DS9 and TNG, but there is something which is obviously not in your backpack, that is: minimal trading experience.

    First of all ... orders are neither bought nor sold. You don't know what a market position is.

    No matter how good your model, if you have to ask this question, my very humble recommendation: go to the market, spend a couple of bucks to learn how things work. You may hold me for arrogant and patronizing, but let me say very sincerely, that no matter how good your ML model is ... if you don't know how orders and positions work in the market, it's going to be a disaster. Spend the bucks, get some experience.

    You may also read the documentation: Docs - Strategy

    @trader911 said in Multiple consecutive buy signals implementation and issue of profit with only buys:

    Below is the log that was printed. Which showed profit with one buy.

    You also need to slow down and understand the minimum. You first said when your system recommended hold (no action) you still saw a profit.

    Now you say that you have executed one buy and you see a profit. Well, it would be a MIRACLE if you execute a buy and there is no variation in the value of your portfolio. That you see an increment is for sure just a coincidence. You could have also seen a decrease.

    If this is something you cannot comprehend, this adds to my recommendation: get to know how things work.



  • I don't need a validation of my expertise in minimal trading experience from you... I know I am new to trading. I am learning now. But I definitely know what a "market position" means. If you assume others are stupid that's your problem. You have written a couple of hundred words probably in both of your responses but none of them have any substance. You just quote and repeat what I say in my query (but surprisingly miss the important bits). I have read your other responses as well and they are no different. People ask queries about "how to do x using your y platform" everywhere, read keras related questions and their communities response, I bet they are not lectured about their proficiency.

    Also you were confused about my 'profit' right? Sometimes I say I get profit with "only hold", sometimes I say profit with "only buy"? You wouldn't have that confusion if you had focused less on being condescending and more on reading question. My 2nd point in main post is this -- "Also I noticed profits when there is no transaction at all or even with only buys". Anyways I don't need any more help from you or your library. Thanks for nothing.


Log in to reply
 

});