- ago
Hello there..

Someone could tell me what I'm doing wrong here?

I'm trying to implement a system in 60 minutes but considering indicators on daily and weekly scale.





0
847
Solved
10 Replies

Reply

Bookmark

Sort
- ago
#1


0
Cone8
 ( 4.98% )
- ago
#2
Please hit the "Open as C# Coded Strategy", and copy/paste the code here.
0
- ago
#3
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase {     public MyStrategy() : base() { } public override void Initialize(BarHistory bars) {          indicator1 = new ScaledInd(bars,new StochD(bars,14,3),HistoryScale.Weekly);          PlotIndicator(indicator1,new WLColor(0,0,0));          indicator2 = new ScaledInd(bars,new SmoothedInd(bars,bars,14,3),bars.Close,3)),HistoryScale.Weekly);          PlotIndicator(indicator2,new WLColor(0,0,255));          indicator = new ScaledInd(bars,new StochD(bars,14,3),HistoryScale.Weekly);          indicator12 = new ScaledInd(bars,new StochD(bars,14,3),HistoryScale.Daily);          PlotIndicator(indicator12,new WLColor(255,0,0));          indicator22 = new ScaledInd(bars,new SmoothedInd(bars,bars,14,3),bars.Close,3)),HistoryScale.Daily);          PlotIndicator(indicator22,new WLColor(0,128,0));          indicator3 = new ScaledInd(bars,new StochD(bars,14,3),HistoryScale.Daily);          indicator13 = new StochD(bars,14,3);          PlotIndicator(indicator13,new WLColor(255,165,0));          indicator23 = new SmoothedInd(bars,new StochD(bars,14,3),new SMA(bars.Close,3));          PlotIndicator(indicator23,new WLColor(128,128,0));          source = bars.High;          pct = 0.00;          pct = (100.0 + pct) / 100.0;          multSource = source * pct;          PlotStopsAndLimits(3);          source2 = new ScaledInd(bars,new Lowest(bars.Low,1),HistoryScale.Daily);          PlotIndicator(source2,new WLColor(128,0,128));          pct2 = 0.00;          pct2 = (100.0 - pct2) / 100.0;          multSource2 = source2 * pct2;          PlotStopsAndLimits(3);          StartIndex = 14; } public override void Execute(BarHistory bars, int idx) {          int index = idx;          Position foundPosition0 = FindOpenPosition(0);          bool condition0;          if (foundPosition0 == null)          {             condition0 = false;             {                count = 0;                if (index - 0 >= 0 && indicator1[index] > indicator2[index - 0])                {                   count++;                }                if (indicator[index] < 10.00)                {                   count++;                }                if (count >= 1)                {                   count2 = 0;                   if (index - 0 >= 0 && indicator12[index] > indicator22[index - 0])                   {                      count2++;                   }                   if (indicator3[index] < 10.00)                   {                      count2++;                   }                   if (count2 >= 1)                   {                      if (indicator13.CrossesOver(indicator23, index))                      {                         condition0 = true;                      }                   }                }             }             if (condition0)             {                val = multSource[idx];                _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Stop, val, 0,"Buy at Stop 0% above High");             }          }          else          {             condition0 = false;             {                condition0 = true;             }             if (condition0)             {                Backtester.CancelationCode = 107;                val2 = multSource2[idx];                ClosePosition(foundPosition0, OrderType.Stop, + val2, "Sell at Stop 0% below Lowest(Low,1) to Daily");             }          } } public override void NewWFOInterval(BarHistory bars) {          indicator13 = new StochD(bars,14,3);          indicator23 = new SmoothedInd(bars,new StochD(bars,14,3),new SMA(bars.Close,3));          source = bars.High;          source2 = new ScaledInd(bars,new Lowest(bars.Low,1),HistoryScale.Daily); }       private int count;       private bool mc;       private IndicatorBase indicator1;       private IndicatorBase indicator2;       private IndicatorBase indicator;       private int count2;       private bool mc2;       private IndicatorBase indicator12;       private IndicatorBase indicator22;       private IndicatorBase indicator3;       private IndicatorBase indicator13;       private IndicatorBase indicator23;       private double pct;       private double val;       private TimeSeries source;       private TimeSeries multSource;       private double pct2;       private double val2;       private IndicatorBase source2;       private TimeSeries multSource2;       private Transaction _transaction; } }
0
Glitch8
 ( 10.62% )
- ago
#4
You cannot nest two Transformer indicators, here you are trying to apply a ScaleInd to a SmoothInd. This is a known limitation, this the error message.
0
Best Answer
- ago
#5
Oh...

But is there some way to implement this with building blocks? Because crossing a signal is a building block, not a problem. But compare with a signal i don't know if it's possible
0
- ago
#6
This is a limitation in Blocks but not so in C# strategy coding.
0
- ago
#7
Ok. Thanks.
0
Cone8
 ( 4.98% )
- ago
#8
It doesn't work for every indicator, but for many like StochD, you can get very close to the same result without using ScaleInd by just increasing your indicator Periods/Lengths proportionally for the scale.

For example, to get a StochD(14, 3) for daily bars from 60 minute bars, multiply both by 7 - just use StochD(98, 21). Here's how that comparison looks -


You'd be using the "Gold" series, which actually is more responsive, updating on every hourly bar.


3
- ago
#9
Thanks Cone, I was thinking if that would work, apparently, yes!
0
Cone8
 ( 4.98% )
- ago
#10
Yah, it's pretty close - certainly close enough for a stable, not overoptimized strategy. By the way, here's the code for that graph. Run it on 1-hour bars, market filter enabled so that there are 7 1-hour bars (the last one is really only 30 minutes).

CODE:
public override void Initialize(BarHistory bars) {          StochD stoD = StochD.Series(bars, 98, 21);          PlotIndicator(stoD, WLColor.Gold);                    BarHistory dbars = BarHistoryCompressor.ToDaily(bars);          StochD stochD = StochD.Series(dbars, 14, 3);          TimeSeries sto = TimeSeriesSynchronizer.Synchronize(stochD, bars.Close);          PlotTimeSeries(sto, "Daily StochD", stoD.PaneTag, WLColor.Red); }
1

Reply

Bookmark

Sort