Hi Seong,
I guess I don't yet understand completely. Are you using OHLC values to determine if the stop is reached? I can't understand why the limit order resulted when the closing price stayed above the stop price of 99.99?
Also, what is the point of the 'stop_reached' flag if it is not used? Shouldn't you be retaining the stop price and setting the stop_reached flag to True?
I've attached an update to my backtest.
Grant
The log output:
2014-09-22PRINT101.07
2014-09-22PRINTEvent({'status': 0, 'limit_reached': False, 'created': Timestamp('2014-09-22 00:00:00+0000', tz='UTC'), 'stop': 99.99, 'reason': None, 'stop_reached': False, 'commission': None, 'amount': 50, 'limit': 100.0, 'sid': Security(24, symbol='AAPL', security_name='APPLE INC', exchange='NASDAQ GLOBAL SELECT MARKET', start_date=datetime.datetime(1993, 1, 4, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 9, 30, 0, 0, tzinfo=), first_traded=None), 'id': '9bc9b28c2d9647518168ca4e9aa8da43', 'dt': Timestamp('2014-09-22 00:00:00+0000', tz='UTC'), 'filled': 0})
2014-09-23PRINT102.64
2014-09-23PRINTEvent({'status': 0, 'limit_reached': False, 'created': Timestamp('2014-09-22 00:00:00+0000', tz='UTC'), 'stop': None, 'reason': None, 'stop_reached': False, 'commission': None, 'amount': 50, 'limit': 100.0, 'sid': Security(24, symbol='AAPL', security_name='APPLE INC', exchange='NASDAQ GLOBAL SELECT MARKET', start_date=datetime.datetime(1993, 1, 4, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 9, 30, 0, 0, tzinfo=), first_traded=None), 'id': '9bc9b28c2d9647518168ca4e9aa8da43', 'dt': Timestamp('2014-09-22 00:00:00+0000', tz='UTC'), 'filled': 0})
2014-09-24PRINT101.74
2014-09-24PRINTEvent({'status': 0, 'limit_reached': False, 'created': Timestamp('2014-09-22 00:00:00+0000', tz='UTC'), 'stop': None, 'reason': None, 'stop_reached': False, 'commission': None, 'amount': 50, 'limit': 100.0, 'sid': Security(24, symbol='AAPL', security_name='APPLE INC', exchange='NASDAQ GLOBAL SELECT MARKET', start_date=datetime.datetime(1993, 1, 4, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 9, 30, 0, 0, tzinfo=), first_traded=None), 'id': '9bc9b28c2d9647518168ca4e9aa8da43', 'dt': Timestamp('2014-09-22 00:00:00+0000', tz='UTC'), 'filled': 0})
2014-09-25PRINT97.87
2014-09-25PRINTEvent({'status': 1, 'limit_reached': True, 'created': Timestamp('2014-09-22 00:00:00+0000', tz='UTC'), 'stop': None, 'reason': None, 'stop_reached': False, 'commission': 1.5, 'amount': 50, 'limit': 100.0, 'sid': Security(24, symbol='AAPL', security_name='APPLE INC', exchange='NASDAQ GLOBAL SELECT MARKET', start_date=datetime.datetime(1993, 1, 4, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 9, 30, 0, 0, tzinfo=), first_traded=None), 'id': '9bc9b28c2d9647518168ca4e9aa8da43', 'dt': datetime.datetime(2014, 9, 25, 0, 0, tzinfo=), 'filled': 50})
2014-09-26PRINT100.73
2014-09-26PRINTEvent({'status': 1, 'limit_reached': True, 'created': Timestamp('2014-09-22 00:00:00+0000', tz='UTC'), 'stop': None, 'reason': None, 'stop_reached': False, 'commission': 1.5, 'amount': 50, 'limit': 100.0, 'sid': Security(24, symbol='AAPL', security_name='APPLE INC', exchange='NASDAQ GLOBAL SELECT MARKET', start_date=datetime.datetime(1993, 1, 4, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 9, 30, 0, 0, tzinfo=), first_traded=None), 'id': '9bc9b28c2d9647518168ca4e9aa8da43', 'dt': datetime.datetime(2014, 9, 25, 0, 0, tzinfo=), 'filled': 50})
End of logs.