/// <summary>
    /// 获取 EMA 值
    /// </summary>
    /// <param name="index">下标</param>
    /// <returns></returns>
    float F_GetEMA(int length, int index = 0)
    {
        if (V_Cache == null)
        {
            return(0);
        }

        if (V_Cache.V_KLineData.Count < length + index)
        {
            return(0);
        }

        return(EMA.GetEMA(length, V_Cache.V_KLineData.GetRange(index, length)));
    }
Esempio n. 2
0
        public bool IsMatch(Dictionary <int, KLineCache> klineDataDic, float btcLSPercent, List <int> MACycleList)
        {
            switch (type)
            {
            case MatchConditionType.MA:

                int value = (int)args1;

                if (!klineDataDic.ContainsKey(value) && value % 1440 == 0)
                {
                    int        merge = value / 1440;
                    KLineCache cache = new KLineCache();
                    cache.RefreshData(klineDataDic[1440].GetMergeKLine(merge));
                    klineDataDic[value] = cache;
                }

                if (klineDataDic.ContainsKey(value))
                {
                    KLineCache kLineCache = klineDataDic[value];

                    List <float> maList = new List <float>();

                    List <float> perList = new List <float>();

                    for (int i = 0; i < paramsList1.Count; i++)
                    {
                        int maIndex = (int)paramsList1[i];

                        float maValue = 0;

                        if (maIndex == 0)
                        {
                            maValue = kLineCache.V_KLineData[0].V_ClosePrice;
                        }
                        else
                        {
                            if (MACycleList[maIndex - 1] > kLineCache.V_KLineData.Count)
                            {
                                return(false);
                            }

                            maValue = MA.GetMA(MACycleList[maIndex - 1], kLineCache.V_KLineData);
                        }


                        maList.Add(maValue);


                        float perValue = MathF.Abs((kLineCache.V_KLineData[0].V_ClosePrice - maValue) / maValue * 100);

                        perList.Add(perValue);
                    }

                    bool match = true;
                    for (int i = 0; i < maList.Count - 1; i++)
                    {
                        float perValue = MathF.Abs((maList[i] - maList[i + 1]) / maList[i + 1] * 100);

                        if (perValue > 1 && maList[i] < maList[i + 1])
                        {
                            match = false;
                            break;
                        }
                    }

                    if (match)
                    {
                        for (int i = 0; i < paramsList2.Count; i++)
                        {
                            if (paramsList2[i] < 0)
                            {
                                if (perList[i] < MathF.Abs(paramsList2[i]))
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else
                            {
                                if (perList[i] > paramsList2[i])
                                {
                                    match = false;
                                    break;
                                }
                            }
                        }
                    }

                    return(match);
                }

                break;

            case MatchConditionType.EMA:

                value = (int)args1;

                if (klineDataDic.ContainsKey(value))
                {
                    KLineCache kLineCache = klineDataDic[value];

                    List <float> maList = new List <float>();

                    List <float> perList = new List <float>();

                    for (int i = 0; i < paramsList1.Count; i++)
                    {
                        int maIndex = (int)paramsList1[i];

                        float maValue = 0;

                        if (maIndex == 0)
                        {
                            maValue = kLineCache.V_KLineData[0].V_ClosePrice;
                        }
                        else
                        {
                            if (MACycleList[maIndex - 1] > kLineCache.V_KLineData.Count)
                            {
                                return(false);
                            }
                            maValue = EMA.GetEMA(MACycleList[maIndex - 1], kLineCache.V_KLineData);
                        }

                        maList.Add(maValue);


                        float perValue = MathF.Abs((kLineCache.V_KLineData[0].V_ClosePrice - maValue) / maValue * 100);

                        perList.Add(perValue);
                    }

                    bool match = true;
                    for (int i = 0; i < maList.Count - 1; i++)
                    {
                        if (maList[i] < maList[i + 1])
                        {
                            match = false;
                            break;
                        }
                    }

                    if (match)
                    {
                        for (int i = 0; i < paramsList2.Count; i++)
                        {
                            if (paramsList2[i] < 0)
                            {
                                if (perList[i] < MathF.Abs(paramsList2[i]))
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else
                            {
                                if (perList[i] > paramsList2[i])
                                {
                                    match = false;
                                    break;
                                }
                            }
                        }
                    }

                    return(match);
                }
                break;

            case MatchConditionType.BtcLSPercent:

                if (args1 < 0)
                {
                    if (btcLSPercent < MathF.Abs(args1))
                    {
                        return(false);
                    }

                    return(true);
                }
                else
                {
                    if (btcLSPercent > args1)
                    {
                        return(false);
                    }

                    return(true);
                }

                break;

            case MatchConditionType.PriceList:

                value = (int)args1;

                if (klineDataDic.ContainsKey(value))
                {
                    KLineCache kLineCache = klineDataDic[value];

                    bool match = true;

                    int count = (int)paramsList1[0];

                    if (Math.Abs(count) + 1 > kLineCache.V_KLineData.Count)
                    {
                        return(false);
                    }

                    if (count > 0)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            if (kLineCache.V_KLineData[i].GetAvg() < kLineCache.V_KLineData[i + 1].GetAvg())
                            {
                                match = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < -count; i++)
                        {
                            if (kLineCache.V_KLineData[i].GetAvg() > kLineCache.V_KLineData[i + 1].GetAvg())
                            {
                                match = false;
                                break;
                            }
                        }
                    }
                    return(match);
                }
                break;

            case MatchConditionType.OldPrice:

                value = (int)args1;

                if (klineDataDic.ContainsKey(value))
                {
                    KLineCache kLineCache = klineDataDic[value];

                    bool match = false;

                    int startInedx = (int)paramsList1[0];
                    int dir        = (int)paramsList1[1];
                    int count      = Math.Abs(dir);

                    float curValue = kLineCache.V_KLineData[0].V_ClosePrice;

                    if (startInedx < kLineCache.V_KLineData.Count)
                    {
                        float p1 = kLineCache.V_KLineData[startInedx].GetAvg();
                        float p2 = kLineCache.V_KLineData[startInedx - count].GetAvg();

                        float percent = MathF.Abs((p1 - p2) / p2 * 100);

                        if (percent > 2)
                        {
                            if (dir > 0)
                            {
                                if (p1 < p2 && curValue < p1)
                                {
                                    match = true;
                                }
                            }
                            else
                            {
                                if (p1 > p2 && curValue > p1)
                                {
                                    match = true;
                                }
                            }
                        }
                    }
                    return(match);
                }
                break;

            default:
                break;
            }

            return(false);
        }
Esempio n. 3
0
 float F_GetEMA(int length)
 {
     return(EMA.GetEMA(length, V_Cache.V_KLineData));
 }