Hi,
I would like to implement a strategy in WL7. I currently run it manually. Simplifying for example's sake:
About 30min before market close, I look at the mostly formed daily candle. If it's green, I buy at market price. If it's red, I sell any open positions at market price
Is this possible with Building Blocks or in a C# coded strategy? Maybe there's a workaround where I use 6 hour candles or something like that?
I've read these posts but I believe my question is different: I don't want to peek ahead at the next bar, or enter exactly at the close. I want to make a decision based on a mostly complete daily candle then enter and fill an order before the market closes.
https://www.wealth-lab.com/Discussion/Buy-At-Close-in-Blocks-5650
https://wealth-lab.com/Discussion/How-to-buy-at-open-and-sell-at-close-the-same-day-6836
https://www.wealth-lab.com/Support/Faq (How can my strategy from Blocks enter or exit at close?)
https://www.wealth-lab.com/Discussion/How-do-I-enter-at-the-close-of-the-day-5504
Thanks!
I would like to implement a strategy in WL7. I currently run it manually. Simplifying for example's sake:
About 30min before market close, I look at the mostly formed daily candle. If it's green, I buy at market price. If it's red, I sell any open positions at market price
Is this possible with Building Blocks or in a C# coded strategy? Maybe there's a workaround where I use 6 hour candles or something like that?
I've read these posts but I believe my question is different: I don't want to peek ahead at the next bar, or enter exactly at the close. I want to make a decision based on a mostly complete daily candle then enter and fill an order before the market closes.
https://www.wealth-lab.com/Discussion/Buy-At-Close-in-Blocks-5650
https://wealth-lab.com/Discussion/How-to-buy-at-open-and-sell-at-close-the-same-day-6836
https://www.wealth-lab.com/Support/Faq (How can my strategy from Blocks enter or exit at close?)
https://www.wealth-lab.com/Discussion/How-do-I-enter-at-the-close-of-the-day-5504
Thanks!
Rename
Hi,
You can implement it with a MarketClose order + "...how many minutes before the close" in Preferences > Trading. Please strike F1 while in Trading Preferences for more info.
You can implement it with a MarketClose order + "...how many minutes before the close" in Preferences > Trading. Please strike F1 while in Trading Preferences for more info.
Hi Eugene,
Thanks for the response and the F1 help tip! I didn't know about that shortcut.
I think I may be implementing this MarketClose incorrectly. Let's say I see my exit signal 30min before close on Tuesday, based on the mostly-formed Tuesday daily candle. I want to submit a market order to close right then, 30min before close on Tuesday.
What I had originally with building blocks was it was submitting a market order Wednesday at open. Now, with the MarketClose orders implemented (see below), it appears to submit the market order Wednesday, 30min before close.
What am I doing wrong in my code?
Thanks for the response and the F1 help tip! I didn't know about that shortcut.
I think I may be implementing this MarketClose incorrectly. Let's say I see my exit signal 30min before close on Tuesday, based on the mostly-formed Tuesday daily candle. I want to submit a market order to close right then, 30min before close on Tuesday.
What I had originally with building blocks was it was submitting a market order Wednesday at open. Now, with the MarketClose orders implemented (see below), it appears to submit the market order Wednesday, 30min before close.
What am I doing wrong in my code?
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript2 { public class MyStrategy : UserStrategyBase { public MyStrategy() : base() { } public override void Initialize(BarHistory bars) { indicator = new SMA(bars.Volume,14); PlotIndicator(indicator,Color.FromArgb(255,0,0,0)); indicator2 = bars.Close; indicator1 = new EMA(bars.Close,8); PlotIndicator(indicator1,Color.FromArgb(255,0,0,255)); indicator22 = new EMA(bars.Close,21); PlotIndicator(indicator22,Color.FromArgb(255,255,0,0)); ha = HeikinAshi.Convert(bars); indicator12 = bars.Close; indicator23 = new EMA(bars.Close,8); ha2 = HeikinAshi.Convert(bars); StartIndex = 21; } public override void Execute(BarHistory bars, int idx) { int index = idx; Position foundPosition0 = FindOpenPosition(0); bool condition0; if (foundPosition0 == null) { condition0 = false; { if (indicator[index] > 500000.00) { if (indicator2[index] > 20.00) { if (index - 0 >= 0 && indicator1[index] > indicator22[index - 0]) { if (ha.Close[index] > ha.Open[index]) { condition0 = true; } } } } } if (condition0) { _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy At Market (1)"); } } else { condition0 = false; { if (index - 0 >= 0 && indicator12[index] < indicator23[index - 0]) { condition0 = true; } } if (condition0) { ClosePosition(foundPosition0, OrderType.MarketClose, 0, "Sell At Market (1)"); } condition0 = false; { if (ha2.Close[index] <= ha.Open[index]) { condition0 = true; } } if (condition0) { ClosePosition(foundPosition0, OrderType.MarketClose, 0, "Sell At Market (1)"); } } } private IndicatorBase indicator; private TimeSeries indicator2; private IndicatorBase indicator1; private IndicatorBase indicator22; private BarHistory ha; private TimeSeries indicator12; private IndicatorBase indicator23; private BarHistory ha2; private Transaction _transaction; } }
You could run this using 30 minute data, then code your strategy to submit when the time is 3:30. You could also use the synchronizers to compress the 30 minute data to daily for analysis as needed.
Your Response
Post
Edit Post
Login is required