Exemplo n.º 1
0
        public static Boolean isMomentumDetected(List <CMRow> rows, int period, double averageThreshold, double pctRemove)
        {
            cmResult result     = calculateMaxAndAvg(rows, period, pctRemove);
            CMRow    currentRow = rows[rows.Count - 1];

            if (currentRow.deltaPt >= result.maxThreshold && currentRow.deltaPt >= result.averageThreshold * averageThreshold)
            {
                return(true);
            }
            return(false);

            /*
             * List<CMRow> _clnRows =  new List<CMRow> ();
             * _clnRows = cloneRows(rows);
             * CMRow currentRow = rows[rows.Count - 1];
             * _clnRows.Reverse();
             * List<CMRow> lastNRows = firstNRow(_clnRows, period);
             * lastNRows.Sort(delegate(CMRow x, CMRow y)
             * {
             *  if (x.deltaPt > y.deltaPt)
             *      return 1;
             *  if (x.deltaPt < y.deltaPt)
             *      return -1;
             *  if (x.deltaPt == y.deltaPt)
             *      return 0;
             *  return 0;
             * });
             *
             * int numExcluded = Convert.ToInt32(Math.Floor(period * 0.1));
             * int numTooHigh = numExcluded * 2;
             * int indexTooHighInclude = period -numTooHigh-1;
             * int startIncludeIndex = 0 + numExcluded ;
             * int endIncludeIndex = period - numExcluded -1;
             *
             * double average = 0;
             * double valueTooHigh = 0;
             * for (int i = 0; i < lastNRows.Count; i++)
             * {
             *  if (i >= startIncludeIndex && i <= endIncludeIndex) {
             *      average += lastNRows[i].deltaPt;
             *  }
             *
             *  if (i == indexTooHighInclude)
             *      valueTooHigh = lastNRows[i].deltaPt;
             * }
             * average = average / (lastNRows.Count - numExcluded * 2);
             * if (currentRow.deltaPt >= valueTooHigh && currentRow.deltaPt >= average * 3 )
             *  return true;
             * return false;
             */
        }
Exemplo n.º 2
0
        public static double findMaxDeltaTriggerMomentum(List <CMRow> rows, int period, double averageThreshold, double pctRemove)
        {
            cmResult result = calculateMaxAndAvg(rows, period, pctRemove);

            //log.Info("result.averageThreshold=" + result.averageThreshold);
            //log.Info("result.maxThreshold=" + result.maxThreshold);
            return(Math.Max(result.averageThreshold * averageThreshold, result.maxThreshold));

            /*
             * List<CMRow> _clnRows = new List<CMRow>();
             * _clnRows = cloneRows(rows);
             * CMRow currentRow = rows[rows.Count - 1];
             *
             * _clnRows.Reverse();
             * List<CMRow> lastNRows = firstNRow(_clnRows, period);
             *
             * lastNRows.Sort(delegate(CMRow x, CMRow y)
             * {
             *  if (x.deltaPt > y.deltaPt)
             *      return 1;
             *  if (x.deltaPt < y.deltaPt)
             *      return -1;
             *  if (x.deltaPt == y.deltaPt)
             *      return 0;
             *  return 0;
             * });
             *
             * int numExcluded = Convert.ToInt32(Math.Floor(period * 0.1));
             * int numTooHigh = numExcluded * 2;
             * int indexTooHighInclude = period - numTooHigh - 1;
             * int startIncludeIndex = 0 + numExcluded;
             * int endIncludeIndex = period - numExcluded - 1;
             *
             * double average = 0;
             * double valueTooHigh = 0;
             * for (int i = 0; i < lastNRows.Count; i++)
             * {
             *  if (i >= startIncludeIndex && i <= endIncludeIndex)
             *  {
             *      average += lastNRows[i].deltaPt;
             *  }
             *
             *  if (i == indexTooHighInclude)
             *      valueTooHigh = lastNRows[i].deltaPt;
             * }
             * average = average / (lastNRows.Count - numExcluded * 2) * 2;
             *
             * return Math.Max(average, valueTooHigh);
             */
        }
Exemplo n.º 3
0
        public static cmResult calculateMaxAndAvg(List <CMRow> rows, int period, double pctRemove)
        {
            List <CMRow> _clnRows = new List <CMRow>();

            _clnRows = cloneRows(rows);
            CMRow currentRow = rows[rows.Count - 1];

            _clnRows.Reverse();
            List <CMRow> lastNRows = firstNRow(_clnRows, period);

            lastNRows.Sort(delegate(CMRow x, CMRow y)
            {
                if (x.deltaPt > y.deltaPt)
                {
                    return(1);
                }
                if (x.deltaPt < y.deltaPt)
                {
                    return(-1);
                }
                if (x.deltaPt == y.deltaPt)
                {
                    return(0);
                }
                return(0);
            });

            double halfPctRemove = pctRemove / 2;
            //halfPctRemove = Math.Round(halfPctRemove, 1);
            int numExcluded         = Convert.ToInt32(Math.Floor(period * halfPctRemove));
            int numTooHigh          = numExcluded * 2;
            int indexTooHighInclude = period - numTooHigh - 1;
            int startIncludeIndex   = 0 + numExcluded;
            int endIncludeIndex     = period - numExcluded - 1;

            double average      = 0;
            double valueTooHigh = 0;

            for (int i = 0; i < lastNRows.Count; i++)
            {
                if (i >= startIncludeIndex && i <= endIncludeIndex)
                {
                    average += lastNRows[i].deltaPt;
                }

                if (i == indexTooHighInclude)
                {
                    valueTooHigh = lastNRows[i].deltaPt;
                }
            }

            average = average / (lastNRows.Count - numExcluded * 2);
            cmResult result = new cmResult();

            result.averageThreshold = average;
            result.maxThreshold     = valueTooHigh;
            return(result);
            //if (currentRow.deltaPt >= valueTooHigh && currentRow.deltaPt >= average * 3 )
            //    return true;
            //return false;
        }