【发布时间】:2019-09-29 09:47:48
【问题描述】:
我正在编写一个小型技术分析库,其中包含 TA-lib 中不可用的项目。我从在 cTrader 找到的示例开始,并将其与 TradingView 版本中的代码进行匹配。
这是来自 TradingView 的 Pine 脚本代码:
len = input(9, minval=1, title="Length")
high_ = highest(hl2, len)
low_ = lowest(hl2, len)
round_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val
value = 0.0
value := round_(.66 * ((hl2 - low_) / max(high_ - low_, .001) - .5) + .67 * nz(value[1]))
fish1 = 0.0
fish1 := .5 * log((1 + value) / max(1 - value, .001)) + .5 * nz(fish1[1])
fish2 = fish1[1]
这是我的尝试来实现该指标:
public class FisherTransform : IndicatorBase
{
public int Length = 9;
public decimal[] Fish { get; set; }
public decimal[] Trigger { get; set; }
decimal _maxHigh;
decimal _minLow;
private decimal _value1;
private decimal _lastValue1;
public FisherTransform(IEnumerable<Candle> candles, int length)
: base(candles)
{
Length = length;
RequiredCount = Length;
_lastValue1 = 1;
}
protected override void Initialize()
{
Fish = new decimal[Series.Length];
Trigger = new decimal[Series.Length];
}
public override void Compute(int startIndex = 0, int? endIndex = null)
{
if (endIndex == null)
endIndex = Series.Length;
for (int index = 0; index < endIndex; index++)
{
if (index == 1)
{
Fish[index - 1] = 1;
}
_minLow = Series.Average.Lowest(Length, index);
_maxHigh = Series.Average.Highest(Length, index);
_value1 = Maths.Normalize(0.66m * ((Maths.Divide(Series.Average[index] - _minLow, Math.Max(_maxHigh - _minLow, 0.001m)) - 0.5m) + 0.67m * _lastValue1));
_lastValue1 = _value1;
Fish[index] = 0.5m * Maths.Log(Maths.Divide(1 + _value1, Math.Max(1 - _value1, .001m))) + 0.5m * Fish[index - 1];
Trigger[index] = Fish[index - 1];
}
}
}
IndicatorBase class and CandleSeries class
问题
输出值似乎在预期范围内,但是我的 Fisher 变换交叉不与我在 TradingView 的指标版本中看到的匹配。
问题
如何在 C# 中正确实现 Fisher 变换指示器?我希望这与 TradingView 的 Fisher 变换输出相匹配。
我所知道的
我已经对照我个人编写的其他指标和来自 TA-Lib 的指标检查了我的数据,并且这些指标通过了我的单元测试。我还逐个对照 TradingView 数据检查了我的数据,发现我的数据符合预期。所以我不怀疑我的数据是问题所在。
细节
下图是上面显示的应用于 TradingView 图表的 Fisher 变换代码。我的目标是尽可能地匹配这个输出。
Fisher 青色 触发器 洋红色
预期输出:
交叉在东部时间 15:30 完成
-
Fisher 值约为 2.86
-
大约触发值为 1.79
交叉在东部时间 10:45 完成
-
Fisher 值约为 -3.67
-
大约触发值为 -3.10
我的实际输出:
交叉在东部时间 15:30 完成
-
我的费雪值是 1.64
-
我的触发值为 1.99
交叉在东部时间 10:45 完成
-
我的费雪值是 -1.63
-
我的触发值是-2.00
赏金
为了让您的生活更轻松,我提供了一个小型控制台应用程序 完成通过和失败的单元测试。所有单元测试都是 针对相同的数据集进行。通过的单元测试来自 测试工作 简单移动平均线指标。失败的单位 测试针对有问题的 Fisher 变换 指标。
Project Files(5/14 更新)
帮助我通过 FisherTransform 测试,我将奖励奖金。
如果您需要任何其他资源或信息,请发表评论。
我会考虑的替代答案
-
在 C# 中提交您自己的工作 FisherTransform
-
解释为什么我的 FisherTransform 实际上按预期工作
【问题讨论】:
-
那么我们如何测试我们是否正确?我们如何知道它是否符合您的规范?
-
如果它与 TradingView 的输出相匹配,我们就是黄金。 @TheGeneral
-
我认为您需要更多地考虑这一点,TradingViews 的实现有可能是不正确的,而且我们没有可匹配的测试数据,只有一个答案并且您测试它失败了告诉我们这是行不通的。我的意思是这可能会永远持续下去
-
我同意@TheGeneral,我不止一次发现TradingView formulas did not make sense。他们的商业模式主要依赖于用户提供的、可能未经证实的公式。
-
为了比较,请随意检查我的开源 .NET 库中Ehlers Fisher Transform 的实现。我在 GitHub 存储库中包含手动计算以进行比较。