- ago
I have a small issue with an oscillator I developed by myself (in Tradingview). I wanted to transform it into WL8 but it does not work as planned.

The TimeSeries _ssmi should move between +100 and -100, but I only get a line that rises continously.

Maybe someone has an idea how I can realize this?

CODE:
public class SSMI : IndicatorBase { public SSMI() : base() { } public SSMI(BarHistory barHistory, TimeSeries source, int highLowPeriod, int smoothingFactor) : base() { Parameters[0].Value = barHistory; Parameters[1].Value = source; Parameters[2].Value = highLowPeriod; Parameters[3].Value = smoothingFactor; Populate(); } public static SSMI Series(BarHistory barHistory, TimeSeries source, int highLowPeriod, int smoothingFactor) { return new SSMI(barHistory, source, highLowPeriod, smoothingFactor); } protected override void GenerateParameters() { AddParameter("Bars", ParameterType.BarHistory, PriceComponent.Close); AddParameter("Source", ParameterType.TimeSeries, PriceComponent.Close); AddParameter("High/Low Period", ParameterType.Int32, 5); AddParameter("Smoothing Factor", ParameterType.Int32, 3); } public override string Name { get { return "Scaled Stochastic Momentum Index"; } } public override string Abbreviation { get { return "SSMI"; } } public override string HelpDescription { get { return ""; } } public override string PaneTag { get { return "SSMI"; } } public override PlotStyle DefaultPlotStyle { get { return PlotStyle.Line; } } public override WLColor DefaultColor { get { return WLColor.Green; } } public override void Populate() { BarHistory bars = Parameters[0].AsBarHistory; TimeSeries source = Parameters[1].AsTimeSeries; int highLowPeriod = Parameters[2].AsInt; int smoothingFactor = Parameters[3].AsInt; DateTimes = bars.DateTimes; if (bars.Count == 0 || bars.Count < highLowPeriod) return; TimeSeries hiLoDiff; TimeSeries relativeDiff = new TimeSeries(source.DateTimes); TimeSeries _ssmi = new TimeSeries(source.DateTimes); TimeSeries highestHigh = Highest.Series(bars.High, highLowPeriod); TimeSeries lowestLow = Lowest.Series(bars.Low, highLowPeriod); hiLoDiff = highestHigh - lowestLow; for (int bar = 1; bar < bars.Count; bar++) { relativeDiff = bars.Close[bar] - (highestHigh + lowestLow) / 2; } _ssmi = (EMA.Series(EMA.Series(relativeDiff, smoothingFactor), smoothingFactor) / (EMA.Series(EMA.Series(hiLoDiff, smoothingFactor), smoothingFactor) / 2) * 100); Values = _ssmi.Values; } }
0
231
Solved
2 Replies

Reply

Bookmark

Sort
- ago
#1
Here's the original Tradingview code

0
- ago
#2
Replace this...
CODE:
for (int bar = 1; bar < bars.Count; bar++) { relativeDiff = bars.Close[bar] - (highestHigh + lowestLow) / 2; }
with this...
CODE:
relativeDiff = bars.Close - (highestHigh + lowestLow) / 2;

No looping required. It can take place, but here you're just re-assigning the series over and over instead of working with its value on bar.

This works:
CODE:
public override void Initialize(BarHistory bars) {          var source = bars.Close;          var highLowPeriod = 5;          var smoothingFactor = 3;                    TimeSeries hiLoDiff;          TimeSeries relativeDiff = new TimeSeries(source.DateTimes);          TimeSeries _ssmi = new TimeSeries(source.DateTimes);          TimeSeries highestHigh = Highest.Series(bars.High, highLowPeriod);          TimeSeries lowestLow = Lowest.Series(bars.Low, highLowPeriod);          hiLoDiff = highestHigh - lowestLow;          relativeDiff = bars.Close - (highestHigh + lowestLow) / 2d;          var hld2 = (EMA.Series(EMA.Series(hiLoDiff, smoothingFactor), smoothingFactor) / 2d);          var rd2 = (EMA.Series(EMA.Series(relativeDiff, smoothingFactor), smoothingFactor));     _ssmi = rd2 / hld2 * 100.0;          PlotTimeSeries(_ssmi, "s","S"); }
1
Best Answer

Reply

Bookmark

Sort