20+ year WLD 3.x user ... just purchased WLD 8 and just starting to learn c# and play around with the program. Can anyone help me switch the Stop orders in Cone's channel breakout to StopLimit orders with limit 0.5% more/less than stop price? There are no StopLimit orders yet in the building block section.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript7 { public class MyStrategy : UserStrategyBase { public MyStrategy() : base() { AddParameter("Period", ParameterType.Int32, 50, 5, 100, 1); } public override void Initialize(BarHistory bars) { source = new Highest(bars.High,Parameters[0].AsInt); PlotIndicator(source,new WLColor(0,0,0)); source.MassageColors = true; pct = 0.01; pct = (100.0 + pct) / 100.0; multSource = source * pct; PlotStopsAndLimits(3); source2 = new Lowest(bars.Low,50); PlotIndicator(source2,new WLColor(0,0,255)); source2.MassageColors = true; pct2 = 0.01; pct2 = (100.0 - pct2) / 100.0; multSource2 = source2 * pct2; PlotStopsAndLimits(3); StartIndex = 50; } public override void Execute(BarHistory bars, int idx) { int index = idx; Position foundPosition0 = FindOpenPosition(0); bool condition0; if (foundPosition0 == null) { condition0 = false; { condition0 = true; } if (condition0) { val = multSource[idx]; _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Stop, val, 0,"Buy at Stop 0.01% above Highest(High,50)"); } } else { condition0 = false; { condition0 = true; } if (condition0) { Backtester.CancelationCode = 234; val2 = multSource2[idx]; ClosePosition(foundPosition0, OrderType.Stop, + val2, "Sell at Stop 0.01% below Lowest(Low,50)"); } } } public override void NewWFOInterval(BarHistory bars) { source = new Highest(bars.High,Parameters[0].AsInt); source2 = new Lowest(bars.Low,50); } private double pct; private double val; private IndicatorBase source; private TimeSeries multSource; private double pct2; private double val2; private IndicatorBase source2; private TimeSeries multSource2; private Transaction _transaction; } }
Rename
QUOTE:
20+ year WLD 3.x user ... just purchased WLD 8 and just starting to learn c# and play around with the program.
Great to hear from a veteran user, thank you for subscribing.
Adjust the entry part like this:
CODE:
_transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.StopLimit, val, 0,"Buy at Stop 0.01% above Highest(High,50)"); _transaction.StopLimitLimitPrice = val * 1.005;
And now the exit logic to:
CODE:
//ClosePosition(foundPosition0, OrderType.Stop, + val2, "Sell at Stop 0.01% below Lowest(Low,50)"); Transaction t = PlaceTrade(bars, TransactionType.Sell, OrderType.StopLimit,val2, "Sell at Stop 0.01% below Lowest(Low,50)"); t.StopLimitLimitPrice = val2 * 0.995;
Thank you. It is nice to see that all of the familiar names are still around.
Your Response
Post
Edit Post
Login is required