Hi, i pasted code from the link below
http://traders.com/Documentation/FEEDbk_docs/2019/10/TradersTips.html
and this was the result
Seems like the directive at line 6 is used in the link to make the code work. In my code, the directive is grayed out. What am i missing?
http://traders.com/Documentation/FEEDbk_docs/2019/10/TradersTips.html
and this was the result
Seems like the directive at line 6 is used in the link to make the code work. In my code, the directive is grayed out. What am i missing?
Rename
You should not be pasting code published in that section before Feb 2021 as they had been created for Wealth-Lab 5/6. Thus, they speak an incompatible WL6 "dialect":
http://traders.com/Documentation/FEEDbk_docs/2021/02/TradersTips.html#item3
http://traders.com/Documentation/FEEDbk_docs/2021/02/TradersTips.html#item3
Here is a translation:
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //construtor public MyStrategy() : base() { AddParameter("Period", ParameterType.Int32, 20, 5, 50, 5); AddParameter("Std Dev", ParameterType.Double, 2.0, 0.5, 5.0, 0.5); } //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { int period = Parameters[0].AsInt; double stdDev = Parameters[1].AsDouble; bbL = BBLower.Series(bars.Close, period, stdDev); bbU = BBUpper.Series(bars.Close, period, stdDev); PlotIndicatorBands(bbL, bbU, WLColor.Blue, 2, 25); StartIndex = period; } //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)) { //code your buy conditions here if ( //touches the lower band (bars.Close[idx - 1] > bbL[idx - 1]) && ((bars.Low[idx - 1] < bbL[idx - 1]) || (bars.Low[idx - 2] < bbL[idx - 2])) //engulfing: && (bars.Close[idx - 2] < bars.Open[idx - 2]) && (bars.Close[idx - 1] > bars.Open[idx - 1]) && (bars.Open[idx - 1] < bars.Close[idx - 2]) && (bars.Close[idx - 1] > bars.Open[idx - 2]) && (bars.Close[idx] > bars.High[idx - 1]) ) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } else { //code your sell conditions here if (bars.High[idx] > bbU[idx]) PlaceTrade(bars, TransactionType.Sell, OrderType.Market); } } //declare private variables below private BBLower bbL; private BBUpper bbU; } }
Thank you.
Your Response
Post
Edit Post
Login is required