- ago
I wrote an indicator that has the following line in the Populate() function:

CODE:
TimeSeries o = source.NamedSeries["Open Volume Bid"];


When I try to use this indicator in Strategy Builder I see the following error:



Please help me fix the error.
0
256
Solved
6 Replies

Reply

Bookmark

Sort
- ago
#1
Please don't end all your topic titles with a "." ? That's not necessary. Also I renamed the topic to better deliver the message rather than be too generic, can you feel the difference?

WAS: Using custom indicators in Strategy Builder.
Is: Exception on calling NamedSeries in custom indicator

At first you should check if the named series exists. You're not doing it, that's why the code fails. Please see an example of what I'm trying to convey in the QuickRef, BarHistory > NamedSeries. If after adding the check you're still having trouble, you could copy/paste the complete code here for our review.
0
- ago
#2
Eugene, hi!

Everything was done as you described above. When launching the strategy, it now gives another error.



CODE:
using WealthLab.Core; using System; using System.Drawing; using WealthLab.Indicators; namespace WealthLab.MyIndicators { public class Domindicator : IndicatorBase { //parameterless constructor public Domindicator() : base() { } //for code based construction public Domindicator(BarHistory source) : base() {          Parameters[0].Value = source; Populate(); }       //static Series method       public static Domindicator Series(BarHistory source)       {          return new Domindicator(source);       } //name public override string Name { get { return "DOMIndicator"; } } //abbreviation public override string Abbreviation { get { return "Domindicator"; } } //description public override string HelpDescription { get { return ""; } } //price pane public override string PaneTag { get { return "MyPane"; } }       //default color       public override WLColor DefaultColor       {          get          {             return WLColor.FromArgb(255,0,0,255);          }       }       //default plot style       public override PlotStyle DefaultPlotStyle       {          get          {             return PlotStyle.Line;          }       }       //populate       public override void Populate()       {          BarHistory source = Parameters[0].AsBarHistory;          if (Bars.NamedSeries.ContainsKey("Open Volume Bid")             && Bars.NamedSeries.ContainsKey("High Volume Bid")          && Bars.NamedSeries.ContainsKey("Low Volume Bid")          && Bars.NamedSeries.ContainsKey("Close Volume Bid")          && Bars.NamedSeries.ContainsKey("Vol Volume Bid")          && Bars.NamedSeries.ContainsKey("Open Volume Ask")          && Bars.NamedSeries.ContainsKey("High Volume Ask")          && Bars.NamedSeries.ContainsKey("Low Volume Ask")          && Bars.NamedSeries.ContainsKey("Close Volume Ask")          && Bars.NamedSeries.ContainsKey("Vol Volume Ask"))          {             BarHistory volumeBid = new BarHistory(source);             TimeSeries o = source.NamedSeries["Open Volume Bid"];             TimeSeries h = source.NamedSeries["High Volume Bid"];             TimeSeries l = source.NamedSeries["Low Volume Bid"];             TimeSeries c = source.NamedSeries["Close Volume Bid"];             TimeSeries v = source.NamedSeries["Vol Volume Bid"];             for (int bar = 0; bar < source.Count; bar++)             {                volumeBid.Add(source.DateTimes[bar], o[bar], h[bar], l[bar], c[bar], v[bar]);             }             BarHistory volumeAsk = new BarHistory(source);             o = source.NamedSeries["Open Volume Ask"];             h = source.NamedSeries["High Volume Ask"];             l = source.NamedSeries["Low Volume Ask"];             c = source.NamedSeries["Close Volume Ask"];             v = source.NamedSeries["Vol Volume Ask"];             for (int bar = 0; bar < source.Count; bar++)             {                volumeAsk.Add(source.DateTimes[bar], o[bar], h[bar], l[bar], c[bar], v[bar]);             }                   TimeSeries VolumeHighBidDivHighAsk = ((volumeBid.High +volumeBid.Low) /2) / ((volumeAsk.High +volumeAsk.Low) /2) * 100;             DateTimes = source.Close.DateTimes;             //modify the code below to implement your own indicator calculation             for (int n = 0; n < source.Close.Count; n++)             {                            if (((volumeBid.High[n] + volumeBid.Low[n]) / 2) >= ((volumeAsk.High[n] + volumeAsk.Low[n]) / 2))                {                   Values[n] = ((volumeBid.High[n] + volumeBid.Low[n]) / 2) / ((volumeAsk.High[n] + volumeAsk.Low[n]) / 2) * 100 - 100;                }                else                {                   Values[n] = -((volumeBid.High[n] + volumeBid.Low[n]) / 2) / ((volumeAsk.High[n] + volumeAsk.Low[n]) / 2) * 100 + 100;                }             }          }          else          {             for (int n = 0; n < source.Close.Count; n++)             {                Values[n] = -100000;             }          }     } //generate parameters protected override void GenerateParameters() {          AddParameter("Source", ParameterType.BarHistory, null); } } }
0
- ago
#3
Denis, looks like you have a compiler error there.
0
Cone8
 ( 24.80% )
- ago
#4
Let's take a closer look. Custom indicators are missing a reference when used in strategies.
0
- ago
#5
Confirmed the bug with referencing a custom indicator assembly in B20.
0
- ago
#6
Denis, consider it working again in B21. Just verified Dion's fix.
1
Best Answer

Reply

Bookmark

Sort