- ago
Hello everyone, i've been trying to translate a strategy into wealth lab backtest but unfortunately i'm doing something wrong.

Here's the strategy.



the minimum of a candle need to be lower than the previous two candles;
the close needs to be higher than the last candle;
the buy order needs to be at the maximum of this candle;
and the stop loss at the minimum of the candle of entry.

i'm looking for a 2x profit the size of the candle, and a 1x stop loss the size of the candle.

i believe this pattern is really known, so im looking forward for some help. ty in advance.

this is what i came up with.

2
919
Solved
7 Replies

Reply

Bookmark

Sort
Cone8
 ( 28.25% )
- ago
#1
It looks like you got the entry part right. For the stop, you need this rule from the PowerPack extension -



There isn't a block rule available right now to specify a candle and use its range for a limit target. It's easy to do in a C# strategy, so just open a New C# Coded Strategy, replace the code with this, Compile, Save, and Run -

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript123 { 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) {          _L = Lowest.Series(bars.Low, 2);          StartIndex = 2;          PlotStopsAndLimits(3); } //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 (bars.Low[idx] < _L[idx - 1])                if (bars.Close[idx] > bars.Close[idx - 1])                   PlaceTrade(bars, TransactionType.Buy, OrderType.Stop, bars.High[idx]); } else {             //code your sell conditions here             Position pos = LastPosition;             int ebar = pos.EntryBar;             ClosePosition(pos, OrderType.Stop, bars.Low[ebar]);             double tgt = bars.High[ebar] + 2 * (bars.High[ebar] - bars.Low[ebar]);             ClosePosition(pos, OrderType.Limit, tgt); } }       //declare private variables below       Lowest _L;        } }
1
Best Answer
- ago
#2
We may need to create a condition that refers to the size of the bar before entry. That should benefit the users of Building Blocks.
0
Glitch8
 ( 12.08% )
- ago
#3
Instead of creating a new condition, maybe it can be expressed via an indicator and maybe a qualifier?
0
- ago
#4
It'd be possible but complicated for a new or demo user to construct this with e.g. MathIndOpInd. I think a simpler and more intuitive for Blocks users would be to expand the good old "Sell/Cover at Profit Target/Stop Loss" conditions with two extra inputs:

[ ] Multiple of bar size [DoubleUpDown] e.g. 1x, 2x... the bar size
[ ] Bars before entry bar [0, 1...]

With the new parameter enabled, the ProfitTarget/StopLoss parameter would instead refer to a multiple of the size of the bar before entry. What do you think?
1
MIH8
- ago
#5
The topic reminds me of the following discussion and the calculation for the ATR exit via blocks. Nested indicators became a problem.

https://www.wealth-lab.com/Discussion/How-to-set-get-entry-bar-s-price-in-exits-7976
0
Cone8
 ( 28.25% )
- ago
#6
QUOTE:
With the new parameter enabled, the ProfitTarget/StopLoss parameter would instead refer to a multiple of the size of the bar before entry. What do you think?
I was thinking the same, but to generalize it more, I'd make it a multiple of the HighestHigh - LowestLow for n-lookback and x-bars on or before the entry bar.
1
- ago
#7
The Blocks for "Take profit/Stop loss as a fraction of the signal bar size" are added to PowerPack B15:
https://www.wealth-lab.com/extension/detail/PowerPack#changeLog
0

Reply

Bookmark

Sort