Is there a way (hopefully using the Building Blocks) that I can make a strategy that buys immediately at market open if the open is higher than the last bar's high? I tried to use the Gap indicator compared to value +1.0, but it is buying 1 bar too late. For example...
--Bar 1--
O: $2
H: $10
L: $1
C: $9
--Bar 2--
O: $12
H: $20
L: $11
C: $19
--Bar 3--
O: $22
H: $30
L: $21
C: $29
Right now, I can get it to assess that Bar2 opens higher than Bar1, but I can't get it to buy on Bar2 rather than Bar3. I want it to buy in the morning on Bar2 immediately after it acknowledges that Bar2's Open price is larger than Bar1's High. Any tips?
--Bar 1--
O: $2
H: $10
L: $1
C: $9
--Bar 2--
O: $12
H: $20
L: $11
C: $19
--Bar 3--
O: $22
H: $30
L: $21
C: $29
Right now, I can get it to assess that Bar2 opens higher than Bar1, but I can't get it to buy on Bar2 rather than Bar3. I want it to buy in the morning on Bar2 immediately after it acknowledges that Bar2's Open price is larger than Bar1's High. Any tips?
Rename
To process the session's open price of the current trading day, a WL8 strategy requires overriding the ExecuteSessionOpen virtual method in C# code. An example of such strategy is familiar to you through @Cone's development on your request:
https://www.wealth-lab.com/Discussion/9891
This kind of task is beyond the capability of Building Blocks.
https://www.wealth-lab.com/Discussion/9891
This kind of task is beyond the capability of Building Blocks.
Here are the steps to modify a block strategy as C# Code for that.
1. Open as a C# Coded Strategy
2. Find the condition that triggers the trade and comment it out (as shown below)
3. Copy "ExecuteSessionOpen" block of code below. If the statement from #2 looks a little different than the one show here, then copy and substitute it.
4. Everywhere you see a _setup statement below, add it to your code in the same places.
5. Save your C# Coded strategy.
1. Open as a C# Coded Strategy
2. Find the condition that triggers the trade and comment it out (as shown below)
3. Copy "ExecuteSessionOpen" block of code below. If the statement from #2 looks a little different than the one show here, then copy and substitute it.
4. Everywhere you see a _setup statement below, add it to your code in the same places.
5. Save your C# Coded strategy.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript123 { public class ShortTheGap : UserStrategyBase { public override void Initialize(BarHistory bars) { StartIndex = 1; } public override void Execute(BarHistory bars, int idx) { bool condition0 = true; _setup = false; if (condition0) { _setup = true; //_transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy At Market (1)"); } } public override void ExecuteSessionOpen(BarHistory bars, int idx, double sessionOpenPrice) { if (_setup && sessionOpenPrice > bars.High[idx] ) _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy At Market (1)"); } //private variables Transaction _transaction; bool _setup; } }
I just noticed that I missed using the _setup parameter in ExecuteSessionOpen(). Please review that block of code above.
By the way, for this to work:
1. Select Wealth-Data in the Historical Providers. It's very fast to load the opening price for the day.
2. If trading symbols not in Wealth-Data, you'll need a historical provider that will give you a partial bar that has the opening price in near real time. (Q-Data won't do it.)
3. You can schedule the Strategy Monitor to run maybe 2 or 3 seconds after the open.
4. Remember that NYSE stocks often have delayed openings on the primary market, so the opening price that you get here might not match the one for Wealth-Data, which will be the open of the primary market (NYSE).
CODE:
WAS: if (sessionOpenPrice > bars.High[idx] ) SHOULD BE: if (_setup && sessionOpenPrice > bars.High[idx] )
By the way, for this to work:
1. Select Wealth-Data in the Historical Providers. It's very fast to load the opening price for the day.
2. If trading symbols not in Wealth-Data, you'll need a historical provider that will give you a partial bar that has the opening price in near real time. (Q-Data won't do it.)
3. You can schedule the Strategy Monitor to run maybe 2 or 3 seconds after the open.
4. Remember that NYSE stocks often have delayed openings on the primary market, so the opening price that you get here might not match the one for Wealth-Data, which will be the open of the primary market (NYSE).
I emailed the concierge email because there are a few more things that I want to do with this strategy. Are you guys still doing the concierge coding?
Your Response
Post
Edit Post
Login is required