Nice job. Nearly perfect.
Re: BarsHeld
You don't have a condition to always exit after 1 bar. You have 2 specific exit conditions - if neither occurs, you'll continue to hold the position.
The other thing that you're missing is that you cannot evaluate data for a bar that doesn't exist yet. You're saying "today and yesterday", when really the code is "tomorrow (bar + 1) and what happened today (bar)".
When the loop gets to the last bar, Open/High/Low/Close/Volume[bar + 1] will throw an error, because you can't see the future. (This is by design - it's an error to peek into the future.) Consequently, for a strategy like this, you have to stop the loop before the last bar to avoid this error:
CODE:
Please log in to see this code.
That's the quick fix - keeping in mind there's no way a strategy that stops before processing the last bar can give you an Alert to buy or sell.
You can do a little better if you use a data provider that supports GetSessionOpen() (see QuickRef), but you still have a problem with the exit because the script also needs to know "tomorrow's high", i.e., High[bar + 1], which you can't know until the end of the day.
If you find that you like the strategy and want to trade it live, you could convert it to an intraday strategy and use 1 minute bars. BuyAtMarket would just be 1 minute late, and, you'd have to decide the high of the day 1 minute early, but this would be then a practical system to trade.