如何在 C# 中找到两个值之间的差异?
我正在使用一个在 10.000000 和 -10.000000 之间波动的振荡器,
该值每 5 分钟更改一次。 我想找出当前值和 5 分钟前的值之间的差异。 这是我的逻辑。
1 bar ago (1BA)= -.2
Current bar (CB) = .3
如果我执行以下操作,我不会得到值 1:
Abs(CB) - Abs(1BA) = .3 - .2 = 1
而:
Abs(CB- 1BA) = .3 - -.2 = 5
我想简单地计算振荡器从一个时间范围到另一个时间范围的移动之间的差异。 我是否以正确的逻辑应用腹肌?
这是我的实际代码,请假设我调用的方法是正确的:
if (Oscillator(PoFast, PoSlow, PoSmooth)[0] >
Oscillator(PoFast, PoSlow, PoSmooth)[3]
&& Math.Abs(Oscillator(PoFast, PoSlow, PoSmooth)[0] -
Oscillator(PoFast, PoSlow, PoSmooth)[3]) > .25)
I am working with an Oscillator that fluctuates between 10.000000 and -10.000000
The value changes say every 5 minutes. I want to find the difference between the current value and the value of 5 minutes ago. Here is my logic.
1 bar ago (1BA)= -.2
Current bar (CB) = .3
Wouldn't I get a value of 1 if I did something like:
Abs(CB) - Abs(1BA) = .3 - .2 = 1
Whereas:
Abs(CB- 1BA) = .3 - -.2 = 5
I want to simply calculate the difference between the move of the oscillator from one time frame to another. Am I applying the Abs with the right logic in mind?
Here is my actual code, please assume my method being called is correct:
if (Oscillator(PoFast, PoSlow, PoSmooth)[0] >
Oscillator(PoFast, PoSlow, PoSmooth)[3]
&& Math.Abs(Oscillator(PoFast, PoSlow, PoSmooth)[0] -
Oscillator(PoFast, PoSlow, PoSmooth)[3]) > .25)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这两个读数中,Abs(CB-1BA) 是正确的,因为两个读数之间存在 0.5 的变化。
编辑:为了使其更具可读性,并假设您获得双精度值,您可以执行类似的操作,但要进行错误检查,并且可能将 .25 设为变量。
Of the two, Abs(CB-1BA) would be correct, since there was a change of .5 between the two readings.
EDIT: To make it more readable, and assuming you're getting double values, you'd do something like this, but with error checking, and probably making the .25 a variable.
你的逻辑 Abs(CB-1BA) 是正确的。
顺便说一句,如果您不是开发人员,您真的认为您应该编写 C# 代码来交易期货合约吗? 它们的风险足以在最好的时候进行交易,更不用说当你编写代码来执行此操作并且你不是开发人员时!!!!
Your logic, Abs(CB-1BA) is correct.
As an aside, if you're not a developer do you really think you should be writing C# code to trade futures contracts? They're risky enough to trade at the best of times, never mind when you're writing code to do it and you're not a developer!!!!