Ejemplo n.º 1
0
        public static void CorvergenceCheck(List <ProbaStruct> ZigZagCollectionMain, List <ProbaStruct> ZigZagCollectionOff,
                                            ProbaStruct NewZigZagValue, double converGap, double converPrice,
                                            DateTime time, ref ProbaStruct CorvergenceHandle, ref int convergence_counter,
                                            double gap, double RatioConver, ref List <Position> Position, object locker,
                                            ModelsAT.BrokerMT tradeTerminal, ref OpenPosition openpos, ILogger logger, string name, bool LoggNeeded)
        {
            if (ZigZagCollectionMain.Last().GapValue < NewZigZagValue.GapValue && ZigZagCollectionMain.Last().price < NewZigZagValue.price)
            {
                convergence_counter++;
                CorvergenceHandle.GapValue = converGap;
                CorvergenceHandle.price    = converPrice;
                CorvergenceHandle.time     = time;
                if (ZigZagCollectionOff.Count != 0)
                {
                    double R     = Math.Abs(NewZigZagValue.GapValue - gap);
                    double R1    = Math.Abs(NewZigZagValue.GapValue - ZigZagCollectionOff.Last().GapValue);
                    double Ratio = R / R1;

                    /* if (LoggNeeded)
                     *   logger.LogEvent(time, name + " Ratio: " + Ratio);
                     * if (RatioConver <= Ratio)
                     * {
                     *   if (Position.Count > 0)
                     *   {
                     *       lock (locker)
                     *       {
                     *           logger.LogEvent(time, name + " Аварийный выход с рынка");
                     *           tradeTerminal.ClosePosition(Position[0].index);
                     *           openpos = OpenPosition.NONE;
                     *       }
                     *       Position.Clear();
                     *   }
                     * }*/
                }
                //if (LoggNeeded)
                //    logger.LogEvent(time, name + " Медвежья конвергенция ");
            }
            else
            {
                convergence_counter = 0;
            }
        }
Ejemplo n.º 2
0
 static void DivergenceAssist(ProbaStruct NewZigZagValue, ref int divergence_counter, ILogger logger, string name, bool LoggNeeded, string message)
 {
     divergence_counter++;
     //if (LoggNeeded)
     //    logger.LogEvent(NewZigZagValue.time, message);
 }
Ejemplo n.º 3
0
 public static void DivergenceCheck(bool MaxMin, List <ProbaStruct> ZigZagCollection, ProbaStruct NewZigZagValue, ref int divergence_counter,
                                    ref bool pos_flag, ILogger logger, string name, DateTime time, bool LoggNeeded, bool OpenClose)
 {
     if (!MaxMin)
     {
         if (NewZigZagValue.GapValue > ZigZagCollection[0].GapValue && NewZigZagValue.price > ZigZagCollection.Last().price)
         {
             string type = "закрытия Long";
             if (OpenClose)
             {
                 type = "открытия Short";
             }
             string message = String.Format("{0} Дивергенция {2} {1} ", name, divergence_counter + 1, type);
             DivergenceAssist(NewZigZagValue, ref divergence_counter, logger, name, LoggNeeded, message);
         }
         else
         {
             divergence_counter = 0;
             pos_flag           = false;
         }
     }
     else
     {
         if (NewZigZagValue.GapValue < ZigZagCollection[0].GapValue && NewZigZagValue.price < ZigZagCollection.Last().price)
         {
             string type = "закрытия Short";
             if (OpenClose)
             {
                 type = "открытия Long";
             }
             string message = String.Format("{0} Дивергенция {2} {1} ", name, divergence_counter + 1, type);
             DivergenceAssist(NewZigZagValue, ref divergence_counter, logger, name, LoggNeeded, message);
         }
         else
         {
             divergence_counter = 0;
             pos_flag           = false;
         }
     }
 }
Ejemplo n.º 4
0
        public void EventHandlerBig(object[] param)
        {
            if (MinValueBig.Count == Size)
            {
                MinValueBig.RemoveAt(0);
            }
            if (MaxValueBig.Count == Size)
            {
                MaxValueBig.RemoveAt(0);
            }
            if (param[0].ToString() == "Min")
            {
                lastvalue = LastZigZagValue.MIN;
                double      gapValue   = (double)param[1];
                double      price      = (double)param[2];
                DateTime    time       = (DateTime)param[3];
                ProbaStruct Temp_value = new ProbaStruct()
                {
                    GapValue = gapValue, price = price, time = time
                };
                MinValueBig.Add(Temp_value);

                if (MinValueBig.Count == Size)
                {
                    double level = 0;
                    lock (locker)
                    {
                        if (!shortlock)
                        {
                            openshortcloselong = true;
                        }
                        for (int i = 1; i < Size; i++)
                        {
                            if (MinValueBig[i].GapValue <MinValueBig[i - 1].GapValue && MinValueBig[i].price> MinValueBig[i - 1].price)
                            {
                                openshortcloselong = false;
                            }
                            level += MinValueBig[i].GapValue;
                        }
                        level       /= Size;
                        lvl_dwn_last = level;
                    }
                }
            }
            if (param[0].ToString() == "Max")
            {
                lastvalue = LastZigZagValue.MAX;
                double      gapValue   = (double)param[1];
                double      price      = (double)param[2];
                DateTime    time       = (DateTime)param[3];
                ProbaStruct Temp_value = new ProbaStruct()
                {
                    GapValue = gapValue, price = price, time = time
                };
                MaxValueBig.Add(Temp_value);

                if (MaxValueBig.Count == Size)
                {
                    double level = 0;
                    lock (locker)
                    {
                        if (!longlock)
                        {
                            openlongcloseshort = true;
                        }
                        for (int i = 1; i < Size; i++)
                        {
                            if (MaxValueBig[i].GapValue > MaxValueBig[i - 1].GapValue && MaxValueBig[i].price < MaxValueBig[i - 1].price)
                            {
                                openlongcloseshort = false;
                            }
                            level += MaxValueBig[i].GapValue;
                        }
                        level      /= Size;
                        lvl_up_last = level;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public override bool Initialize(List <IProcessorInput> inputs, string parameters, ILogger logger)
        {
            ClosePositionStopTrade += Stop;
            if (Models.InputItemInteractivBrokerModel.IB == null)
            {
                return(false);
            }
            this.logger = logger;
            ParametersParser parser = CreateParser(parameters);

            zigzagid      = parser.GetInt("ZigZag_ID");
            zigzagidsmall = parser.GetInt("ZigZagSmall_ID");
            if (zigzagid < 0 || zigzagid > Model.Project.Outputs.Count)
            {
                return(false);
            }
            if (zigzagidsmall < 0 || zigzagidsmall > Model.Project.Outputs.Count)
            {
                return(false);
            }
            gappos = parser.GetInt("Gap");
            if (gappos < 0 || gappos > Model.Project.Outputs.Count)
            {
                return(false);
            }
            //Gap = Model.Project.Proccesors[gappos];
            //Gap.ProcessorAction += PositionHandler;
            //ZigZag = Model.Project.Proccesors[zigzagid];
            //ZigZag.ProcessorAction += EventHandler;
            MinValueSmall = new List <ProbaStruct>();
            MaxValueSmall = new List <ProbaStruct>();
            MinValueBig   = new List <ProbaStruct>();
            MaxValueBig   = new List <ProbaStruct>();
            PositionShort = new Position();
            PositionLong  = new Position();
            name          = parser.GetString("Name");
            ratio         = parser.GetDouble("Ratio");
            tradeTerminal = new ModelsAT.BrokerMT(parser.GetInt("tradeTerminalID"));
            tradeTerminal.setBrokerParam("Name", parser.GetString("ServerName"));
            tradeTerminal.SetServer();
            Size = parser.GetInt("Size");
            if (parser.GetInt("IsReal") == 1)
            {
                tradeTerminal.isReal = true;
            }
            if (parser.GetInt("Logg") == 1)
            {
                LoggNeeded = true;
            }
            else
            {
                LoggNeeded = false;
            }
            //if (divergence > size || divergence == 0) return false;
            openlongcloseshort          = false;
            openshortcloselong          = false;
            longlock                    = false;
            shortlock                   = false;
            profit_to_close             = parser.GetInt("TakeProfit") * Math.Pow(10, -Model.Project.Outputs[gappos].Digits);
            lose_to_close               = parser.GetInt("StopLoss") * Math.Pow(10, -Model.Project.Outputs[gappos].Digits);
            convergenceshort            = false;
            convergencelong             = false;
            divergenceshort             = false;
            divergencelong              = false;
            lastvalue                   = LastZigZagValue.NONE;
            all_profit                  = 0;
            openpos                     = OpenPosition.NONE;
            ConvergenMin                = new ProbaStruct();
            ConvergenMax                = new ProbaStruct();
            Model.OutputsInitializeEnd += InitializeHandler;
            Model.LoadSimulation       += LoadSec;
            return(true);
        }
Ejemplo n.º 6
0
        public void EventHandlerSmall(object[] param)
        {
            if (MinValueSmall.Count == Size)
            {
                MinValueSmall.RemoveAt(0);
            }
            if (MaxValueSmall.Count == Size)
            {
                MaxValueSmall.RemoveAt(0);
            }
            if (param[0].ToString() == "Min")
            {
                lastvalue = LastZigZagValue.MIN;
                double      gapValue   = (double)param[1];
                double      price      = (double)param[2];
                DateTime    time       = (DateTime)param[3];
                ProbaStruct Temp_value = new ProbaStruct()
                {
                    GapValue = gapValue, price = price, time = time
                };
                MinValueSmall.Add(Temp_value);
                if (MinValueSmall.Count == Size)
                {
                    int convergence = 0;
                    int divergence  = 0;
                    lock (locker)
                    {
                        for (int i = 1; i < Size; i++)
                        {
                            if (MinValueSmall[i].GapValue <MinValueSmall[i - 1].GapValue && MinValueSmall[i].price> MinValueSmall[i - 1].price)
                            {
                                convergence++;
                            }
                            if (MinValueSmall[i].GapValue > MinValueSmall[i - 1].GapValue && MinValueSmall[i].price > MinValueSmall[i - 1].price)
                            {
                                divergence++;
                            }
                        }
                        if (MinValueSmall.Last().GapValue < lvl_dwn_last * 0.8)
                        {
                            longlock = true;
                        }
                        else
                        {
                            longlock = false;
                        }
                        if (convergence == Size)
                        {
                            convergenceshort = true;
                        }
                        else
                        {
                            convergenceshort = false;
                        }
                        if (divergence == Size)
                        {
                            divergenceshort = true;
                        }
                        else
                        {
                            divergenceshort = false;
                        }
                    }
                }
            }
            if (param[0].ToString() == "Max")
            {
                lastvalue = LastZigZagValue.MAX;
                double      gapValue   = (double)param[1];
                double      price      = (double)param[2];
                DateTime    time       = (DateTime)param[3];
                ProbaStruct Temp_value = new ProbaStruct()
                {
                    GapValue = gapValue, price = price, time = time
                };
                MaxValueSmall.Add(Temp_value);

                if (MaxValueSmall.Count == Size)
                {
                    int convergence = 0;
                    int divergence  = 0;
                    lock (locker)
                    {
                        if (!longlock)
                        {
                            openlongcloseshort = true;
                        }
                        for (int i = 1; i < Size; i++)
                        {
                            if (MaxValueSmall[i].GapValue > MaxValueSmall[i - 1].GapValue && MaxValueSmall[i].price < MaxValueSmall[i - 1].price)
                            {
                                convergence++;
                            }
                            if (MaxValueSmall[i].GapValue < MaxValueSmall[i - 1].GapValue && MaxValueSmall[i].price < MaxValueSmall[i - 1].price)
                            {
                                divergence++;
                            }
                        }
                        if (MaxValueSmall.Last().GapValue > lvl_up_last * 0.8)
                        {
                            shortlock = true;
                        }
                        else
                        {
                            shortlock = false;
                        }
                        if (convergence == Size)
                        {
                            convergencelong = true;
                        }
                        else
                        {
                            convergencelong = false;
                        }
                        if (divergence == Size)
                        {
                            divergencelong = true;
                        }
                        else
                        {
                            divergencelong = false;
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public override bool Initialize(List <IProcessorInput> inputs, string parameters, ILogger logger)
        {
            ClosePositionStopTrade += Stop;
            if (Models.InputItemInteractivBrokerModel.IB == null)
            {
                return(false);
            }
            this.logger = logger;
            ParametersParser parser = CreateParser(parameters);

            zigzagid_1 = parser.GetInt("ZigZag_ID1");
            if (zigzagid_1 < 0 || zigzagid_1 > Model.Project.Outputs.Count)
            {
                return(false);
            }
            zigzagid_2 = parser.GetInt("ZigZag_ID2");
            if (zigzagid_2 < 0 || zigzagid_2 > Model.Project.Outputs.Count)
            {
                return(false);
            }
            zigzagid_2_2 = parser.GetInt("ZigZag_ID2_2");
            gappos       = parser.GetInt("Gap");
            if (gappos < 0 || gappos > Model.Project.Outputs.Count)
            {
                return(false);
            }
            int t_t = parser.GetInt("type");

            switch (t_t)
            {
            case (0):
                trader_type = TradeType.STANDART;
                break;

            case (1):
                trader_type = TradeType.IN_OUT;
                break;

            default:
                trader_type = TradeType.ONE_IN_TWO_OUT;
                break;
            }
            //Gap = Model.Project.Proccesors[gappos];
            //Gap.ProcessorAction += PositionHandler;
            //ZigZag = Model.Project.Proccesors[zigzagid];
            //ZigZag.ProcessorAction += EventHandler;
            divergenceOpen    = parser.GetInt("DivergenceOpen");
            divergenceClose   = parser.GetInt("DivergenceClose");
            convergen_counter = parser.GetInt("Convergence");
            if (divergenceOpen < 0 || divergenceClose < 0 || convergen_counter < 0)
            {
                return(false);
            }
            MinValueOpen_1    = new List <ProbaStruct>();
            MaxValueOpen_1    = new List <ProbaStruct>();
            MinValueClose_1   = new List <ProbaStruct>();
            MaxValueClose_1   = new List <ProbaStruct>();
            MinValueOpen_2    = new List <ProbaStruct>();
            MaxValueOpen_2    = new List <ProbaStruct>();
            MinValueClose_2   = new List <ProbaStruct>();
            MaxValueClose_2   = new List <ProbaStruct>();
            MinValueOpen_2_2  = new List <ProbaStruct>();
            MaxValueOpen_2_2  = new List <ProbaStruct>();
            MinValueClose_2_2 = new List <ProbaStruct>();
            MaxValueClose_2_2 = new List <ProbaStruct>();
            PositionShort     = new List <Position>();
            PositionLong      = new List <Position>();
            name            = parser.GetString("Name");
            ratio           = parser.GetDouble("Ratio");
            profit_to_close = parser.GetInt("TakeProfit") * Math.Pow(10, -Model.Project.Outputs[gappos].Digits);
            lose_to_close   = parser.GetInt("StopLoss") * Math.Pow(10, -Model.Project.Outputs[gappos].Digits);
            ratio_exp       = parser.GetDouble("Ratio_O");
            tradeTerminal   = new ModelsAT.BrokerMT(parser.GetInt("tradeTerminalID"));
            tradeTerminal.setBrokerParam("Name", parser.GetString("ServerName"));
            tradeTerminal.SetServer();
            if (parser.GetInt("IsReal") == 1)
            {
                tradeTerminal.isReal = true;
            }
            else
            {
                tradeTerminal.isReal = false;
            }
            if (parser.GetInt("Logg") == 1)
            {
                LoggNeeded = true;
            }
            else
            {
                LoggNeeded = false;
            }
            if (parser.GetInt("Expand") == 1)
            {
                can_expand = true;
            }
            else
            {
                can_expand = false;
            }
            divergence_max_open   = 0;
            divergence_min_open   = 0;
            divergence_max_close  = 0;
            divergence_min_close  = 0;
            openlong              = false;
            openshort             = false;
            closelong             = false;
            expand_position_short = false;
            expand_position_long  = false;
            closeshort            = false;
            lastvalue             = LastZigZagValue.NONE;
            all_profit            = 0;
            openpos       = OpenPosition.NONE;
            convergen_min = 0;
            convergen_max = 0;
            ConvergenMin  = new ProbaStruct();
            ConvergenMax  = new ProbaStruct();
            last_pos      = new LastPosition();
            Model.OutputsInitializeEnd += InitializeHandler;
            Model.LoadSimulation       += LoadSec;
            return(true);
        }
Ejemplo n.º 8
0
 void EventHelper_2_type2(object[] param, ref List <ProbaStruct> MinValueClose, ref List <ProbaStruct> MaxValueClose)
 {
     if (MinValueClose.Count == divergenceClose + 1)
     {
         MinValueClose.RemoveAt(0);
     }
     if (MaxValueClose.Count == divergenceClose + 1)
     {
         MaxValueClose.RemoveAt(0);
     }
     if (param[0].ToString() == "Min")
     {
         lastvalue = LastZigZagValue.MIN;
         double      gapValue   = (double)param[1];
         double      price      = (double)param[2];
         DateTime    time       = (DateTime)param[3];
         ProbaStruct Temp_value = new ProbaStruct()
         {
             GapValue = gapValue, price = price, time = time
         };
         if (MinValueClose.Count != 0)
         {
             if (openpos == OpenPosition.LONG)
             {
                 FunTradeWorker.DivergenceCheck(false, MinValueClose, Temp_value, ref divergence_min_close, ref closelong, logger, name, time, LoggNeeded, false);
             }
         }
         MinValueClose.Add(Temp_value);
         if (divergenceClose == 0)
         {
             if (OpenPosition.LONG == openpos)
             {
                 CloseLong = Temp_value;
                 closelong = true;
             }
         }
         else
         if (divergence_min_close == divergenceClose)
         {
             closelong = true;
             CloseLong = MinValueClose.Last();
             string message = String.Format("{0} Решение закрыть позиции Лонг. Ждем локальную дивергенцию... ", name);
             //if (LoggNeeded)
             //    logger.LogEvent(Temp_value.time, message);
             divergence_min_close = 0;
         }
     }
     if (param[0].ToString() == "Max")
     {
         lastvalue = LastZigZagValue.MAX;
         double      gapValue   = (double)param[1];
         double      price      = (double)param[2];
         DateTime    time       = (DateTime)param[3];
         ProbaStruct Temp_value = new ProbaStruct()
         {
             GapValue = gapValue, price = price, time = time
         };
         if (MaxValueClose.Count != 0)
         {
             if (openpos == OpenPosition.SHORT)
             {
                 FunTradeWorker.DivergenceCheck(true, MaxValueClose, Temp_value, ref divergence_max_close, ref closeshort, logger, name, time, LoggNeeded, false);
             }
         }
         MaxValueClose.Add(Temp_value);
         if (divergenceClose == 0)
         {
             if (openpos == OpenPosition.SHORT)
             {
                 CloseShort = Temp_value;
                 closelong  = true;
             }
         }
         else
         if (divergence_max_close == divergenceClose)
         {
             closeshort = true;
             CloseShort = MaxValueClose.Last();
             string message = String.Format("{0} Решение закрыть позиции Шорт. Ждем локальную дивергенцию... ", name);
             //if (LoggNeeded)
             //    logger.LogEvent(Temp_value.time, message);
             divergence_max_close = 0;
         }
     }
 }
Ejemplo n.º 9
0
 public void EventHandler_1_type2(object[] param)
 {
     if (MinValueOpen_1.Count == divergenceOpen + 1)
     {
         MinValueOpen_1.RemoveAt(0);
     }
     if (MaxValueOpen_1.Count == divergenceOpen + 1)
     {
         MaxValueOpen_1.RemoveAt(0);
     }
     if (param[0].ToString() == "Min")
     {
         lastvalue = LastZigZagValue.MIN;
         double      gapValue   = (double)param[1];
         double      price      = (double)param[2];
         DateTime    time       = (DateTime)param[3];
         ProbaStruct Temp_value = new ProbaStruct()
         {
             GapValue = gapValue, price = price, time = time
         };
         if (MinValueOpen_1.Count != 0)
         {
             if (openpos == OpenPosition.SHORT)
             {
                 if (can_expand)
                 {
                     if (Temp_value.GapValue > MinValueOpen_1.Last().GapValue&& Temp_value.price > MinValueOpen_1.Last().price)
                     {
                         expand_position_short = true;
                     }
                     else
                     {
                         expand_position_short = false;
                     }
                 }
             }
             if (openpos == OpenPosition.NONE)
             {
                 FunTradeWorker.DivergenceCheck(false, MinValueOpen_1, Temp_value, ref divergence_min_open, ref openshort, logger, name, time, LoggNeeded, true);
             }
         }
         MinValueOpen_1.Add(Temp_value);
         MinValueClose_1.Add(Temp_value);
         if (divergenceOpen == 0)
         {
             if (openpos == OpenPosition.NONE)
             {
                 openshort = true;
                 OpenShort = Temp_value;
             }
             if (openpos == OpenPosition.SHORT)
             {
                 expand_position_short = true;
             }
         }
         else
         if (divergence_min_open == divergenceOpen)
         {
             openshort  = true;
             OpenShort  = MinValueOpen_1.Last();
             CrashShort = MinValueOpen_1[0];
             string message = String.Format("{0} Решение открытия позиции Шорт. Ждем локальную дивергенцию... ", name);
             //if (LoggNeeded)
             //    logger.LogEvent(Temp_value.time, message);
             divergence_min_open = 0;
         }
     }
     if (param[0].ToString() == "Max")
     {
         lastvalue = LastZigZagValue.MAX;
         double      gapValue   = (double)param[1];
         double      price      = (double)param[2];
         DateTime    time       = (DateTime)param[3];
         ProbaStruct Temp_value = new ProbaStruct()
         {
             GapValue = gapValue, price = price, time = time
         };
         if (MaxValueOpen_1.Count != 0)
         {
             if (openpos == OpenPosition.LONG)
             {
                 if (can_expand)
                 {
                     if (Temp_value.GapValue < MaxValueOpen_1.Last().GapValue&& Temp_value.price < MaxValueOpen_1.Last().price)
                     {
                         expand_position_long = true;
                     }
                     else
                     {
                         expand_position_long = false;
                     }
                 }
             }
             if (openpos == OpenPosition.NONE)
             {
                 FunTradeWorker.DivergenceCheck(true, MaxValueOpen_1, Temp_value, ref divergence_max_open, ref openlong, logger, name, time, LoggNeeded, true);
             }
         }
         MaxValueOpen_1.Add(Temp_value);
         if (divergenceOpen == 0)
         {
             if (openpos == OpenPosition.NONE)
             {
                 OpenLong = Temp_value;
                 openlong = true;
             }
             if (openpos == OpenPosition.LONG)
             {
                 expand_position_short = true;
             }
         }
         else
         if (divergence_max_open == divergenceOpen)
         {
             openlong  = true;
             OpenLong  = MaxValueOpen_1.Last();
             CrashLong = MaxValueOpen_1[0];
             string message = String.Format("{0} Решение открытия позиции Лонг. Ждем локальную дивергенцию... ", name);
             //if (LoggNeeded)
             //    logger.LogEvent(Temp_value.time, message);
             divergence_max_open = 0;
         }
     }
 }
Ejemplo n.º 10
0
 void EventHelper(object[] param, List <ProbaStruct> MinValueOpen, List <ProbaStruct> MinValueClose, List <ProbaStruct> MaxValueOpen, List <ProbaStruct> MaxValueClose)
 {
     if (MinValueOpen.Count == divergenceOpen + 1)
     {
         MinValueOpen.RemoveAt(0);
     }
     if (MinValueClose.Count == divergenceClose + 1)
     {
         MinValueClose.RemoveAt(0);
     }
     if (MaxValueOpen.Count == divergenceOpen + 1)
     {
         MaxValueOpen.RemoveAt(0);
     }
     if (MaxValueClose.Count == divergenceClose + 1)
     {
         MaxValueClose.RemoveAt(0);
     }
     if (param[0].ToString() == "Min")
     {
         lastvalue = LastZigZagValue.MIN;
         double      gapValue   = (double)param[1];
         double      price      = (double)param[2];
         DateTime    time       = (DateTime)param[3];
         ProbaStruct Temp_value = new ProbaStruct()
         {
             GapValue = gapValue, price = price, time = time
         };
         if (MinValueOpen.Count != 0)
         {
             if (openpos == OpenPosition.SHORT)
             {
                 if (can_expand)
                 {
                     if (Temp_value.GapValue > MinValueOpen.Last().GapValue&& Temp_value.price > MinValueOpen.Last().price)
                     {
                         expand_position_short = true;
                     }
                     else
                     {
                         expand_position_short = false;
                     }
                 }
             }
             FunTradeWorker.CorvergenceCheck(MinValueOpen, MaxValueOpen, Temp_value, gapValue, price, time,
                                             ref ConvergenMin, ref convergen_min, Model.Project.Outputs[gappos].Value,
                                             ratio, ref PositionShort, locker, tradeTerminal, ref openpos, logger, name, LoggNeeded);
             if (openpos == OpenPosition.NONE)
             {
                 FunTradeWorker.DivergenceCheck(false, MinValueOpen, Temp_value, ref divergence_min_open, ref openshort, logger, name, time, LoggNeeded, true);
             }
         }
         if (MinValueClose.Count != 0)
         {
             if (openpos == OpenPosition.LONG)
             {
                 FunTradeWorker.DivergenceCheck(false, MinValueClose, Temp_value, ref divergence_min_close, ref closelong, logger, name, time, LoggNeeded, false);
             }
         }
         MinValueOpen.Add(Temp_value);
         MinValueClose.Add(Temp_value);
         if (divergenceOpen == 0)
         {
             if (openpos == OpenPosition.NONE)
             {
                 openshort = true;
                 OpenShort = Temp_value;
             }
             if (openpos == OpenPosition.SHORT)
             {
                 expand_position_short = true;
             }
         }
         else
         if (divergence_min_open == divergenceOpen)
         {
             openshort  = true;
             OpenShort  = MinValueOpen.Last();
             CrashShort = MinValueOpen[0];
             string message = String.Format("{0} Решение открытия позиции Шорт. Ждем локальную дивергенцию... ", name);
             //if (LoggNeeded)
             //    logger.LogEvent(Temp_value.time, message);
             divergence_min_open = 0;
         }
         if (divergenceClose == 0)
         {
             if (openpos == OpenPosition.LONG)
             {
                 CloseLong = Temp_value;
                 closelong = true;
             }
         }
         else
         if (divergence_min_close == divergenceClose)
         {
             closelong = true;
             CloseLong = MinValueClose.Last();
             string message = String.Format("{0} Решение закрыть позиции Лонг. Ждем локальную дивергенцию... ", name);
             //if (LoggNeeded)
             //    logger.LogEvent(Temp_value.time, message);
             divergence_min_close = 0;
         }
     }
     if (param[0].ToString() == "Max")
     {
         lastvalue = LastZigZagValue.MAX;
         double      gapValue   = (double)param[1];
         double      price      = (double)param[2];
         DateTime    time       = (DateTime)param[3];
         ProbaStruct Temp_value = new ProbaStruct()
         {
             GapValue = gapValue, price = price, time = time
         };
         if (MaxValueOpen.Count != 0)
         {
             if (openpos == OpenPosition.LONG)
             {
                 if (can_expand)
                 {
                     if (Temp_value.GapValue < MaxValueOpen.Last().GapValue&& Temp_value.price < MaxValueOpen.Last().price)
                     {
                         expand_position_long = true;
                     }
                     else
                     {
                         expand_position_long = false;
                     }
                 }
             }
             FunTradeWorker.CorvergenceCheck(MaxValueOpen, MinValueOpen, Temp_value, gapValue, price, time, ref ConvergenMax, ref convergen_max,
                                             Model.Project.Outputs[gappos].Value, ratio, ref PositionLong, locker, tradeTerminal, ref openpos, logger, name, LoggNeeded);
             if (openpos == OpenPosition.NONE)
             {
                 FunTradeWorker.DivergenceCheck(true, MaxValueOpen, Temp_value, ref divergence_max_open, ref openlong, logger, name, time, LoggNeeded, true);
             }
         }
         if (MaxValueClose.Count != 0)
         {
             if (openpos == OpenPosition.SHORT)
             {
                 FunTradeWorker.DivergenceCheck(true, MaxValueClose, Temp_value, ref divergence_max_close, ref closeshort, logger, name, time, LoggNeeded, false);
             }
         }
         MaxValueOpen.Add(Temp_value);
         MaxValueClose.Add(Temp_value);
         if (divergenceOpen == 0)
         {
             if (openpos == OpenPosition.NONE)
             {
                 openlong = true;
                 OpenLong = Temp_value;
             }
             if (openpos == OpenPosition.LONG)
             {
                 expand_position_short = true;
             }
         }
         else
         if (divergence_max_open == divergenceOpen)
         {
             openlong  = true;
             OpenLong  = MaxValueOpen.Last();
             CrashLong = MaxValueOpen[0];
             string message = String.Format("{0} Решение открытия позиции Лонг. Ждем локальную дивергенцию... ", name);
             //if (LoggNeeded)
             //    logger.LogEvent(Temp_value.time, message);
             divergence_max_open = 0;
         }
         if (divergenceClose == 0)
         {
             if (openpos == OpenPosition.SHORT)
             {
                 CloseShort = Temp_value;
                 closelong  = true;
             }
         }
         else
         if (divergence_max_close == divergenceClose)
         {
             closeshort = true;
             CloseShort = MaxValueClose.Last();
             string message = String.Format("{0} Решение закрыть позиции Шорт. Ждем локальную дивергенцию... ", name);
             //if (LoggNeeded)
             //    logger.LogEvent(Temp_value.time, message);
             divergence_max_close = 0;
         }
     }
 }