Trying to figure out a way to predict the price of the lower bollinger band at open the next day. I can backtest using the below Rule8 but I'm aiming for a way to get the actual number that this might produce at open so I could use that as a condition in place of Rule8 below.
CODE:
Please log in to see this code.
Is there a way to code out the calculation of the lower bollinger band where bars 0-18 are used and bar 0 is used twice. I tried to convert something I had somewhere else into WLP but have only got this far and think I'm on the right track but not sure.
MiddleBB-2.5*SQR(((Close[bar]- MiddleBB)^2 +(Close[bar]- MiddleBB)^2 +(Close[bar-1]- MiddleBB)^2 +(Close[bar-2]- MiddleBB)^2 +(Close[bar-3]- MiddleBB)^2 +(Close[bar-4]- MiddleBB)^2 +(Close[bar-5]- MiddleBB)^2 +(Close[bar-6]- MiddleBB)^2 +(Close[bar-7]- MiddleBB)^2 +( Close[bar-8]- MiddleBB)^2 +( Close[bar-9]- MiddleBB)^2 +( Close[bar-10]- MiddleBB)^2 +( Close[bar-11]- MiddleBB)^2 +( Close[bar-12]- MiddleBB)^2 +( Close[bar-13]- MiddleBB)^2 +( Close[bar-14]- MiddleBB)^2 +( Close[bar-15]- MiddleBB)^2 +( Close[bar-16]- MiddleBB)^2 +( Close[bar-17]- MiddleBB)^2 +( Close[bar-18]- MiddleBB)^2 )/20)
Size:
Color:
Here's your formula for the
current bar as I understand it. You can get Open[bar+1] shortly after the market's open using Open.PartialValue or GetSessionOpen with providers that support it.
CODE:
Please log in to see this code.
Size:
Color:
Or if you wish to make it more universal:
CODE:
Please log in to see this code.
Size:
Color:
Here's another way to look at it. If you're operating on the Open, then you should test that way too. Here's a mock-up that compares the predicted bband series using the Opening price with the bband using the Close for the same day. You can see how the "red" series is fairly accurately predicting the BBand for the
next day. (Try using a short period to better see the effect.)
CODE:
Please log in to see this code.
Size:
Color:
Thanks! That worked as expected.
Is it possible to automate a strategy where you place a limit order only if Today's open is below Today's lower bollinger band? I realize the bollinger band moves throughout the day which is why I was trying to predict that value and can use that in place of the actual bollinger band as it would remain constant. I've included what I have below to when backtesting but always receive the below error message with every symbol. I'm assuming it is because of the Open[bar+1] and LowerBB[bar+1]. If I'm going about this the wrong way any suggestions are welcome.
Error processing symbol AAPL Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
CODE:
Please log in to see this code.
Size:
Color:
Your assumption is correct. If it was that simple to use Open[bar+1] we would've suggested it, wouldn't we? If you review Cone's code carefully, you'll notice a pointer to GetSessionOpen in the QuickRef that makes possible to run this kind of strategy after market open.
Size:
Color:
Thanks for the help on that. Was able to get things set up to run after market open as suggested.
Had a question about prioritization using the predicted bollinger band. I'm trying to set priority for if a stock opens below the predicted BB with a standard dev of 3 to take priority over one that opens between a standard dev of 3 and 2.5. I'd be using the same limit order in my last post. I saw some post in the forum about prioritizing using the highest value and by timeofday but don't think either of those would work here. Is this possible?
CODE:
Please log in to see this code.
Size:
Color:
So the lower the open price is the better, right? If so, you'd use a lower GetSessionOpen value as the Position.Priority:
CODE:
Please log in to see this code.
A minus before
GetSessionOpen prioritizes lower values. Coding on-the-fly just to give you an idea.
Size:
Color:
Wouldn't that prioritize based on lowest opening price? I'm not necessarily going for the lowest open price. If I have 10 stocks that all open below below the 2.5 deviation and 4 of the 10 open below the 3 deviation I would want to prioritize those 4 to execute first.
Size:
Color:
You're right. In this case you'd want to prioritize stocks with the biggest negative difference between LowerBB2[bar] and GetSessionOpen instead.
Size:
Color:
You can "peek" in order to make that prioritization in backtesting. In all likelihood (but not necessarily) in live trading those 4 stocks would have executed first. It's not necessarily the case because of the staggered open of listed stocks on the NYSE... an issue might not open until, say, 0933, during which time another one of your limit orders were hit.
For other limit orders, however, the only correct way to assign priority in backtesting is by time-of-day, which is not easy to do unless you have clean EOD and intraday data. See
Setting Priority for AtStop/AtLimit Orders.
Size:
Color:
@Eugene - Would the biggest negative difference work? I would think the price of the stock (higher priced would likely have higher negative difference) would have an impact on that as well which is why I was trying to use a standard deviation of 3 which would help remove the stock price from priority.
@Cone - I think I understand. I'm using the Fidelity data for GetSessionOpen so I would hope that would be clean but it depends on when they get their data as well although it would be nice to see this in backtesting if possible even knowing that it is peeking. I did review the SetTimeOfDayPriority but this isn't exactly what I'm trying to do although I understand why this is used with the limit order.
Right now I have 2 separate scans for this and I just run the scan with deviation of 3 first to get those trades then run the 2.5 right after. It sounds like this might be the only way to accurately do this at this point.
Size:
Color: