I am trying to implement WillVal indicator. It seems to work, but there is one problem. When I change benchmark symbol in the parameters, the indicator value does not change. Why can this be?
CODE:
using WealthLab.Core; using System; using System.Drawing; using WealthLab.Indicators; namespace WealthLab.MyIndicators { public class WillVal : IndicatorBase { //parameterless constructor public WillVal() : base() { OverboughtLevel = 85; OversoldLevel = 15; } //for code based construction public WillVal(TimeSeries source, String benchmark, Int32 ema1, Int32 ema2, Int32 period) : base() { Parameters[0].Value = source; Parameters[1].Value = benchmark; Parameters[2].Value = ema1; Parameters[3].Value = ema2; Parameters[4].Value = period; OverboughtLevel = 85; OversoldLevel = 15; Populate(); } //static Series method public static WillVal Series(TimeSeries source, String benchmark, Int32 ema1, Int32 ema2, Int32 period) { return new WillVal(source, benchmark, ema1, ema2, period); } //name public override string Name { get { return "Will Val"; } } //abbreviation public override string Abbreviation { get { return "WillVal"; } } //description public override string HelpDescription { get { return "Larry William's WillVal. Benchmark TLT, GLD, UUP."; } } //price pane public override string PaneTag { get { return "WillVal"; } } //default color public override WLColor DefaultColor { get { return WLColor.Navy; } } //default plot style public override PlotStyle DefaultPlotStyle { get { return PlotStyle.Oscillator; } } //populate public override void Populate() { TimeSeries source = Parameters[0].AsTimeSeries; String benchmark = Parameters[1].AsString; Int32 ema1 = Parameters[2].AsInt; Int32 ema2 = Parameters[3].AsInt; Int32 period = Parameters[4].AsInt; DateTimes = source.DateTimes; if (period <= 0 || ema1 <= 0 || ema2 <= 0 || benchmark == "") return; TimeSeries price = new TimeSeries(DateTimes); TimeSeries value = new TimeSeries(DateTimes); TimeSeries wv = new TimeSeries(DateTimes); BarHistory bBenchmark = WLHost.Instance.GetHistory(benchmark, source.DetermineScale(), DateTime.MinValue, DateTime.MaxValue, 0, null); TimeSeries bPrice = TimeSeriesSynchronizer.Synchronize(bBenchmark.Close, source); TimeSeries ma1 = EMA.Series(source, ema1); TimeSeries ma2 = EMA.Series(source, ema2); price = bPrice / source; value = ma1 - ma2; // Calculate WV series for (int i = source.FirstValidIndex; i < source.Count; i++) { int start = Math.Max(0, i - period + 1); double min = value[start]; double max = value[start]; for (int j = start; j <= i; j++) { if (value[j] < min) min = value[j]; if (value[j] > max) max = value[j]; } if (max != min) Values[i] = 100.0 * (value[i] - min) / (max - min); else Values[i] = double.NaN; } } //generate parameters protected override void GenerateParameters() { AddParameter("Source", ParameterType.TimeSeries, PriceComponent.Close); AddParameter("Benchmark", ParameterType.String, "GLD"); AddParameter("EMA1", ParameterType.Int32, 2); AddParameter("EMA2", ParameterType.Int32, 22); AddParameter("Period", ParameterType.Int32, 65); } } }
Rename
You have:
price = bPrice / source;
Hence, via bPrice, price is based on your benchmark symbol. But, you never use price after you assign its values.
price = bPrice / source;
Hence, via bPrice, price is based on your benchmark symbol. But, you never use price after you assign its values.
QUOTE:That's right, error in calculations
Hence, via bPrice, price is based on your benchmark symbol. But, you never use price after you assign its values.
It seems the correct one is
CODE:and
price = bPrice / source; TimeSeries ma1 = EMA.Series(price, ema1); TimeSeries ma2 = EMA.Series(price, ema2);
CODE:
AddParameter("EMA1", ParameterType.Int32, 22); AddParameter("EMA2", ParameterType.Int32, 2);
Your Response
Post
Edit Post
Login is required