ARTICLE AD BOX
I'm trying to translate the pine-script code to BigBeluga's Two pole Trading View Oscillator to use on my cTrader charts. The Trading View code is here:
https://www.tradingview.com/script/2Ssn4yDZ-Two-Pole-Oscillator-BigBeluga/
I have created the following code in cTrader using Visual Studio, but the results don't appear to be the same on charts I've compared (Trading view's with the indicator vs cTrader's with my translated version of the indicator), and I can't seem to figure out where/what I'm doing wrong with my C# code for cTrader.
For instance, on all the TV charts I've looked at, the curves are nice and smooth; in comparison on cTrader half the times the oscillator's lines come out jagged and more pointy than a smooth curve.
So am hoping someone can point out any issues or something that may have "been lost in translation" with my attempt at converting the pine script to C# cTrader indicator framework.
I give it "full access" permissions so I could try debugging in VS to see if that would yield me any clues as to where the issues might be.
Here is my C# cTrader code:
using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; namespace cAlgo.Indicators { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)] public class TwoPoleOscillator : Indicator { [Parameter("Filter Length", DefaultValue = 20, MinValue = 1)] public int length { get; set; } // === OUTPUTS === [Output("two_p", LineColor = "#55ffda", Thickness = 1)] public IndicatorDataSeries two_p { get; set; } [Output("two_pp")] public IndicatorDataSeries two_pp { get; set; } [Output("buy", PlotType = PlotType.Points, LineColor = "#55ffda", Thickness = 3)] public IndicatorDataSeries buy_plot { get; set; } [Output("sell", PlotType = PlotType.Points, LineColor = "#8c5bff", Thickness = 3)] public IndicatorDataSeries sell_plot { get; set; } // === SERIES === private IndicatorDataSeries sma_n1; private IndicatorDataSeries sma_closeMinusSma1; private IndicatorDataSeries smooth1; private IndicatorDataSeries smooth2; private SimpleMovingAverage sma1; private SimpleMovingAverage sma_norm; private StandardDeviation stdev_norm; protected override void Initialize() { #if DEBUG var result = System.Diagnostics.Debugger.Launch(); #endif sma_n1 = CreateDataSeries(); sma_closeMinusSma1 = CreateDataSeries(); smooth1 = CreateDataSeries(); smooth2 = CreateDataSeries(); sma1 = Indicators.SimpleMovingAverage(Bars.ClosePrices, 25); sma_norm = Indicators.SimpleMovingAverage(sma_closeMinusSma1, 25); stdev_norm = Indicators.StandardDeviation(sma_closeMinusSma1, 25, MovingAverageType.Simple); } public override void Calculate(int index) { //if (index < 30) // return; // === CALCULATIONS === sma_closeMinusSma1[index] = (Bars.ClosePrices[index] - sma1.Result[index]); sma_n1[index] = ((Bars.ClosePrices[index] - sma1.Result[index]) - (sma_norm.Result[index])) / stdev_norm.Result[index]; // === TWO-POLE FILTER === double alpha = 2.0 / (length + 1); if (double.IsNaN(smooth1[index - 1])) smooth1[index] = sma_n1[index]; else smooth1[index] = (1 - alpha) * smooth1[index] + alpha * sma_n1[index]; if (double.IsNaN(smooth2[index - 1])) smooth2[index] = sma_n1[index]; else smooth2[index] = (1 - alpha) * smooth2[index] + alpha * smooth1[index]; two_p[index] = smooth2[index]; two_pp[index] = index >= 4 ? two_p[index - 4] : double.NaN; // === SIGNALS === bool buy = index > 4 && two_p[index - 1] < two_pp[index - 1] && two_p[index] > two_pp[index] && two_p[index] < 0; bool sell = index > 4 && two_p[index - 1] > two_pp[index - 1] && two_p[index] < two_pp[index] && two_p[index] > 0; buy_plot[index] = buy ? two_p[index] : double.NaN; sell_plot[index] = sell ? two_p[index] : double.NaN; } } }