我如何才能找到在C#2值之间的差异? [英] How can I find the difference between 2 values in C#?

查看:137
本文介绍了我如何才能找到在C#2值之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与10.000000和-10.000000之间波动的振荡器工作



价值的变化,每5分钟说。我想找到当前值和的5分钟前的值之间的差。这是我的逻辑。

  1巴前(1BA)= -.2 
当前条(CB)= 0.3

难道我得到的值为1,如果我不喜欢的东西:

  ABS(CB) -  ABS(1BA)= 0.3  -  0.2 = 1 

鉴于:

  ABS(CB-1BA)= 0.3  -  -.2 = 5 

我想简单计算振荡器的移动从一个时间帧到另一个之间的差。 ?我是应用在ABS与正确的逻辑记



下面是我实际的代码,请假设我的方法被称为是正确的:

 如果(振荡器(PoFast,PoSlow,PoSmooth)[0]> 
振荡器(PoFast,PoSlow,PoSmooth)[3]
&功放;&安培; Math.Abs​​(振荡器(PoFast,PoSlow,PoSmooth)[0] -
振荡器(PoFast,PoSlow,PoSmooth)[3])> 0.25)


解决方案

二,ABS(CB-1BA)将是正确的,因为有一个变化.5两次读数



修改:为了使其更具可读性,假设你得到双重价值,你会怎么做这样的事情,但有错误检查,而且很可能使.25变量。

 双击[] =值振荡器(PoFast ,PoSlow,PoSmooth); 
双currentBar =值[0];
双oneBarAgo =值[3];

如果(currentBar> oneBarAgo和放大器;&安培; Math.Abs​​(currentBar - oneBarAgo)GT; 0.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)

解决方案

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.

double[] values = Oscillator(PoFast, PoSlow, PoSmooth);
double currentBar = values[0];
double oneBarAgo = values[3];

if (currentBar > oneBarAgo && Math.Abs(currentBar - oneBarAgo) > .25)
{
    // do something
}

这篇关于我如何才能找到在C#2值之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆