in wld6, i used a way just like
but in wld8 or newest version, how could i do the same?
please help me, i need convert some wld6 code to wld8 !
CODE:
if ( BuyAtStop( bar+2, Highest.Series( Bars.High, lookback )[bar], "Long" ) == null ){ ShortAtStop( bar+2, Lowest.Series( Bars.Low, lookback )[bar], "Short" ); }
but in wld8 or newest version, how could i do the same?
please help me, i need convert some wld6 code to wld8 !
Rename
Using bar + 2 in a signal is actually a peeking error in Version 6 (it would have created a Position in the backtest one bar ahead of when it was actually possible).
But ignoring that, the idea is to prioritize the Buy over the Short if both signals could have occurred on the same bar. To do it, you need to peek ahead. WL (Version 8) doesn't allow you to peek unless you try hard to do it. This would be one of those situations.
Below is framework you can use. It will avoid the peeking error, always prioritizing the Buy in the backtest. On the last bar, it will generate both signals to send to the broker - which the broker may not allow and result in an order error.
In any case, for live trading you'll probably need to enable "Use Live Positions" in the Trading Preferences to make sure you're dealing with the correct position type.
But ignoring that, the idea is to prioritize the Buy over the Short if both signals could have occurred on the same bar. To do it, you need to peek ahead. WL (Version 8) doesn't allow you to peek unless you try hard to do it. This would be one of those situations.
Below is framework you can use. It will avoid the peeking error, always prioritizing the Buy in the backtest. On the last bar, it will generate both signals to send to the broker - which the broker may not allow and result in an order error.
In any case, for live trading you'll probably need to enable "Use Live Positions" in the Trading Preferences to make sure you're dealing with the correct position type.
CODE:
using System; using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using WealthLab.DataExtensions; using System.Collections.Generic; namespace WealthScript3 { public class Strategy12415 : UserStrategyBase { Parameter _lookback; IndicatorBase _highest; IndicatorBase _lowest; public Strategy12415() { _lookback = AddParameter("Lookback", ParameterType.Int32, 20, 10, 30, 2); } public override void Initialize(BarHistory bars) { _highest = Highest.Series(bars.High, _lookback.AsInt); _lowest = Lowest.Series(bars.Low, _lookback.AsInt); // PlotIndicatorLine(_highest, WLColor.Green, 1, LineStyle.Dotted); // PlotIndicatorLine(_lowest, WLColor.Red, 1, LineStyle.Dotted); PlotStopsAndLimits(3); StartIndex = _lookback.AsInt; } public override void Execute(BarHistory bars, int idx) { Position p = LastPosition; if (p == null || !p.IsOpen) { bool buyFilled = false; // don't peek for the fill on the last bar to avoid error if (idx < bars.Count - 1) buyFilled = bars.High[idx + 1] >= _highest[idx]; PlaceTrade(bars, TransactionType.Buy, OrderType.Stop, _highest[idx], "Long"); if (!buyFilled) PlaceTrade(bars, TransactionType.Short, OrderType.Stop, _lowest[idx], "Short"); } else { if (idx + 1 - p.EntryBar >= 1) ClosePosition(p, OrderType.Market, 0, "Time based"); if (p.PositionType == PositionType.Long) { //handle the long position } else { //handle the short position } } } } }
@Cone
thank u first! that's an good idea.
but i think that is not elegant way LoL!
if u have any time,please tell me,Why is there such a big difference in the new version?
As a user since the 3rd generation, we has always relied on our app.
Today, when I was translating some code, I found that many function names have been changed, and some function help is very brief, such as EMA & EMA2. Before, I could easily find two options: [EMACalculation.Legacy, EMACalculation.Modern], but now it is difficult to distinguish between EMA and EMA2, which one I really need.
The oversimplified function description caused me a lot of confusion
at last, I don't know if it's path dependency or I'm not used to it yet, why do I feel that wld8 is not as user-friendly as wld6
thank u first! that's an good idea.
but i think that is not elegant way LoL!
if u have any time,please tell me,Why is there such a big difference in the new version?
As a user since the 3rd generation, we has always relied on our app.
Today, when I was translating some code, I found that many function names have been changed, and some function help is very brief, such as EMA & EMA2. Before, I could easily find two options: [EMACalculation.Legacy, EMACalculation.Modern], but now it is difficult to distinguish between EMA and EMA2, which one I really need.
The oversimplified function description caused me a lot of confusion
at last, I don't know if it's path dependency or I'm not used to it yet, why do I feel that wld8 is not as user-friendly as wld6
WealthLab 7 (now 8) was a complete re-write from scratch with the benefit of over 20 years of experience for modern Windows technologies. It takes work to get used to any new platform, and sure, the framework has changed significantly - it's far more versatile and summarized in this blog - Anatomy of a Wealth-Lab Strategy.
What's not elegant about that solution? That's how stop and limit trades are "filled" by the backtest engine - by comparing prices. Here, you're doing it yourself because you need to peek ahead. By the way that was actually a flaw in WL6. Since the trade was "filled" on the bar before the entry, the backtest/script had access to a future position. That's not possible to do in WL8.
What's not elegant about that solution? That's how stop and limit trades are "filled" by the backtest engine - by comparing prices. Here, you're doing it yourself because you need to peek ahead. By the way that was actually a flaw in WL6. Since the trade was "filled" on the bar before the entry, the backtest/script had access to a future position. That's not possible to do in WL8.
yep!you are right, I think i should adapt to the new environment, forget the past and embrace the new situation。Instead of reminiscing about the past, i should try to explore how to achieve it in the new environment.
last question,
Strategy Square seems to be much quieter than before, will it be lively again? What I mean is that I have not actively updated version 7 and version 8 in the past few years, because they do not have as many public strategies as version 6 for reference.
last question,
Strategy Square seems to be much quieter than before, will it be lively again? What I mean is that I have not actively updated version 7 and version 8 in the past few years, because they do not have as many public strategies as version 6 for reference.
"Strategy Square" - I like that name. It's up to everyone to make it active again!
Right now, there's not much of an incentive to participate, so maybe that's what's needed.
Right now, there's not much of an incentive to participate, so maybe that's what's needed.
Your Response
Post
Edit Post
Login is required