Trades not getting executed using order_target_percent
-
I am trying to create a pairs trading strategy so I need to buy one stock and sell another.
I am using order_target_percent to buy and sellif Longcondition: self.order_target_percent(self.data,target=self.percent) self.order_target_percent(self.data1,target=-self.percent) if self.printlog: print('%04d - %s -Long Order Target Percent: %.2f' % (len(self), dt.isoformat(), self.percent))
and similarly I sell on shortcondition.
When I am running this code, sometimes the order for stock 1 is getting executed but the order of stock 2 isn't getting executed at all. Theoretically, if both orders are placed together, there should be equal number of trades for both the stock, but there are like 10 trades for stock 1 but only 3 trades for stock 2.
Output looks like this2011-06-24, Long Entry 0121 - 2011-06-24 -Long Order Target Percent: 0.05 0122 - 2011-06-27 - Position on data 1 Size: -1 - Position on data 2 Size: 01 - Value 499.78 0123 - 2011-06-28 - Position on data 1 Size: -1 - Position on data 2 Size: 01 - Value 499.88 2011-06-28, Long Exit 0123 - 2011-06-28 -Long exit Target Percent: 0.05 0124 - 2011-06-29 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.98 2011-06-29, Short Entry 0124 - 2011-06-29 -Short Order Target Percent: 0.05 0125 - 2011-06-30 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.02 0126 - 2011-07-01 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.15
You can see that it is getting positions for stock 1 but not stock 2
-
@zuj Hard to say for sure from this info. If you could try using the loggings from the notify_order and notify_trades as found frequently in the docs it would be helpful.
As a suggestion, but I'm not sure if this is your problem here, try putting your shorts first and long trades second. This will ensure adequate cash flow. If this doesn't solve it, we'll need more detailed information on what is happening with the trades and failures.
-
@run-out I don't see why using short first can help if I am only using 5% of the whole portfolio for each trade and closing both of the positions before taking another two positions.
Here is the result of the trade list analyzer for each trade[{'brokervalue': 499.89189999999996, 'chng%': 0.77, 'cumpnl': 0.120000000000001, 'datein': datetime.date(2011, 1, 5), 'dateout': datetime.date(2011, 1, 14), 'dir': 'long', 'mae': -0.24, 'mae%': -1.55, 'mfe': 0.36, 'mfe%': 2.32, 'nbars': 7, 'pnl': 0.120000000000001, 'pnl%': 0.02338772382086332, 'pnl/bar': 0.02, 'pnlcomm': 0.11688600000000099, 'pricein': 15.51, 'priceout': 15.63, 'ref': 450, 'size': 1, 'ticker': 'EWA', 'value': 15.51}, {'brokervalue': 499.89189999999996, 'chng%': 0.89, 'cumpnl': -0.09999999999999787, 'datein': datetime.date(2011, 1, 5), 'dateout': datetime.date(2011, 1, 14), 'dir': 'short', 'mae': -0.52, 'mae%': -2.1, 'mfe': 0.33, 'mfe%': 1.33, 'nbars': 7, 'pnl': -0.21999999999999886, 'pnl%': -0.04498668337305429, 'pnl/bar': -0.03, 'pnlcomm': -0.22498599999999885, 'pricein': 24.82, 'priceout': 25.04, 'ref': 451, 'size': -1, 'ticker': 'EWC', 'value': -24.82}, {'brokervalue': 499.58878000000004, 'chng%': 1.94, 'cumpnl': -0.3999999999999986, 'datein': datetime.date(2011, 3, 11), 'dateout': datetime.date(2011, 3, 21), 'dir': 'short', 'mae': -0.37, 'mae%': -2.39, 'mfe': 0.81, 'mfe%': 5.24, 'nbars': 6, 'pnl': -0.3000000000000007, 'pnl%': -0.0606371097431266, 'pnl/bar': -0.05, 'pnlcomm': -0.3031200000000007, 'pricein': 15.45, 'priceout': 15.75, 'ref': 452, 'size': -1, 'ticker': 'EWA', 'value': -15.45}, {'brokervalue': 500.0655720000001, 'chng%': 3.04, 'cumpnl': 0.08000000000000185, 'datein': datetime.date(2011, 3, 22), 'dateout': datetime.date(2011, 3, 29), 'dir': 'long', 'mae': -0.12, 'mae%': -0.76, 'mfe': 0.75, 'mfe%': 4.75, 'nbars': 5, 'pnl': 0.4800000000000004, 'pnl%': 0.09543689111673011, 'pnl/bar': 0.1, 'pnlcomm': 0.47679200000000044, 'pricein': 15.8, 'priceout': 16.28, 'ref': 453, 'size': 1, 'ticker': 'EWA', 'value': 15.8}, {'brokervalue': 500.63217300000014, 'chng%': 3.41, 'cumpnl': 0.6500000000000021, 'datein': datetime.date(2011, 3, 30), 'dateout': datetime.date(2011, 4, 12), 'dir': 'long', 'mae': -0.04, 'mae%': -0.24, 'mfe': 0.96, 'mfe%': 5.75, 'nbars': 9, 'pnl': 0.5700000000000003, 'pnl%': 0.11330534068440129, 'pnl/bar': 0.06, 'pnlcomm': 0.5666010000000002, 'pricein': 16.71, 'priceout': 17.28, 'ref': 454, 'size': 1, 'ticker': 'EWA', 'value': 16.71}, {'brokervalue': 500.71872600000023, 'chng%': -0.52, 'cumpnl': 0.740000000000002, 'datein': datetime.date(2011, 4, 13), 'dateout': datetime.date(2011, 4, 15), 'dir': 'short', 'mae': -0.08, 'mae%': -0.46, 'mfe': 0.23, 'mfe%': 1.33, 'nbars': 2, 'pnl': 0.08999999999999986, 'pnl%': 0.017288741049409105, 'pnl/bar': 0.04, 'pnlcomm': 0.08655299999999985, 'pricein': 17.28, 'priceout': 17.19, 'ref': 455, 'size': -1, 'ticker': 'EWA', 'value': -17.28}, {'brokervalue': 500.18528500000014, 'chng%': 3.13, 'cumpnl': 0.2100000000000044, 'datein': datetime.date(2011, 4, 19), 'dateout': datetime.date(2011, 4, 20), 'dir': 'short', 'mae': -0.63, 'mae%': -3.72, 'mfe': 0.04, 'mfe%': 0.24, 'nbars': 1, 'pnl': -0.5299999999999976, 'pnl%': -0.10653506096354733, 'pnl/bar': -0.53, 'pnlcomm': -0.5334409999999976, 'pricein': 16.94, 'priceout': 17.47, 'ref': 456, 'size': -1, 'ticker': 'EWA', 'value': -16.94}, {'brokervalue': 500.28175100000016, 'chng%': 0.57, 'cumpnl': 0.3100000000000023, 'datein': datetime.date(2011, 4, 21), 'dateout': datetime.date(2011, 4, 29), 'dir': 'long', 'mae': -0.03, 'mae%': -0.17, 'mfe': 0.3, 'mfe%': 1.7, 'nbars': 5, 'pnl': 0.09999999999999787, 'pnl%': 0.019286053167277373, 'pnl/bar': 0.02, 'pnlcomm': 0.09646599999999787, 'pricein': 17.62, 'priceout': 17.72, 'ref': 457, 'size': 1, 'ticker': 'EWA', 'value': 17.62}, {'brokervalue': 500.38831600000015, 'chng%': -0.64, 'cumpnl': 0.4200000000000017, 'datein': datetime.date(2011, 5, 4), 'dateout': datetime.date(2011, 5, 10), 'dir': 'short', 'mae': -0.06, 'mae%': -0.35, 'mfe': 0.64, 'mfe%': 3.71, 'nbars': 4, 'pnl': 0.10999999999999943, 'pnl%': 0.021300996845675352, 'pnl/bar': 0.03, 'pnlcomm': 0.10656499999999944, 'pricein': 17.23, 'priceout': 17.12, 'ref': 458, 'size': -1, 'ticker': 'EWA', 'value': -17.23}, {'brokervalue': 500.4149810000002, 'chng%': -0.18, 'cumpnl': 0.45000000000000284, 'datein': datetime.date(2011, 5, 12), 'dateout': datetime.date(2011, 5, 18), 'dir': 'short', 'mae': -0.19, 'mae%': -1.14, 'mfe': 0.29, 'mfe%': 1.74, 'nbars': 4, 'pnl': 0.030000000000001137, 'pnl%': 0.005328861435685706, 'pnl/bar': 0.01, 'pnlcomm': 0.026665000000001136, 'pricein': 16.69, 'priceout': 16.66, 'ref': 459, 'size': -1, 'ticker': 'EWA', 'value': -16.69}, {'brokervalue': 499.7916670000002, 'chng%': -3.67, 'cumpnl': -0.1699999999999946, 'datein': datetime.date(2011, 5, 20), 'dateout': datetime.date(2011, 5, 23), 'dir': 'long', 'mae': -0.68, 'mae%': -4.03, 'mfe': 0.08, 'mfe%': 0.47, 'nbars': 1, 'pnl': -0.6199999999999974, 'pnl%': -0.12455942041431355, 'pnl/bar': -0.62, 'pnlcomm': -0.6233139999999975, 'pricein': 16.88, 'priceout': 16.26, 'ref': 460, 'size': 1, 'ticker': 'EWA', 'value': 16.88}, {'brokervalue': 500.0084030000002, 'chng%': -1.34, 'cumpnl': 0.05000000000000426, 'datein': datetime.date(2011, 5, 24), 'dateout': datetime.date(2011, 5, 25), 'dir': 'short', 'mae': -0.07, 'mae%': -0.43, 'mfe': 0.25, 'mfe%': 1.52, 'nbars': 1, 'pnl': 0.21999999999999886, 'pnl%': 0.04336526883310337, 'pnl/bar': 0.22, 'pnlcomm': 0.21673599999999887, 'pricein': 16.43, 'priceout': 16.21, 'ref': 461, 'size': -1, 'ticker': 'EWA', 'value': -16.43}, {'brokervalue': 499.66508100000016, 'chng%': -2.03, 'cumpnl': -0.2899999999999956, 'datein': datetime.date(2011, 5, 27), 'dateout': datetime.date(2011, 6, 2), 'dir': 'long', 'mae': -0.53, 'mae%': -3.16, 'mfe': 0.14, 'mfe%': 0.83, 'nbars': 3, 'pnl': -0.33999999999999986, 'pnl%': -0.0686632460454869, 'pnl/bar': -0.11, 'pnlcomm': -0.34332199999999985, 'pricein': 16.78, 'priceout': 16.44, 'ref': 462, 'size': 1, 'ticker': 'EWA', 'value': 16.78}, {'brokervalue': 499.6118440000002, 'chng%': 0.31, 'cumpnl': -0.3399999999999963, 'datein': datetime.date(2011, 6, 3), 'dateout': datetime.date(2011, 6, 10), 'dir': 'short', 'mae': -0.4, 'mae%': -2.48, 'mfe': 0.21, 'mfe%': 1.3, 'nbars': 5, 'pnl': -0.05000000000000071, 'pnl%': -0.010654536813630306, 'pnl/bar': -0.01, 'pnlcomm': -0.053237000000000714, 'pricein': 16.16, 'priceout': 16.21, 'ref': 463, 'size': -1, 'ticker': 'EWA', 'value': -16.16}, {'brokervalue': 499.57364300000006, 'chng%': 0.81, 'cumpnl': -0.4699999999999953, 'datein': datetime.date(2011, 6, 13), 'dateout': datetime.date(2011, 6, 15), 'dir': 'short', 'mae': -0.44, 'mae%': -2.73, 'mfe': 0.17, 'mfe%': 1.06, 'nbars': 2, 'pnl': -0.129999999999999, 'pnl%': -0.026662230679411144, 'pnl/bar': -0.06, 'pnlcomm': -0.13323299999999902, 'pricein': 16.1, 'priceout': 16.23, 'ref': 464, 'size': -1, 'ticker': 'EWA', 'value': -16.1}, {'brokervalue': 499.57364300000006, 'chng%': 0.4, 'cumpnl': -0.3699999999999939, 'datein': datetime.date(2011, 6, 13), 'dateout': datetime.date(2011, 6, 15), 'dir': 'long', 'mae': -0.31, 'mae%': -1.25, 'mfe': 0.41, 'mfe%': 1.65, 'nbars': 2, 'pnl': 0.10000000000000142, 'pnl%': 0.019026240144645833, 'pnl/bar': 0.05, 'pnlcomm': 0.09503200000000142, 'pricein': 24.79, 'priceout': 24.89, 'ref': 465, 'size': 1, 'ticker': 'EWC', 'value': 24.79}, {'brokervalue': 499.66551900000013, 'chng%': 1.96, 'cumpnl': -0.6799999999999926, 'datein': datetime.date(2011, 6, 16), 'dateout': datetime.date(2011, 6, 22), 'dir': 'short', 'mae': -0.47, 'mae%': -2.97, 'mfe': 0.1, 'mfe%': 0.63, 'nbars': 4, 'pnl': -0.3099999999999987, 'pnl%': -0.06264166678103793, 'pnl/bar': -0.08, 'pnlcomm': -0.3131949999999987, 'pricein': 15.82, 'priceout': 16.13, 'ref': 466, 'size': -1, 'ticker': 'EWA', 'value': -15.82}, {'brokervalue': 499.66551900000013, 'chng%': 1.68, 'cumpnl': -0.26999999999999247, 'datein': datetime.date(2011, 6, 16), 'dateout': datetime.date(2011, 6, 22), 'dir': 'long', 'mae': -0.28, 'mae%': -1.15, 'mfe': 0.76, 'mfe%': 3.11, 'nbars': 4, 'pnl': 0.41000000000000014, 'pnl%': 0.08113420592852572, 'pnl/bar': 0.1, 'pnlcomm': 0.4050710000000001, 'pricein': 24.44, 'priceout': 24.85, 'ref': 467, 'size': 1, 'ticker': 'EWC', 'value': 24.44}, {'brokervalue': 499.9773890000002, 'chng%': 3.89, 'cumpnl': -0.8799999999999919, 'datein': datetime.date(2011, 6, 27), 'dateout': datetime.date(2011, 6, 29), 'dir': 'short', 'mae': -0.75, 'mae%': -4.78, 'mfe': 0.06, 'mfe%': 0.38, 'nbars': 2, 'pnl': -0.6099999999999994, 'pnl%': -0.12249551075260907, 'pnl/bar': -0.3, 'pnlcomm': -0.6132009999999994, 'pricein': 15.7, 'priceout': 16.31, 'ref': 468, 'size': -1, 'ticker': 'EWA', 'value': -15.7}, {'brokervalue': 499.9773890000002, 'chng%': 3.85, 'cumpnl': 0.050000000000007816, 'datein': datetime.date(2011, 6, 27), 'dateout': datetime.date(2011, 6, 29), 'dir': 'long', 'mae': -0.09, 'mae%': -0.37, 'mfe': 1.2, 'mfe%': 4.96, 'nbars': 2, 'pnl': 0.9299999999999997, 'pnl%': 0.18536553516218704, 'pnl/bar': 0.46, 'pnlcomm': 0.9250709999999998, 'pricein': 24.18, 'priceout': 25.11, 'ref': 469, 'size': 1, 'ticker': 'EWC', 'value': 24.18}]
-
@zuj said in Trades not getting executed using order_target_percent:
Output
Here's a more detailed output
Running on 2011-01-02 00:00:00 2011-07-03 00:00:00 Starting Portfolio Value: 500.00 0001 - 2011-01-03 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.00 0002 - 2011-01-04 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.00 2011-01-04, Short Entry 0002 - 2011-01-04 -Short Order Target Percent: 0.05 2011-01-05, BUY EXECUTED, Price: 15.51, Cost: 15.51, Comm 0.00 2011-01-05, SELL EXECUTED, Price: 24.82, Cost: -24.82, Comm 0.00 0003 - 2011-01-05 - Position on data 1 Size: 01 - Position on data 2 Size: -1 - Value 500.05 0004 - 2011-01-06 - Position on data 1 Size: 01 - Position on data 2 Size: -1 - Value 500.01 0005 - 2011-01-07 - Position on data 1 Size: 01 - Position on data 2 Size: -1 - Value 499.93 0006 - 2011-01-10 - Position on data 1 Size: 01 - Position on data 2 Size: -1 - Value 500.05 0007 - 2011-01-11 - Position on data 1 Size: 01 - Position on data 2 Size: -1 - Value 499.66 0008 - 2011-01-12 - Position on data 1 Size: 01 - Position on data 2 Size: -1 - Value 499.64 0009 - 2011-01-13 - Position on data 1 Size: 01 - Position on data 2 Size: -1 - Value 499.91 2011-01-13, Short Exit 0009 - 2011-01-13 -Short exit Target Percent: 0.05 2011-01-14, SELL EXECUTED, Price: 15.63, Cost: 15.51, Comm 0.00 2011-01-14, BUY EXECUTED, Price: 25.04, Cost: -24.82, Comm 0.00 0010 - 2011-01-14 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0011 - 2011-01-18 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0012 - 2011-01-19 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0013 - 2011-01-20 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0014 - 2011-01-21 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0015 - 2011-01-24 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0016 - 2011-01-25 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0017 - 2011-01-26 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0018 - 2011-01-27 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0019 - 2011-01-28 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0020 - 2011-01-31 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0021 - 2011-02-01 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0022 - 2011-02-02 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0023 - 2011-02-03 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0024 - 2011-02-04 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0025 - 2011-02-07 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0026 - 2011-02-08 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0027 - 2011-02-09 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0028 - 2011-02-10 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0029 - 2011-02-11 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0030 - 2011-02-14 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0031 - 2011-02-15 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0032 - 2011-02-16 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0033 - 2011-02-17 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0034 - 2011-02-18 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0035 - 2011-02-22 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0036 - 2011-02-23 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0037 - 2011-02-24 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0038 - 2011-02-25 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0039 - 2011-02-28 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0040 - 2011-03-01 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0041 - 2011-03-02 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0042 - 2011-03-03 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0043 - 2011-03-04 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0044 - 2011-03-07 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0045 - 2011-03-08 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0046 - 2011-03-09 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 0047 - 2011-03-10 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.89 2011-03-10, Long Entry 0047 - 2011-03-10 -Long Order Target Percent: 0.05 2011-03-11, SELL EXECUTED, Price: 15.45, Cost: -15.45, Comm 0.00 0048 - 2011-03-11 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 499.56 0049 - 2011-03-14 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 499.73 0050 - 2011-03-15 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.17 0051 - 2011-03-16 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.52 0052 - 2011-03-17 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.34 0053 - 2011-03-18 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 499.92 2011-03-18, Long Exit 0053 - 2011-03-18 -Long exit Target Percent: 0.05 2011-03-21, BUY EXECUTED, Price: 15.75, Cost: -15.45, Comm 0.00 0054 - 2011-03-21 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.59 2011-03-21, Short Entry 0054 - 2011-03-21 -Short Order Target Percent: 0.05 2011-03-22, BUY EXECUTED, Price: 15.80, Cost: 15.80, Comm 0.00 0055 - 2011-03-22 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 499.56 0056 - 2011-03-23 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 499.68 0057 - 2011-03-24 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.00 0058 - 2011-03-25 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.07 0059 - 2011-03-28 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.06 2011-03-28, Short Exit 0059 - 2011-03-28 -Short exit Target Percent: 0.05 2011-03-29, SELL EXECUTED, Price: 16.28, Cost: 15.80, Comm 0.00 0060 - 2011-03-29 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.07 2011-03-29, Short Entry 0060 - 2011-03-29 -Short Order Target Percent: 0.05 2011-03-30, BUY EXECUTED, Price: 16.71, Cost: 16.71, Comm 0.00 0061 - 2011-03-30 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.12 0062 - 2011-03-31 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.17 0063 - 2011-04-01 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.37 0064 - 2011-04-04 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.35 0065 - 2011-04-05 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.33 0066 - 2011-04-06 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.60 0067 - 2011-04-07 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.59 0068 - 2011-04-08 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.76 0069 - 2011-04-11 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.80 2011-04-11, Short Exit 0069 - 2011-04-11 -Short exit Target Percent: 0.05 2011-04-12, SELL EXECUTED, Price: 17.28, Cost: 16.71, Comm 0.00 0070 - 2011-04-12 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.63 2011-04-12, Long Entry 0070 - 2011-04-12 -Long Order Target Percent: 0.05 2011-04-13, SELL EXECUTED, Price: 17.28, Cost: -17.28, Comm 0.00 0071 - 2011-04-13 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.66 0072 - 2011-04-14 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.62 2011-04-14, Long Exit 0072 - 2011-04-14 -Long exit Target Percent: 0.05 2011-04-15, BUY EXECUTED, Price: 17.19, Cost: -17.28, Comm 0.00 0073 - 2011-04-15 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.72 0074 - 2011-04-18 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.72 2011-04-18, Long Entry 0074 - 2011-04-18 -Long Order Target Percent: 0.05 2011-04-19, SELL EXECUTED, Price: 16.94, Cost: -16.94, Comm 0.00 0075 - 2011-04-19 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.66 2011-04-19, Long Exit 0075 - 2011-04-19 -Long exit Target Percent: 0.05 2011-04-20, BUY EXECUTED, Price: 17.47, Cost: -16.94, Comm 0.00 0076 - 2011-04-20 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.19 2011-04-20, Short Entry 0076 - 2011-04-20 -Short Order Target Percent: 0.05 2011-04-21, BUY EXECUTED, Price: 17.62, Cost: 17.62, Comm 0.00 0077 - 2011-04-21 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.28 0078 - 2011-04-25 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.30 0079 - 2011-04-26 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.39 0080 - 2011-04-27 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.43 0081 - 2011-04-28 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.47 2011-04-28, Short Exit 0081 - 2011-04-28 -Short exit Target Percent: 0.05 2011-04-29, SELL EXECUTED, Price: 17.72, Cost: 17.62, Comm 0.00 0082 - 2011-04-29 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.28 0083 - 2011-05-02 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.28 0084 - 2011-05-03 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.28 2011-05-03, Long Entry 0084 - 2011-05-03 -Long Order Target Percent: 0.05 2011-05-04, SELL EXECUTED, Price: 17.23, Cost: -17.23, Comm 0.00 0085 - 2011-05-04 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.56 0086 - 2011-05-05 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.82 0087 - 2011-05-06 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.53 0088 - 2011-05-09 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.33 2011-05-09, Long Exit 0088 - 2011-05-09 -Long exit Target Percent: 0.05 2011-05-10, BUY EXECUTED, Price: 17.12, Cost: -17.23, Comm 0.00 0089 - 2011-05-10 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.39 0090 - 2011-05-11 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.39 2011-05-11, Long Entry 0090 - 2011-05-11 -Long Order Target Percent: 0.05 2011-05-12, SELL EXECUTED, Price: 16.69, Cost: -16.69, Comm 0.00 0091 - 2011-05-12 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.25 0092 - 2011-05-13 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.52 0093 - 2011-05-16 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.52 0094 - 2011-05-17 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 500.39 2011-05-17, Long Exit 0094 - 2011-05-17 -Long exit Target Percent: 0.05 2011-05-18, BUY EXECUTED, Price: 16.66, Cost: -16.69, Comm 0.00 0095 - 2011-05-18 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.41 0096 - 2011-05-19 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.41 2011-05-19, Short Entry 0096 - 2011-05-19 -Short Order Target Percent: 0.05 2011-05-20, BUY EXECUTED, Price: 16.88, Cost: 16.88, Comm 0.00 0097 - 2011-05-20 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.35 2011-05-20, Short Exit 0097 - 2011-05-20 -Short exit Target Percent: 0.05 2011-05-23, SELL EXECUTED, Price: 16.26, Cost: 16.88, Comm 0.00 0098 - 2011-05-23 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.79 2011-05-23, Long Entry 0098 - 2011-05-23 -Long Order Target Percent: 0.05 2011-05-24, SELL EXECUTED, Price: 16.43, Cost: -16.43, Comm 0.00 0099 - 2011-05-24 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 499.82 2011-05-24, Long Exit 0099 - 2011-05-24 -Long exit Target Percent: 0.05 2011-05-25, BUY EXECUTED, Price: 16.21, Cost: -16.43, Comm 0.00 0100 - 2011-05-25 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.01 0101 - 2011-05-26 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 500.01 2011-05-26, Short Entry 0101 - 2011-05-26 -Short Order Target Percent: 0.05 2011-05-27, BUY EXECUTED, Price: 16.78, Cost: 16.78, Comm 0.00 0102 - 2011-05-27 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.00 0103 - 2011-05-31 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.11 0104 - 2011-06-01 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 499.72 2011-06-01, Short Exit 0104 - 2011-06-01 -Short exit Target Percent: 0.05 2011-06-02, SELL EXECUTED, Price: 16.44, Cost: 16.78, Comm 0.00 0105 - 2011-06-02 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.67 2011-06-02, Long Entry 0105 - 2011-06-02 -Long Order Target Percent: 0.05 2011-06-03, SELL EXECUTED, Price: 16.16, Cost: -16.16, Comm 0.00 0106 - 2011-06-03 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 499.46 0107 - 2011-06-06 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 499.53 0108 - 2011-06-07 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 499.40 0109 - 2011-06-08 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 499.70 0110 - 2011-06-09 - Position on data 1 Size: -1 - Position on data 2 Size: 00 - Value 499.49 2011-06-09, Long Exit 0110 - 2011-06-09 -Long exit Target Percent: 0.05 2011-06-10, BUY EXECUTED, Price: 16.21, Cost: -16.16, Comm 0.00 0111 - 2011-06-10 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.61 2011-06-10, Long Entry 0111 - 2011-06-10 -Long Order Target Percent: 0.05 2011-06-13, SELL EXECUTED, Price: 16.10, Cost: -16.10, Comm 0.00 2011-06-13, BUY EXECUTED, Price: 24.79, Cost: 24.79, Comm 0.00 0112 - 2011-06-13 - Position on data 1 Size: -1 - Position on data 2 Size: 01 - Value 499.56 0113 - 2011-06-14 - Position on data 1 Size: -1 - Position on data 2 Size: 01 - Value 499.59 2011-06-14, Long Exit 0113 - 2011-06-14 -Long exit Target Percent: 0.05 2011-06-15, BUY EXECUTED, Price: 16.23, Cost: -16.10, Comm 0.00 2011-06-15, SELL EXECUTED, Price: 24.89, Cost: 24.79, Comm 0.00 0114 - 2011-06-15 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.57 2011-06-15, Long Entry 0114 - 2011-06-15 -Long Order Target Percent: 0.05 2011-06-16, SELL EXECUTED, Price: 15.82, Cost: -15.82, Comm 0.00 2011-06-16, BUY EXECUTED, Price: 24.44, Cost: 24.44, Comm 0.00 0115 - 2011-06-16 - Position on data 1 Size: -1 - Position on data 2 Size: 01 - Value 499.44 0116 - 2011-06-17 - Position on data 1 Size: -1 - Position on data 2 Size: 01 - Value 499.21 0117 - 2011-06-20 - Position on data 1 Size: -1 - Position on data 2 Size: 01 - Value 499.40 0118 - 2011-06-21 - Position on data 1 Size: -1 - Position on data 2 Size: 01 - Value 499.69 2011-06-21, Long Exit 0118 - 2011-06-21 -Long exit Target Percent: 0.05 2011-06-22, BUY EXECUTED, Price: 16.13, Cost: -15.82, Comm 0.00 2011-06-22, SELL EXECUTED, Price: 24.85, Cost: 24.44, Comm 0.00 0119 - 2011-06-22 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.67 0120 - 2011-06-23 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.67 0121 - 2011-06-24 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.67 2011-06-24, Long Entry 0121 - 2011-06-24 -Long Order Target Percent: 0.05 2011-06-27, SELL EXECUTED, Price: 15.70, Cost: -15.70, Comm 0.00 2011-06-27, BUY EXECUTED, Price: 24.18, Cost: 24.18, Comm 0.00 0122 - 2011-06-27 - Position on data 1 Size: -1 - Position on data 2 Size: 01 - Value 499.78 0123 - 2011-06-28 - Position on data 1 Size: -1 - Position on data 2 Size: 01 - Value 499.88 2011-06-28, Long Exit 0123 - 2011-06-28 -Long exit Target Percent: 0.05 2011-06-29, BUY EXECUTED, Price: 16.31, Cost: -15.70, Comm 0.00 2011-06-29, SELL EXECUTED, Price: 25.11, Cost: 24.18, Comm 0.00 0124 - 2011-06-29 - Position on data 1 Size: 00 - Position on data 2 Size: 00 - Value 499.98 2011-06-29, Short Entry 0124 - 2011-06-29 -Short Order Target Percent: 0.05 2011-06-30, BUY EXECUTED, Price: 16.70, Cost: 16.70, Comm 0.00 0125 - 2011-06-30 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.02 0126 - 2011-07-01 - Position on data 1 Size: 01 - Position on data 2 Size: 00 - Value 500.15 Final Portfolio Value: 500.15
-
@zuj Could you include your code please?
-
@run-out I really don't get why the full code is required because it has nothing to do with the order_target_percent thing.
if Longcondition: self.order_target_percent(self.data,target=self.percent) self.order_target_percent(self.data1,target=-self.percent) if self.printlog: print('%04d - %s -Long Order Target Percent: %.2f' % (len(self), dt.isoformat(), self.percent)) if Shortcondition: self.order_target_percent(self.data,target=-self.percent) self.order_target_percent(self.data1,target=self.percent) if self.printlog: print('%04d - %s -Short Order Target Percent: %.2f' % (len(self), dt.isoformat(), self.percent))
Longcondition and short condition might as well be sma crossover for data0 and vice versa.
-
@zuj said in Trades not getting executed using order_target_percent:
I really don't get why the full code is required
In order to debug something, than this something need to be presented. Otherwise there is nothing to debug.
@zuj said in Trades not getting executed using order_target_percent:
Longcondition and short condition might as well be sma crossover for data0 and vice versa.
If you don't want to show the original code, than no problem, just provide the code with some general trading rules which has the same issue.
-
@ab_trader That's exactly what I did. I provided you the general code already. I even provided you the outputs. Never have I made any post so detailed yet you need more. In no way can I provide the full strategy that I have been researching for months. Like I said, the long and short conditions might as well be sma crossover of data0 i.e. long when sma(10) > sma(20) and vice versa because it doesn't matter. I am issuing two trades together so there numbers should be equal which is not the case.
But there is no need for it now because I solved the issue by myself. order_target_percent is faulty af. -
@zuj said in Trades not getting executed using order_target_percent:
order_target_percent is faulty af.
That's possible, but needs to be proved.
On the other side, it looks like you are trying to open position on 5% from 500$, which is 25$. But 2ndcdsta stock price (EWC, right?) is more than 25$.