Hi all,
I am new on the platform, trying to figure things out.
I am not sure what I am doing wrong but it looks to me like my limit order is not getting filled properly. Any pointers?
Hi all,
I am new on the platform, trying to figure things out.
I am not sure what I am doing wrong but it looks to me like my limit order is not getting filled properly. Any pointers?
Here is the log:
2013-05-20PRINTOHLC: 166.78 167.58 166.61 166.93
2013-05-20handle_data:20INFOsubmitted limit order after market close
2013-05-21PRINTOHLC: 167.08 167.80 166.50 167.19
2013-05-22PRINTOHLC: 167.34 169.07 165.17 165.85
2013-05-23PRINTOHLC: 164.16 165.91 163.94 165.43
2013-05-24PRINTOHLC: 164.47 165.38 163.98 165.32
2013-05-28PRINTOHLC: 167.04 167.78 165.81 166.30
2013-05-29PRINTOHLC: 165.42 165.80 164.34 165.22
2013-05-30PRINTOHLC: 165.35 166.59 165.22 165.82
2013-05-31PRINTOHLC: 165.37 166.31 163.13 163.44
2013-06-03PRINTOHLC: 163.83 164.46 162.66 164.38
2013-06-03handle_data:30INFOshould have been filled today!!!
2013-06-04PRINTOHLC: 164.44 165.10 162.73 163.50
2013-06-04handle_data:30INFOshould have been filled today!!!
2013-06-05PRINTOHLC: 163.09 163.42 161.13 161.26
2013-06-05handle_data:27INFOfilled today at 161.26
2013-06-05handle_data:28INFOEvent({'status': 1, 'created': datetime.datetime(2013, 5, 20, 0, 0, tzinfo=), 'limit_reached': True, 'stop': None, 'stop_reached': False, 'commission': 0.0, 'amount': 10, 'limit': 163.0, 'sid': Security(8554, symbol=u'SPY', security_name=u'SPDR S&P 500 ETF TRUST', exchange=u'NYSE ARCA EXCHANGE', start_date=datetime.datetime(1993, 1, 29, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 4, 16, 0, 0, tzinfo=), first_traded=None), 'dt': datetime.datetime(2013, 6, 5, 0, 0, tzinfo=), 'id': 'a409c7664fd84bababeecfa15c4a50aa', 'filled': 10})
2013-06-06PRINTOHLC: 161.20 162.74 160.25 162.70
2013-06-07PRINTOHLC: 163.85 164.95 163.14 164.81
2013-06-10PRINTOHLC: 165.31 165.40 164.37 164.76
End of logs.
Hi DS,
Take a look at the attached algo, I believe it's working as you intended. I added a check for open orders that solved your issue.
Also, I'm not sure why you were logging "submitted limit order after market close" - the limit order is submitted in the first bar of the algorithm. For backtests in daily mode it's at market close in Day 1 and in minute mode it will be at 9:31AM. If I missed your intentions let me know and I'll take another look!
Cheers,
Alisa
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.
Hi Alisa,
Thanks for looking into it. I ran your algo and got the same problem as I get on mine. My limit order should have been filled on 6/3 when day's low was 162.66 which is below my limit of 163. Instead, my limit order got filled on 6/5 and for some reason it got filled at close price of 6/5 daily bar (is it a coincidence?)
What I am trying to point out is that it looks to me like either I am doing something wrong or platform's logic re filling of limit orders on daily backtests is not right.
Thanks,
Dmitriy
Hi Dmitriy,
Got it - thanks for clarifying! The backtester uses the close_price of the previous bar to trigger the limit order. So if the close price passes the limit threshold, you'll enter the limit order. Unfortunately (and there is room for improvement here), it doesn't look at the other OHL values. Because of this, it was only looking at the close price of the previous day, since you were running your algo in daily mode.
I'd suggest to run your same algo in minutely mode, which will give you more granular price details. You'll enter the limit order if the close_price of the previous minute crossed your threshold. This will give you behavior closer to what you're expecting.
In live trading, limit orders are handled directly by the broker. Your order is submitted in your handle_data call and it's executed and filled by IB. Hope that helps!
Alisa
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.