Exemplo n.º 1
0
        static void AddPositionVolumeAssist(ref LastPosition last_pos, double gap, double price, List <Position> Position,
                                            object locker, ModelsAT.BrokerMT tradeTerminal, ArbitrageTradeWF.OrderType order_type,
                                            ILogger logger, DateTime time, string name, bool LoggNeeded)
        {
            last_pos.gap   = gap;
            last_pos.price = price;
            int ind = Position.Last().index;

            lock (locker)
            {
                tradeTerminal.OpenOrder(order_type, ind);
            }
            Position.Add(new Processors.Position()
            {
                index = ind, value = price
            });
            if (LoggNeeded)
            {
                logger.LogEvent(time, name + " Увеличиваем объем позиции " + ind + " req price : " + price);
            }
        }
Exemplo n.º 2
0
 public static void AddPositionVolume_Old(bool LongShort, ref LastPosition last_pos, double gap, double price, List <Position> Position,
                                          ref bool expand_position, object locker, ModelsAT.BrokerMT tradeTerminal, ILogger logger,
                                          DateTime time, string name, bool LoggNeeded)
 {
     if (expand_position)
     {
         if (!LongShort)
         {
             if (gap > last_pos.gap && price > last_pos.price)
             {
                 AddPositionVolumeAssist(ref last_pos, gap, price, Position, locker, tradeTerminal, ArbitrageTradeWF.OrderType.MKT_Sell, logger, time, name, LoggNeeded);
                 expand_position = false;
             }
         }
         else
         {
             if (gap < last_pos.gap && price < last_pos.price)
             {
                 AddPositionVolumeAssist(ref last_pos, gap, price, Position, locker, tradeTerminal, ArbitrageTradeWF.OrderType.MKT_Buy, logger, time, name, LoggNeeded);
                 expand_position = false;
             }
         }
     }
 }
Exemplo n.º 3
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);
        }