I am using Wealthlab 8, build 14.
Have not used Wealthlab in a long time.
Can someone help me code this trading strategy:
Buy October 15 and sell May 1st.
Thanks,
Larry
Have not used Wealthlab in a long time.
Can someone help me code this trading strategy:
Buy October 15 and sell May 1st.
Thanks,
Larry
Rename
We will add a Date Filter condition to upcoming build 7 of the PowerPack extension that will let you build such strategies without any code:
https://www.wealth-lab.com/extension/detail/PowerPack
https://www.wealth-lab.com/extension/detail/PowerPack
It looks like a rule like that would only work for 2022, right? We probably need a DayOfYear rule.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript4 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { _dayOfYearBuy = (new DateTime(2022, 10, 15)).DayOfYear - 1; _dayOfYearSell = (new DateTime(2022, 5, 1)).DayOfYear - 1; WriteToDebugLog(_dayOfYearBuy + ", " + _dayOfYearSell); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { if (bars.DateTimes[idx].DayOfYear >= _dayOfYearBuy) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } else { Position pos = LastPosition; if (bars.DateTimes[idx].DayOfYear >= _dayOfYearSell) if (pos == null || pos.EntryDate.Year != bars.DateTimes[idx].Year) ClosePosition(LastPosition, OrderType.Market); } } //declare private variables below int _dayOfYearBuy; int _dayOfYearSell; } }
QUOTE:
It looks like a rule like that would only work for 2022, right?
No, if you enable "Ignore Years".
Eugene and Cone,
Thank you for your help.
Presently, during back testing, I am missing some years. From 1994 to 2021, I am missing trades for buying (1995, 1996, 2001, 2001, 2002, 2003, 2008, 2010, 2012, 2015, 2016, 2018, 2020).
Can you please make all years trade.
Thank you so much.
Larry
Thank you for your help.
Presently, during back testing, I am missing some years. From 1994 to 2021, I am missing trades for buying (1995, 1996, 2001, 2001, 2002, 2003, 2008, 2010, 2012, 2015, 2016, 2018, 2020).
Can you please make all years trade.
Thank you so much.
Larry
Do one of the following:
1. Cut down on the Position size so that all trades can be taken
2. If you want to use 100% equity, use some margin
3. Or (new for WL7/8) change the "Basis Price" selection in the Position Sizing control to "Market Open next Bar". Hit F1 to read about it in "Strategy Settings" topic.
1. Cut down on the Position size so that all trades can be taken
2. If you want to use 100% equity, use some margin
3. Or (new for WL7/8) change the "Basis Price" selection in the Position Sizing control to "Market Open next Bar". Hit F1 to read about it in "Strategy Settings" topic.
QUOTE:
...Or (new for WL7/8) change the "Basis Price" selection in the Position Sizing control to "Market Open next Bar". Hit F1 to read about it in "Strategy Settings" topic. ...
Cone.
Worked great... Can I save the strategy setting for all strategies for "Market Open next bar"?
Thank you,
Larry
There's a button at the bottom of the Settings page to "Save as Default for New Strategies".
Your Response
Post
Edit Post
Login is required