Esempio n. 1
0
 public override void update_value(int curIndex, FinancialInstrument instr)
 {
     if (curIndex <= period2)
     {
         add_value(instr.get_interval(curIndex, 0).ClosingPrice);
     }
     else
     {
         double newVal = get_value(curIndex, 0) * period;
         newVal -= instr.get_interval(curIndex, period).ClosingPrice - instr.get_interval(curIndex, period2).OpeningPrice;                //Удаляем старое значение из суммы
         newVal += instr.get_interval(curIndex, 0).ClosingPrice - instr.get_interval(curIndex, 0).OpeningPrice;                           //Добавляем новое значение
         add_value(newVal);
     }
 }
Esempio n. 2
0
        public void accept_new_interval(int curIndex, FinancialInstrument instrument)
        {
            double close = instrument.get_interval(curIndex, 0).ClosingPrice;
            double open  = instrument.get_interval(curIndex, 0).OpeningPrice;

            if (close > open && curDirection == 1)
            {
                curResult++;
            }
            else if (close < open && curDirection == -1)
            {
                curResult++;
            }
            else
            {
                curResult = 0;
            }
            result.Add(curResult);
        }
Esempio n. 3
0
        //Проверка срабатывания условия
        public bool check(int curIndex, FinancialInstrument instr)
        {
            //Обновить индикаторы
            if (indicator1 != null)
            {
                indicator1.update_value(curIndex, instr);
            }

            if (indicator2 != null)
            {
                indicator2.update_value(curIndex, instr);
            }

            double par1 = 0, par2 = 0;

            switch (parameter1)
            {
            case ParameterCondition.Const:
                par1 = const1;
                break;

            case ParameterCondition.PriceClose:
                par1 = instr.get_interval(curIndex, indexOfInterval1).ClosingPrice;
                break;

            case ParameterCondition.PriceOpen:
                par1 = instr.get_interval(curIndex, indexOfInterval1).OpeningPrice;
                break;

            case ParameterCondition.PriceMax:
                par1 = instr.get_interval(curIndex, indexOfInterval1).MaxPrice;
                break;

            case ParameterCondition.PriceMin:
                par1 = instr.get_interval(curIndex, indexOfInterval1).MinPrice;
                break;

            case ParameterCondition.Volume:
                par1 = instr.get_interval(curIndex, indexOfInterval1).Volume;
                break;

            default:                            //Индикатор
                par1 = indicator1.get_value(curIndex, indexOfInterval1);
                break;
            }

            switch (parameter2)
            {
            case ParameterCondition.Const:
                par2 = const2;
                break;

            case ParameterCondition.PriceClose:
                par2 = instr.get_interval(curIndex, indexOfInterval2).ClosingPrice;
                break;

            case ParameterCondition.PriceOpen:
                par2 = instr.get_interval(curIndex, indexOfInterval2).OpeningPrice;
                break;

            case ParameterCondition.PriceMax:
                par2 = instr.get_interval(curIndex, indexOfInterval2).MaxPrice;
                break;

            case ParameterCondition.PriceMin:
                par2 = instr.get_interval(curIndex, indexOfInterval2).MinPrice;
                break;

            case ParameterCondition.Volume:
                par2 = instr.get_interval(curIndex, indexOfInterval2).Volume;
                break;

            default:                            //Индикатор
                par2 = indicator2.get_value(curIndex, indexOfInterval2);
                break;
            }

            switch (predicate)
            {
            case Predicate.Equal:
                return(par1 == par2);

            case Predicate.Less:
                return(par1 < par2);

            case Predicate.LessEqual:
                return(par1 <= par2);

            case Predicate.More:
                return(par1 > par2);

            case Predicate.MoreEqual:
                return(par1 >= par2);
            }
            return(false);
        }