コード例 #1
0
ファイル: TA.cs プロジェクト: larytet/JQuant
        /// <summary>
        /// divide the series in two (or three) parts, calculate maximum and minimum in each part parts
        /// maximums should be "close" enough and subsequent low should be higher than the previous
        /// check if i have at least three points luying on the same ascending line and at least two
        /// points around the maximum
        ///
        /// When dividing the range in two or three segments two different approaches are used
        /// - equal time
        /// - fib (0.38, 0.618, 1) time
        /// </summary>
        public bool isTriangle(int start, int end, PriceVolumeSeries series)
        {
            bool result = false;

            do
            {
                // no enough points for triangle
                if ((end - start) < 6)
                {
                    break;
                }

                int    halfPoint = (end - start) / 2;
                double average, min1, max1, min2, max2;
                int    min1Idx, max1Idx, min2Idx, max2Idx;

                double stdDeviation = StdDeviations * series.StdDeviation;

                if ((series.Max - series.Min) < 2 * stdDeviation)
                {
                    break;
                }

                PriceVolumeSeries.CalculateAverage(series, start, halfPoint - start + 1, out average, out min1, out min1Idx, out max1, out max1Idx);
                PriceVolumeSeries.CalculateAverage(series, halfPoint, end - halfPoint + 1, out average, out min2, out min2Idx, out max2, out max2Idx);

                //   max2-stdDeviation < max1 < max2+stdDeviation
                if ((max1 <= (max2 - stdDeviation)) || (max1 >= (max2 + stdDeviation)))
                {
                    break;
                }

                if (min2 < min1 + stdDeviation)
                {
                    break;
                }

                // i have two conditions - maxs are "close" and second low is higher than the first
                // do i have two highs and three lows ? two highs (two maxs) are in place. now lows
                double tangent    = (min2 - min1) / (min2Idx - min1Idx);
                double target     = min1 - tangent * (min1Idx - start);
                bool   thirdPoint = false;
                bool   closeUnder = false;

                // look for 3rd close on line described by the tangent
                // on the way I make sure that all closes are above the ascending line
                for (int i = start; i <= end; i++)
                {
                    Candle candle = (Candle)series.Data[i];
                    double close  = candle.close;

                    if ((i != min1Idx) && (i != min2Idx) && (close < target - stdDeviation))
                    {
                        closeUnder = true;
                        break;
                    }

                    thirdPoint = thirdPoint | ((i != min1Idx) && (i != min2Idx) && (close > target - stdDeviation) && (close < target + stdDeviation));

                    target = target + tangent;
                }

                result = !closeUnder && thirdPoint;
            }while (false);


            return(result);
        }
コード例 #2
0
ファイル: TA.cs プロジェクト: sopnic/larytet-master
 protected void Add(Candle candle)
 {
     paramsCalculated = false;
     Data.Add(candle);
 }
コード例 #3
0
ファイル: TA.cs プロジェクト: larytet/JQuant
 protected void Add(Candle candle)
 {
     paramsCalculated = false;
     Data.Add(candle);
 }