testidor
testidor
I would check out the schedule_function feature, it makes dealing with time management within your algo much simpler, especially when something only needs to happen at specific times, e.g. market open/close.
Here is the algo from above using the schedule function so that it closes its position each day before the close. I would have it wait until the bband has reverted before closing the position though, it seems like it just buys into a declining market each time right now.
David
@Barry - Look what happens in lines 28-29. If this is the second or subsequent time the handle_data function is called the same day (ie. it's 9:32 am EST/EDT or later), the function returns and the rest of its code is not executed.
If this is the first time, it's 9:31 am, and the function invests 100%; but it isn't 3:30 pm or later, so it doesn't execute the order to sell.
Also, your comments are out of sync with your code. Importantly, you write in lines 54-55 and 60-61 that you check whether you're long/short, but you don't. Add and current_position <= 0
before the closing parenthesis in line 57.