https://www.tradingview.com/script/2Ssn ... BigBeluga/
Ich habe den folgenden Code in cTrader mit Visual Studio erstellt, aber die Ergebnisse scheinen in den von mir verglichenen Diagrammen nicht die gleichen zu sein (Handelsansichten mit dem Indikator vs. cTraders mit meiner übersetzten Version des Indikators), und ich Ich kann anscheinend nicht herausfinden, wo/was ich mit meinem C#-Code für cTrader falsch mache.
Zum Beispiel sind die Kurven in allen TV-Charts, die ich mir angesehen habe, schön glatt; Im Vergleich dazu erscheinen bei cTrader die Hälfte der Fälle, in denen die Linien des Oszillators gezackt und spitzer sind als eine glatte Kurve.
Ich hoffe also, dass jemand auf Probleme oder etwas hinweisen kann, das bei meinem Versuch, das Pine-Skript in das C#-cTrader-Indikator-Framework zu konvertieren, „in der Übersetzung verloren gegangen“ sein könnte.
Ich gebe ihm „Vollzugriff“-Berechtigungen, damit ich versuchen kann, in VS zu debuggen, um zu sehen, ob mir das irgendwelche Hinweise geben würde wo die Probleme liegen könnten.
Hier ist mein C# cTrader-Code:
Code: Select all
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;
}
}
}
Mobile version