- ago
Need some help with following example to convert WL6 to 7 to get a better understanding. Any help would be appreciated
CODE:
         for (int bar = 300; bar < Bars.Count; bar++)          {             if (IsLastPositionActive)             {                Position p = LastPosition;                if (p.PositionType == PositionType.Long)                {                   int bt2 = 0;                   if ((Low[bar] < 1.01 * Lowest.Series(Low, 70)[bar - 10]) && (Low[bar] < 1.002 * Lowest.Series(Low, 10)[bar - 1]) && (Low[bar] > 0.995 * Lowest.Series(Low, 70)[bar - 1]))                      bt2 = 1;                   if ((Close[bar] <= Lowest.Series(Low, slider17.ValueInt)[bar - 1]) && (bt2 <= 0))                      SellAtMarket(bar + 1, p, "Exit 2");                   int s1 = 0;                   int yy = 0;                   for (int pa = bar - 4; pa <= bar; pa++)                   {                      if ((reversalGravestoneDoji[pa]) && (High[pa] > Highest.Series(High, 15)[pa - 1]))                         s1 = 1;                      if (HullMA.Series(Close, 10)[pa] < HullMA.Series(Close, 10)[pa - 1])                         yy = 1;                      if (HullMA.Series(Close, 10)[pa] > HullMA.Series(Close, 10)[pa - 1])                         yy = 0;                   }                   if (((s1 + yy) >= 2) && (bt2 <= 0))                      SellAtMarket(bar + 1, p, "Exit 6");                }             }
0
946
Solved
6 Replies

Reply

Bookmark

Sort
- ago
#1
Hi,

A head-on conversion may not be evident because parameter sliders are defined much differently (and this is outside the scope of your code snippet - see examples in the V7 QuickRef for: https://www.wealth-lab.com/Support/ApiReference/Parameter)

If you haven't downloaded the updated V6 QuickRef with Version 7 equivalents, I sincerely recommend getting it from here:

https://wl6.wealth-lab.com/Forum/Posts/Download-Version-6-9-QuickRef-with-Version-7-Equivalents-40609
0
- ago
#2
I have no problem with WL7 parameter sliders. I have difficulty setting up the loops and the structure within to make trades. In WL6 their were enough canned strategies included to help with understanding trying to do different things but it is not the case with WL7. I do like the TD interface.
0
Cone8
 ( 13.28% )
- ago
#3
I can help. It's really not very different if you following the translation hints here.
0
- ago
#4
I'm sure there are quite a bit of strategies to illustrate a lot of coding concepts now - up to insider buying and code-based rotation. Have you actually taken a look at the topic I referred? You don't set up the trading loop anymore in V7 and that's explained on the picture there:

https://wl6.wealth-lab.com/Forum/Posts/Download-Version-6-9-QuickRef-with-Version-7-Equivalents-40609
0
Cone8
 ( 13.28% )
- ago
#5
This should get you going.
- You need to have installed the Advanced Smoothers extension.
- Pay attention to the comments.
- I substituted a "Neutral Gravestone Doji" for your "Reversal Gravestone Doji" since it appears we don't have the latter in the Candlestick library yet. If there's a difference, we can add that later.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; using WealthLab.AdvancedSmoothers; using WealthLab.Candlesticks; namespace WealthScript4 {    public class StrategyGiorgos : UserStrategyBase    {       IndicatorBase _lowest;       IndicatorBase _highest;       IndicatorBase _hullMA;              private CandleGenePattern _cp;       public StrategyGiorgos()       {          AddParameter("slider0", ParameterTypes.Int32, 20, 10, 30, 1); // this is Parameters[0]          AddParameter("slider1", ParameterTypes.Int32, 20, 10, 30, 1); // this is Parameters[1]          AddParameter("slider2", ParameterTypes.Int32, 20, 10, 30, 1); // etc.          AddParameter("slider3", ParameterTypes.Int32, 20, 10, 30, 1);          AddParameter("slider4", ParameterTypes.Int32, 20, 10, 30, 1);          // etc.       }       public override void Initialize(BarHistory bars)       {          StartIndex = 300;          _lowest = Lowest.Series(bars.Low, 70);          _highest = Highest.Series(bars.High, 15);          _hullMA = HMA.Series(bars.Close, 10);          _cp = CandleGeneDecoder.FindPattern("Neutral Gravestone Doji");       }       /** NOTE - I changed the parameter reference from "int idx" to "int bar" to match the code **/       public override void Execute(BarHistory bars, int bar)       {                   if (CandleGeneDecoder.DetectPattern(bars, bar, _cp))          {             CandleEventItem cfi = new CandleEventItem(_cp, bars.DateTimes[bar]);             CandleBarGlyph cbg = new CandleBarGlyph(cfi, _cp);             DrawCustomBarGlyph(bar, cbg);          }                    if (!HasOpenPosition(bars, PositionType.Long))          {             //code your buy conditions here          }          else          {             Position p = LastPosition;             if (p.PositionType == PositionType.Long)             {                int bt2 = 0;                if ((bars.Low[bar] < 1.01 * _lowest[bar - 10]) && (bars.Low[bar] < 1.002 * _lowest[bar - 1]) && (bars.Low[bar] > 0.995 * _lowest[bar - 1]))                   bt2 = 1;                /** Change the Parameters index as required - should be Parameters[16] or Parameters[17] - depends on the order added above **/                if ((bars.Close[bar] <= Lowest.Series(bars.Low, Parameters[0].AsInt)[bar - 1]) && (bt2 <= 0))                {                   ClosePosition(p, OrderType.Market, 0, "Exit 2");                }                                int s1 = 0;                int yy = 0;                for (int pa = bar - 4; pa <= bar; pa++)                {                   if ((CandleGeneDecoder.DetectPattern(bars, pa, _cp)) && (bars.High[pa] > _highest[pa - 1]))                      s1 = 1;                   if (_hullMA[pa] < _hullMA[pa - 1])                      yy = 1;                   if (_hullMA[pa] > _hullMA[pa - 1])                      yy = 0;                }                if (((s1 + yy) >= 2) && (bt2 <= 0))                   ClosePosition(p, OrderType.Market, 0, "Exit 6");             }           } } } }
1
Best Answer
- ago
#6
thanks, very helpful will save lots of time
0

Reply

Bookmark

Sort