- ago
Hello everyone,

I used to use the old WealthLab and it was WAY SIMPLER to build strategies. Now I found myself struggling trying to build anything in this software.
If someone could help me out with this strategy I would be really thankful about it.
The strategy is described below:

Buy at market close when the price closes below the 3 period SMA calculated by the lows.
Sell at market close when price closes above the 3 period SMA calculated by the highs.

Attached I have a screenshot of how the strategy works.

Thank you in advance



0
397
Solved
9 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.81% )
- ago
#1
The old WealthLab? You mean Wealth-Lab Desktop (version 1?) Or, 2, 3, 4, 5, 6?

Sorry you're having trouble, but WL is not geared toward buying at the market close, especially based on indicators that are calculated from the closing price of that very bar. I mean, how can you know the closing price before the market is even closed?

Also, shouldn't your Sell at Close say "above" instead of "below?"
0
Glitch8
 ( 11.81% )
- ago
#2
But, if you really want to do this, here's how you'd code it for WL7:

CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //Initialize public override void Initialize(BarHistory bars) {          smaLow = SMA.Series(bars.Low, 3);          smaHigh = SMA.Series(bars.High, 3);          PlotIndicator(smaLow);          PlotIndicator(smaHigh);          StartIndex = 4; } //Execute public override void Execute(BarHistory bars, int idx) {          if (idx == bars.Count - 1)             return; if (OpenPositions.Count == 0) { if (bars.Close[idx + 1] < smaLow[idx + 1])                PlaceTrade(bars, TransactionType.Buy, OrderType.MarketClose); } else { if (bars.Close[idx + 1] > smaHigh[idx + 1])                PlaceTrade(bars, TransactionType.Sell, OrderType.MarketClose); } }       //private members       private SMA smaHigh;       private SMA smaLow; } }
0
Best Answer
- ago
#3
QUOTE:
... WL is not geared toward buying at the market close, especially based on indicators that are calculated from the closing price of that very bar.

And that's the point. The strategy needs to look into the future with the [idx+1] index below.
CODE:
if (bars.Close[idx + 1] < smaLow[idx + 1]) if (bars.Close[idx + 1] > smaHigh[idx + 1])
And that's fine until you get to the "present" trading day when you can't look forward, in which case, your Alert signals (for the present day) will never occur. Clearly, the point has nothing to do with creating trading signals for "present day" trading.

For trading signals, what's wrong with using the closing prices to determine the signal for trading on the "next" bar (for the next morning)?
0
Glitch8
 ( 11.81% )
- ago
#4
Right. I mean it’s fine for backtesting, but people should be aware of the potential difficulties trading a buy at close strategy like this.
0
- ago
#5
Perhaps the intent here is to trade on 5-minute bars and make the decision at the end of the 3:55pm ET bar, then trade (buy or sell) at 3:56pm on the last bar? But using 5-minute bars was never mentioned here. But that's doable.

Also, placing a trade at 3:56pm may not execute by 4pm. That's a risk.
0
- ago
#6
Thank you very much for the help, really appreciate it !
That's exactly what I was looking for.

In regards to the entry, I'm planning to entry at the end of the end, as close as possible to when the markets close and the same applies for when I'm selling the position.
In order to "visually" see where I would have to entry, I would have to offset the moving averages in 1, like I have on this screenshot below:



But when it comes to the backtest, I can't offset to 1 exatcly because I wouldn't know where the moving average would be since it's calculated for the values when the markets close.
And my strategy is based upon the values of the moving averages of the last 3 days so technically I would entry only on the 4th day.
0
Glitch8
 ( 11.81% )
- ago
#7
Sounds like you’re well aware of the complications! Glad to be of help 🙂
1
- ago
#8
It's truly amazing that most all such topics asking to trade at close get started by users from Brazil. My guess is that some trading educator they're following may be a heavy promoter of the idea.

https://www.wealth-lab.com/Discussion/Buy-Sell-at-close-and-Entry-Bar-6081
https://www.wealth-lab.com/Discussion/Buy-at-close-6716
https://www.wealth-lab.com/Discussion/Entries-exits-at-market-close-6807
https://www.wealth-lab.com/Discussion/How-to-buy-at-open-and-sell-at-close-the-same-day-6836
https://www.wealth-lab.com/Discussion/Close-order-at-a-specific-hour-6847
https://www.wealth-lab.com/Discussion/Reverse-into-short-position-at-market-close-6914

Dion, we need to launch Wealth-Lab Brazil Edition with ubiquitous support for AtClose orders! :)
1
- ago
#9
Note that Wealth-Lab has a preference to place a true Market On Close (MOC) order N minutes before the market close:

Preferences Data/Trading
MarketClose Orders submit how many minutes before market close...

Exchanges require Market On Close (MOC) orders to be submitted 5 or 10 minutes before the close to participate in the closing auction. What the preference does is "hold" an MOC order that you placed until N minutes before the close. At that time, the Order Manager will actually send the order to the broker.

Make sure to read the Help for this preference for more details.

In short, no matter how you slice it, you need to place an order well before the close to get the settled closing price.
0

Reply

Bookmark

Sort