I want to implement outlier detection because I should find when the market is quiet.
(我想实施离群值检测,因为我应该在市场不景气的时候找到它。)
In other words, I have a given array of candles and for each 5 of them I should determine whether the situation is quiet or not. (换句话说,我有一个给定的蜡烛阵列,对于每5支蜡烛,我应该确定情况是否安静。)
When is the situation quiet? (情况什么时候安静?)
A situation is quiet when it meets the following requirements:
(满足以下要求的情况是安静的:)
- All of these 5 candles are nearly small.
(所有这5支蜡烛都差不多。)
Candle's volume is calculated by the following formula: Math.Abs(candle.Open - candle.Close)
. (蜡烛的体积由以下公式计算: Math.Abs(candle.Open - candle.Close)
。)
The problem here is that I don't know how to differentiate a small from bigger candle.
(这里的问题是我不知道如何区分小蜡烛和大蜡烛。)
- The distance between the highest and the lowest element should not be so big.
(最高元素与最低元素之间的距离不应太大。)
The problem here is how to determine if the distance between the highest and the lowest value is big or small
(这里的问题是如何确定最大值和最小值之间的距离是大还是小)
My tries: (我的尝试:)
I tried by calculating the standard deviation but it seems like it can't help my case because the results are too random.
(我尝试通过计算标准偏差来进行尝试,但由于结果过于随机,因此似乎无济于事。)
These candles with higher volume should not meet the conditions. (这些高容量的蜡烛不符合条件。)
- StdDev = Standard Deviation
(StdDev =标准偏差)
- CV = Coefficient of Variation
(CV =变异系数)
Open time: 11/27/2019 1:00:00 AM | StdDev: 7.188532534530273E-05 | CV: 0.004710394164556892
Open time: 11/27/2019 2:00:00 AM | StdDev: 6.919176251549048E-05 | CV: 0.004528256709128957
Open time: 11/27/2019 3:00:00 AM | StdDev: 3.946517452134247E-05 | CV: 0.0025799290397687433
Open time: 11/27/2019 4:00:00 AM | StdDev: 3.6979724174201114E-05 | CV: 0.002417133418798687
Open time: 11/27/2019 5:00:00 AM | StdDev: 3.110466202999165E-05 | CV: 0.002034447120805262
Open time: 11/27/2019 6:00:00 AM | StdDev: 5.2985847166956244E-05 | CV: 0.003472887669067067
Open time: 11/27/2019 7:00:00 AM | StdDev: 8.348652585896753E-05 | CV: 0.0054882018050859535
Open time: 11/27/2019 8:00:00 AM | StdDev: 9.300537618869152E-05 | CV: 0.006126836376066635
Open time: 11/27/2019 9:00:00 AM | StdDev: 8.136338242723194E-05 | CV: 0.0053698114062323095
Open time: 11/27/2019 10:00:00 AM | StdDev: 3.840572873934283E-05 | CV: 0.002541742471167626
Open time: 11/27/2019 11:00:00 AM | StdDev: 7.612489737267272E-05 | CV: 0.00505410286633068
Open time: 11/27/2019 12:00:00 PM | StdDev: 0.0001445423813281074 | CV: 0.009635516387447998
Open time: 11/27/2019 1:00:00 PM | StdDev: 0.00016103571032538092 | CV: 0.010780272481281359
Open time: 11/27/2019 2:00:00 PM | StdDev: 0.0001487615541731129 | CV: 0.009964602731134899
Open time: 11/27/2019 3:00:00 PM | StdDev: 0.00019730686759461785 | CV: 0.013188080181446285
Open time: 11/27/2019 4:00:00 PM | StdDev: 0.00025021490762942194 | CV: 0.016638842108619628
Open time: 11/27/2019 5:00:00 PM | StdDev: 0.00024766408702111035 | CV: 0.016331294890940345
Open time: 11/27/2019 6:00:00 PM | StdDev: 0.0001475466028073844 | CV: 0.009644829572975841
Open time: 11/27/2019 7:00:00 PM | StdDev: 0.0002146625258399797 | CV: 0.01390211293568938
Open time: 11/27/2019 8:00:00 PM | StdDev: 0.00034918476484520355 | CV: 0.022346394780827054
Open time: 11/27/2019 9:00:00 PM | StdDev: 0.0003890790408130464 | CV: 0.02460501111826006
Open time: 11/27/2019 10:00:00 PM | StdDev: 0.0003559950842357241 | CV: 0.022273358207828574
Code:
(码:)
/// <summary>
/// Calculates the standard deviation.
/// </summary>
/// <param name="values"></param>
/// <returns></returns>
public static double StandardDeviation(this List<BinanceKline> values)
{
if (values.Count > 0)
{
// Compute average
double mean = values.Mean();
// Perform the Sum of (value - avg)_2_2
double sum = values.Sum(e => Math.Pow(Convert.ToDouble((e.GetUpperValue() + e.GetLowerValue()) / 2) - mean, 2));
// Put it all together
return Math.Sqrt(sum / (values.Count - 1));
}
return 0;
}
By the way, as a value, it gets the mean value of the candle (the highest value + the lowest value) / 2
.
(顺便说一下,作为一个值,它得到蜡烛的平均值(the highest value + the lowest value) / 2
。)
It might still be not clear what I want, so here is a picture:
(可能仍然不清楚我想要什么,所以这是一张照片:)
In the left side of the picture, there are no big candles, but the graphic is going up which means it is going far from the rest candles.
(在图片的左侧,没有大蜡烛,但是图形在上升,这意味着它与其余的蜡烛相去甚远。)
In the right side of the picture, the graphic stays quiet ("inline"). (在图片的右侧,图形保持安静(“嵌入式”)。)
It doesn't go up or down but straight. (它不会向上或向下而是直线。)
Can you suggest me how to detect those patterns?
(您能建议我如何检测这些模式吗?)
My idea is not predict for future values but by using already taken data. (我的想法不是预测未来的价值,而是使用已经获取的数据。)
For example those checks will appear on each new candle and it will take the previous 5 candles excluding the new one. (例如,这些检查将出现在每支新蜡烛上,并且将花费前五支蜡烛(不包括新蜡烛)。)
Edit:
(编辑:)
The standard deviation doesn't really work because if you look here:
(标准偏差实际上并不起作用,因为如果您在此处查看:)
Open time: 11/27/2019 12:00:00 PM | StdDev: 0.0001445423813281074 | CV: 0.009635516387447998
Open time: 11/27/2019 1:00:00 PM | StdDev: 0.00016103571032538092 | CV: 0.010780272481281359
The standard deviation should be higher value and definitely not close to 0. The code is working fine but it's just not suitable in this case or at least not alone.
(标准偏差应该是更高的值,并且绝对不能接近0。代码可以正常工作,但是不适用于这种情况,或者至少不是单独适用。)
In combination with something else, it might work. (结合其他东西,它可能会起作用。)
Edit2:
(编辑2:)
The coefficient of variation (CV) seems to be more accurate.
(变异系数(CV)似乎更准确。)
I think that might work. (我认为这可能有效。)
The optimal value for met conditions could be 0.001 as summary from both graphics. (满足条件的最佳值可能是0.001 ,这是两个图形的总和。)
What's your opinion? (你怎么看?)
Output for that example from the picture above:
(上面图片中该示例的输出:)
Open time: 11/15/2019 5:00:00 AM | StdDev: 49.24148243605151 | CV: 0.005714494887752725
Open time: 11/15/2019 6:00:00 AM | StdDev: 48.10100328995206 | CV: 0.005597444742963025
Open time: 11/15/2019 7:00:00 AM | StdDev: 34.570228051026604 | CV: 0.00403204199023016
Open time: 11/15/2019 8:00:00 AM | StdDev: 15.476614859199533 | CV: 0.0018079612622890022
Open time: 11/15/2019 9:00:00 AM | StdDev: 11.576726437123352 | CV: 0.0013526856869483194
Open time: 11/15/2019 10:00:00 AM | StdDev: 13.672853762107772 | CV: 0.0015963730504533972
Open time: 11/15/2019 11:00:00 AM | StdDev: 22.617282551182015 | CV: 0.0026365899074065743
Open time: 11/15/2019 12:00:00 PM | StdDev: 31.647747155208304 | CV: 0.0036823320018835684
Open time: 11/15/2019 1:00:00 PM | StdDev: 30.173184825271647 | CV: 0.0035044316829057126
Open time: 11/15/2019 2:00:00 PM | StdDev: 26.069585871279347 | CV: 0.0030231190376703017
Open time: 11/15/2019 3:00:00 PM | StdDev: 12.839695966026326 | CV: 0.0014866559587110115
Open time: 11/15/2019 4:00:00 PM | StdDev: 6.756121853548856 | CV: 0.0007815331369451161
Open time: 11/15/2019 5:00:00 PM | StdDev: 41.376141434406144 | CV: 0.004795673597019467
Open time: 11/15/2019 6:00:00 PM | StdDev: 79.81362075172356 | CV: 0.00928666074947359
Open time: 11/15/2019 7:00:00 PM | StdDev: 88.35104423548115 | CV: 0.010319785070149313
Open time: 11/15/2019 8:00:00 PM | StdDev: 79.06051554031244 | CV: 0.009271338691229074
Open time: 11/15/2019 9:00:00 PM | StdDev: 34.327389319609104 | CV: 0.00404133486502223
Open time: 11/15/2019 10:00:00 PM | StdDev: 8.048344239655792 | CV: 0.0009489408690167187
Open time: 11/15/2019 11:00:00 PM | StdDev: 6.030277356805678 | CV: 0.0007108047078810328
Open time: 11/16/2019 12:00:00 AM | StdDev: 7.8962145994142245 | CV: 0.0009308828374337032
Open time: 11/16/2019 1:00:00 AM | StdDev: 8.47613886153356 | CV: 0.00099890434169011
Open time: 11/16/2019 2:00:00 AM | StdDev: 9.912337262220127 | CV: 0.0011679248762150303
Open time: 11/16/2019 3:00:00 AM | StdDev: 12.102422484775284 | CV: 0.0014266919637413724
Open time: 11/16/2019 4:00:00 AM | StdDev: 12.490426133643089 | CV: 0.0014727030576166967
Open time: 11/16/2019 5:00:00 AM | StdDev: 12.640563970804447 | CV: 0.0014904318275539364
Open time: 11/16/2019 6:00:00 AM | StdDev: 15.174553947315598 | CV: 0.001790813176679162
Open time: 11/16/2019 7:00:00 AM | StdDev: 8.421461719915296 | CV: 0.0009946885198633634
Open time: 11/16/2019 8:00:00 AM | StdDev: 8.337805916426555 | CV: 0.0009848295065977384
Open time: 11/16/2019 9:00:00 AM | StdDev: 6.463572348167512 | CV: 0.0007636420370893617
Open time: 11/16/2019 10:00:00 AM | StdDev: 5.982922153931075 | CV: 0.0007068892832431122
Open time: 11/16/2019 11:00:00 AM | StdDev: 6.279278023786336 | CV: 0.0007414932821942903
Open time: 11/16/2019 12:00:00 PM | StdDev: 10.051010521335781 | CV: 0.0011860719031101202
Open time: 11/16/2019 1:00:00 PM | StdDev: 10.679646178596128 | CV: 0.0012597437184238111
Open time: 11/16/2019 2:00:00 PM | StdDev: 8.387603948685346 | CV: 0.0009891293173925218
Open time: 11/16/2019 3:00:00 PM | StdDev: 6.277716145224007 | CV: 0.0007401768729218733
Open time: 11/16/2019 4:00:00 PM | StdDev: 6.0087794101637115 | CV: 0.0007084052927520973
Open time: 11/16/2019 5:00:00 PM | StdDev: 5.152108063696313 | CV: 0.0006074484521114183
Open time: 11/16/2019 6:00:00 PM | StdDev: 5.4574552219879005 | CV: 0.0006434300416311673
Open time: 11/16/2019 7:00:00 PM | StdDev: 5.885869731823884 | CV: 0.000693675723796855
<span cla