DIY8
- ago
I have two strategies which I would like to transfer. Both coded mainly with Eugene's help. What format would you like me to send them? png, screenshot, Word?
0
583
Solved
13 Replies

Reply

Bookmark

Sort
- ago
#1
Hi,

Could you please refresh me on when/how we agreed to transfer (convert) them?
0
DIY8
- ago
#2
Eugene - I could not find the quote but it mentioned something about Evolver. I have one strategy and a small strategy, both scripted by yourself. Ian

'Will Wealth-Lab 7|8 recognize my strategies from WL6?
No, but they're pretty easy to convert, and we'll be happy to assist if needed'.
0
- ago
#3
I'd say the preferred way now would be to use Building Blocks as a DIY project (pun intended) to re-create them in WL8 for they have become very flexible and powerful. But if their application is not obvious or the source strategy's complexity exceeds the capacity of Blocks, we'll be happy to assist as said. In this case please feel free to create a topic per each strategy and provide its complete source code (of course not in PNG, screenshot or Word). tia.
0
DIY8
- ago
#4
Eugene - OK will start a project as suggested. Thought about Concierge but no challenge. Ian
0
DIY8
- ago
#5
No luck in trying without instructions or manual. Just would like it transferred to WL8 so that I can use it. Attached strategy (and Indicators) and script.

Eugene said 'no PNG, Screenshot or Word'. Not sure what you want then?
0
- ago
#6
If you copy/paste the WL6 code from the Strategy on screenshots I could whip up a translation of it to WL8. (Perhaps later I could also help you make the score a custom reusable Indicator for better convenience.)
0
DIY8
- ago
#7
OK Eugene, I will give it a go. Ian

CODE:
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; namespace WealthLab.Strategies {    public class ScoreStrategy : WealthScript    {       public double ScoreIt(double val)       {             if (val >0.05)return 1;       if (val <-0.05)return 0;          return 0.5;    }        StrategyParameter paramDays;    StrategyParameter paramScore;       public ScoreStrategy()    {          paramDays = CreateParameter("Days",5,3,30,5);          paramScore = CreateParameter("Score",2,1,6,0.5);                 // Days = value/min/max/increment          // Score = value/min/max/increment       }          protected override void Execute()          {          int days = paramDays.ValueInt;          double scoreThreshold = paramScore.Value;                 const int nLines = 5;          DataSeries[] reglines = new DataSeries[nLines];          DataSeries[] regRoc = new DataSeries[nLines];          DataSeries score = new DataSeries(Bars, "The Score");              Color[] clr = new Color[5];          clr[0] =Color.Red;          clr[1] = Color.Blue;          clr[2] = Color.Green;          clr[3] = Color.Fuchsia;          clr[4] = Color.Black;                 ChartPane rocPane = CreatePane(40, true, true);                 // Create and plot the series          for (int n = 0; n < nLines; n++)          {             reglines[n] = LinearReg.Series(Close, days);             regRoc[n] = ROC.Series(reglines[n], 1); // 3-day rate of change             days += 2;                    PlotSeries(PricePane, reglines[n],clr[n],LineStyle.Solid, 1);             PlotSeries(rocPane,regRoc[n],clr[n],LineStyle.Solid, 1);          }          // Now that we have the series let's create a score series          for(int bar = 5; bar < Bars.Count; bar++)          {          // calculate score          double sum = 0;          for (int n = 0; n < nLines; n++)          {          sum += ScoreIt(regRoc[n][bar]);                    }          score[bar] = sum;                 //calculate mean turnover (bars)                 DataSeries turnover = Close * Volume;          DataSeries meanturnover = SMA.Series(turnover, 20);                 //trading          if (IsLastPositionActive)          {             Position p = LastPosition;             if (score[bar] + score[bar - 1] + score[bar - 2] < (scoreThreshold + 6))                             SellAtClose(bar +1, p);                    }          else if (score[bar] + score[bar - 1] + score[bar - 2] >= (scoreThreshold + 6))          {             BuyAtClose(bar +1);          }       }                 // saving the score in a series makes it easy to plot          ChartPane scorePane = CreatePane(40, true, true);          PlotSeries(scorePane, score, Color.Blue, LineStyle.Histogram, 2);          }          }          }
0
- ago
#8
Here's a word for word translation of your code to WL8:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript4 { public class ScoreStrategy : UserStrategyBase {       public double ScoreIt(double val)       {          if (val > 0.05)return 1;          if (val < -0.05) return 0;          return 0.5;       }       public ScoreStrategy()       {          AddParameter("Days", ParameterType.Int32, 5, 30, 30, 5);          AddParameter("Score", ParameterType.Double, 2, 1, 6, 0.5);       }        //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          int days = Parameters[0].AsInt;          double scoreThreshold = Parameters[1].AsDouble;          const int nLines = 5;          TimeSeries[] reglines = new TimeSeries[nLines];          TimeSeries[] regRoc = new TimeSeries[nLines];          score = new TimeSeries(bars.DateTimes);          WLColor[] clr = new WLColor[5] { WLColor.Red, WLColor.Blue, WLColor.Green, WLColor.Fuchsia, WLColor.Black };          // Create and plot the series          for (int n = 0; n < nLines; n++)          {             reglines[n] = LR.Series(bars.Close, days);             regRoc[n] = ROC.Series(reglines[n], 1); // 3-day rate of change             days += 2;             PlotTimeSeries(reglines[n], reglines[n].Description, "Price", clr[n], PlotStyle.Line);             PlotTimeSeries(regRoc[n], regRoc[n].Description, "rocPane", clr[n], PlotStyle.Line);          }          // Now that we have the series let's create a score series          for (int bar = 5; bar < bars.Count; bar++)          {             // calculate score             double sum = 0;             for (int n = 0; n < nLines; n++)             {                sum += ScoreIt(regRoc[n][bar]);             }             score[bar] = sum;          }          PlotTimeSeries(score, "score", "scorePane", WLColor.Blue, PlotStyle.Histogram);          //calculate mean turnover (bars)          turnover = bars.Close * bars.Volume;          meanturnover = SMA.Series(turnover, 20);          StartIndex = 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(score[idx] + score[idx - 1] + score[idx - 2] >= (scoreThreshold + 6))                PlaceTrade(bars, TransactionType.Buy, OrderType.MarketClose); } else {             //code your sell conditions here             Position p = LastPosition;             if (score[idx] + score[idx - 1] + score[idx - 2] < (scoreThreshold + 6))                ClosePosition(p, OrderType.MarketClose); } }       //declare private variables below       int days;       double scoreThreshold;       TimeSeries score, turnover, meanturnover;    } }
0
Best Answer
DIY8
- ago
#9
Thanks very much Eugene. It works perfectly. Now can I twist your arm for my final request for transfer a small strategy called Meanturnover. Ian

CODE:
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; namespace WealthLab.Strategies {    public class MyStrategy0 : WealthScript    {       protected override void Execute()       {          DataSeries turnover = Close*Volume;                    DataSeries meanturnover = SMA.Series(turnover,5);                    meanturnover.Description = "meanturnover";                    PlotSeries(PricePane, meanturnover, Color.Blue,WealthLab.LineStyle.Solid, 2);          }}}
0
- ago
#10
You're welcome Ian. DIY stands for do it yourself, and this time you'll be proud because you'll really be doing it yourself :)

Turnover is a built-in indicator. You can apply a SMA or any other smoother to it without coding. Familiarize yourself with Transformer indicators. (Use the Help and Youtube videos on change logs - both are helpful immensely.) In this simplest case, the SmoothInd indicator is what you're looking for: SMA of Turnover.

Good luck.
0
DIY8
- ago
#11
Thanks Eugene. That was simple and makes sense. I can now start Optomising, Backtesting and comparing Strategies using the samples, plus my own stats - no more coding. Ian
1
DIY8
- ago
#12
Hi Eugene, you wrote this strategy some time ago. I have since transferred it to a new computer and WL8.

The buy and sell parameters in some instances do not align with the buy or sell on the chart. With the threshold score at 3.0 the Threshold + 6 = 9 for the sum of the present score + present score - 1 and present score -2. Regards, Ian

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript2 {    public class ScoreStrategy : UserStrategyBase    {       public double ScoreIt(double val)       {          if (val > 0.05) return 1;          if (val < -0.05) return 0;          return 0.5;       }       public ScoreStrategy()       {          AddParameter("Days", ParameterType.Int32, 5, 30, 30, 5);          AddParameter("Score", ParameterType.Double, 3.0, 1, 6, 0.5);       }       //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {          int days = Parameters[0].AsInt;          double scoreThreshold = Parameters[1].AsDouble;          const int nLines = 5;          TimeSeries[] reglines = new TimeSeries[nLines];          TimeSeries[] regRoc = new TimeSeries[nLines];          score = new TimeSeries(bars.DateTimes);          WLColor[] clr = new WLColor[5] { WLColor.Red, WLColor.Blue, WLColor.Green, WLColor.Fuchsia, WLColor.Black };          // Create and plot the series          for (int n = 0; n < nLines; n++)          {             reglines[n] = LR.Series(bars.Close, days);             regRoc[n] = ROC.Series(reglines[n], 1); // 3-day rate of change             days += 2;             PlotTimeSeries(reglines[n], reglines[n].Description, "Price", clr[n], PlotStyle.Line);             PlotTimeSeries(regRoc[n], regRoc[n].Description, "rocPane", clr[n], PlotStyle.Line);          }          // Now that we have the series let's create a score series          for (int bar = 5; bar < bars.Count; bar++)          {             // calculate score             double sum = 0;             for (int n = 0; n < nLines; n++)             {                sum += ScoreIt(regRoc[n][bar]);             }             score[bar] = sum;          }          PlotTimeSeries(score, "score", "scorePane", WLColor.Blue, PlotStyle.Histogram);          //calculate mean turnover (bars)          turnover = bars.Close * bars.Volume;          meanturnover = SMA.Series(turnover, 20);          StartIndex = 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 (score[idx] + score[idx - 1] + score[idx - 2] >= (scoreThreshold + 6))                PlaceTrade(bars, TransactionType.Buy, OrderType.MarketClose);          }          else          {             //code your sell conditions here             Position p = LastPosition;             if (score[idx] + score[idx - 1] + score[idx - 2] < (scoreThreshold + 6))                ClosePosition(p, OrderType.MarketClose);          }       }       //declare private variables below       int days;       double scoreThreshold;       TimeSeries score, turnover, meanturnover;    } }
0
- ago
#13
Ian, I doubt I wrote this strategy but I'm sure I made a word for word translation of its WL6 code. (Since it's too much profusion to have the many topics covering the same strategy, I've merged the second topic with this one.)
https://www.wealth-lab.com/Discussion/Transfer-WL6-strategies-to-WL8-9830

@Cone did the WL6 version, though.
https://wl6.wealth-lab.com/Forum/Posts/Linear-regression-scores-32506

QUOTE:
With the threshold score at 3.0 the Threshold + 6 = 9 for the sum of the present score + present score - 1 and present score -2.

Not sure what you're trying to say with this sentence.

QUOTE:
regRoc[n] = ROC.Series(reglines[n], 1); // 3-day rate of change

No, it's 1-day rate of change.
0

Reply

Bookmark

Sort