Example #1
0
        public bool AlternateProduct(OpenRatesBlotter ORBlotter, TimeFrame TFrame, int count, string product, ref int shift, ref int shiftAlternative, int maxShift, ref string alternative, ref string counterAlternative)
        {
            List <string> LSProd      = ARCHIVE.GetProducts();
            int           iLCPCount   = ARCHIVE.GetDATACount(TFrame, product);
            int           iLastPoints = count;
            int           iStartIdx   = iLCPCount - iLastPoints;
            Rates         RATE        = ORBlotter.Get(product);
            int           iDecimals   = RATE.Decimals;

            double dBestCompare  = double.MinValue;
            double dWorstCompare = double.MaxValue;

            alternative = counterAlternative = "";

            foreach (string sP in LSProd)
            {
                if (sP == product)
                {
                    continue;
                }

                Rates RATESecond      = ORBlotter.Get(sP);
                int   iDecimalsSecond = RATESecond.Decimals;

                int iLCPCountSecondary         = ARCHIVE.GetDATACount(TFrame, sP);
                List <ChartPoint> LCPPrimary   = ARCHIVE.GetDATA(TFrame, product, iStartIdx, iLastPoints);
                List <ChartPoint> LCPSecondary = ARCHIVE.GetDATA(TFrame, sP, iLCPCountSecondary - iLastPoints, iLastPoints);
                int iShift = 0;

                double dCompaison = this.CompareCharts(LCPPrimary, LCPSecondary, iDecimals, iDecimalsSecond, maxShift, ref iShift);

                if (dCompaison > dBestCompare)
                {
                    dBestCompare = dCompaison;
                    alternative  = sP;
                    shift        = iShift;
                }

                if (dCompaison < dWorstCompare)
                {
                    dWorstCompare      = dCompaison;
                    counterAlternative = sP;
                    shiftAlternative   = iShift;
                }
            }


            if (shift != 0 || alternative == "" || counterAlternative == "")
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #2
0
        public double Spread(Rates RATE)
        {
            double dSpread  = RATE.Spread;
            double pipValue = Math.Pow(10, -RATE.Decimals);

            dSpread += ACCOUNT.OpeningHazard * pipValue;
            dSpread += ACCOUNT.SqueringHazard * pipValue;

            return(dSpread);// (int)(dSpread / pipValue);
        }
Example #3
0
        /// <summary>
        /// Removes Deals from class and from DATABASE
        /// </summary>
        /// <param name="DealReference">Reference or DealID of deal that will be removed.</param>
        public void Remove(string CCY_Pair)
        {
            Rates RATE = this.Get(CCY_Pair);



            DATA.Remove(RATE);
            LSProducts.Remove(RATE.CCY_Pair);


            // while (!DATA.TryTake(out RATE)) ;
        }
Example #4
0
        public List <ChartPoint> Get(string product, TimeFrame TFrame, int deep)
        {
            if (!DATA.ContainsKey(product))
            {
                return(null);
            }

            int          iMinutes = ABBREVIATIONS.ToMinutes(TFrame);
            List <Rates> LRData   = this.TryGet(product);

            if (LRData.Count < 2)
            {
                return(null);
            }


            Rates RATE = LRData[LRData.Count - 1];

            if (RATE == null)
            {
                RATE = LRData[LRData.Count - 2];
            }

            DateTime          DTNow    = RATE.TimeGMT;
            List <ChartPoint> LCPoints = new List <ChartPoint>();

            for (int i = 0; i < deep; i++)
            {
                DateTime DTEnd   = DTNow.AddMinutes(-i);
                DateTime DTStart = DTNow.AddMinutes(-(i + 1));

                List <Rates> LRChartData = this.Get(product, DTStart, DTEnd, 5);


                if (LRChartData == null || LRChartData.Count <= (iMinutes * 12)) //12 points per minute / 1 pint per second
                {
                    return(null);
                }

                LRChartData = LRChartData.OrderBy(R => R.Time).ToList();

                double   OPEN  = LRChartData.First().BID;
                double   CLOSE = LRChartData.Last().BID;
                double   HIGH  = LRChartData.Max(R => R.BID);
                double   LOW   = LRChartData.Min(R => R.BID);
                DateTime DTime = LRChartData.Last().TimeGMT;

                LCPoints.Add(new ChartPoint(CLOSE, OPEN, HIGH, LOW, DTime));
            }

            return(LCPoints);
        }
Example #5
0
        public int SpreadPips(Rates RATE, bool hazard)
        {
            double dSpread  = RATE.Spread;
            double pipValue = Math.Pow(10, -RATE.Decimals);

            if (hazard)
            {
                dSpread += ACCOUNT.OpeningHazard * pipValue;
                dSpread += ACCOUNT.SqueringHazard * pipValue;
            }

            return((int)(dSpread / pipValue));
        }
Example #6
0
        public Rates Get(string CCY_Pair)
        {
            Rates RATE = null;// DATA.FirstOrDefault(R => R.CCY_Pair == CCY_Pair);

            for (int i = 0; i < this.Count; i++)
            {
                if (DATA[i].CCY_Pair == CCY_Pair)
                {
                    RATE = DATA[i];//.Clone();
                }
            }
            return(RATE);
        }
Example #7
0
        private void UpdateAction()
        {
            if (LbxCCYPairs.SelectedItem == null)
            {
                return;
            }

            string PRODUCT = LbxCCYPairs.SelectedItem.ToString();
            Rates  RATE    = ORBlotter.Get(PRODUCT);


            TbxASK.Text = ABBREVIATIONS.ToString(RATE.ASK, RATE.Decimals);
            TbxBID.Text = ABBREVIATIONS.ToString(RATE.BID, RATE.Decimals);
        }
Example #8
0
        public List <Rates> Get(string product, DateTime DTStartGMT, DateTime DTEndGMT, int secondsDeviation)
        {
            List <Rates> LRMatches = new List <Rates>();

            if (!DATA.ContainsKey(product))
            {
                return(LRMatches);
            }

            List <Rates> LRData = this.TryGet(product);
            DateTime     DTMin  = DateTime.Now.AddYears(100);
            DateTime     DTMax  = DateTime.Now.AddYears(-100);

            for (int i = LRData.Count - 1; i >= 0; i--)
            {
                Rates    RATE         = LRData[i];
                DateTime DTCurrentGMT = RATE.TimeGMT;
                if (DTCurrentGMT >= DTStartGMT && DTCurrentGMT <= DTEndGMT)
                {
                    LRMatches.Add(RATE);

                    if (DTCurrentGMT > DTMax)
                    {
                        DTMax = DTCurrentGMT;
                    }
                    else if (DTCurrentGMT < DTMin)
                    {
                        DTMin = DTCurrentGMT;
                    }
                }

                if (DTCurrentGMT < DTStartGMT)
                {
                    break;
                }
            }

            if (DTMin.AddSeconds(-secondsDeviation) > DTStartGMT)
            {
                return(null);
            }
            else if (DTMax.AddSeconds(secondsDeviation) < DTEndGMT)
            {
                return(null);
            }

            LRMatches.Reverse();

            return(LRMatches);
        }
Example #9
0
        public Rates Get(int CCY_Token)
        {
            //Rates RATE = DATA.FirstOrDefault(R => R.CCY_Token == CCY_Token);

            Rates RATE = null;// DATA.FirstOrDefault(R => R.CCY_Pair == CCY_Pair);

            for (int i = 0; i < this.Count; i++)
            {
                if (DATA[i].CCY_Token == CCY_Token)
                {
                    RATE = DATA[i].Clone();
                }
            }
            return(RATE);
        }
Example #10
0
        /// <summary>
        /// Adds or Replaces RATE with specified CCY_Pair name
        /// </summary>
        /// <param name="RATE">Rates that have to be instert or replaced.</param>
        public void Add(Rates RATE)
        {
            int index = DATA.FindIndex(R => R.CCY_Pair == RATE.CCY_Pair);

            if (index < 0 || index > DATA.Count)
            {
                DATA.Add(RATE);
                LSProducts.Add(RATE.CCY_Pair);
            }
            else
            {
                DATA[index] = RATE;
            }

            ArchiveDATA.Add(RATE);
        }
Example #11
0
        public double Spread(Rates RATE, int pipsGain, bool hazard)
        {
            double dSpread  = RATE.Spread;
            double pipValue = Math.Pow(10, -RATE.Decimals);

            if (hazard)
            {
                dSpread += ACCOUNT.OpeningHazard * pipValue;
                dSpread += ACCOUNT.SqueringHazard * pipValue;
            }

            if (pipsGain > 0)
            {
                dSpread += pipsGain * pipValue;
            }

            return(dSpread);// (int)(dSpread / pipValue);
        }
Example #12
0
        public Rates Clone()
        {
            Rates RATE = new Rates();

            RATE.American  = American;
            RATE.ASK       = ASK;
            RATE.BID       = BID;
            RATE.CCY_Token = CCY_Token;
            RATE.CCY_Pair  = CCY_Pair;
            RATE.CLOSE     = CLOSE;
            RATE.Dealable  = Dealable;
            RATE.Decimals  = Decimals;
            RATE.HIGH      = HIGH;
            RATE.LOW       = LOW;
            RATE.Time      = Time;


            return(RATE);
        }
Example #13
0
        public double ConvertToUSD(string PRODUCT, bool BUY, double amount)
        {
            //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            var    SETTINGS   = OSBlotter.Get(PRODUCT);
            string sPrimary   = PRODUCT.Substring(0, 3);
            string sSecondary = PRODUCT.Substring(4, 3);

            string sContract     = SETTINGS.ContractProduct;
            string sCounter      = SETTINGS.CounterProduct;
            double dContractRate = 0;
            double dCost;

            if (sContract == sCounter && sSecondary == "USD")
            {
                return(Math.Round(amount, 2));
            }

            Rates RATE_Counter = ORBlotter.Get(sCounter);

            if (RATE_Counter == null)
            {
                return(double.NaN);
            }

            if (BUY)
            {
                dContractRate = RATE_Counter.ASK;
            }
            else
            {
                dContractRate = RATE_Counter.BID;
            }


            dCost = amount / dContractRate;


            return(Math.Round(dCost, 2));
        }
Example #14
0
        public double CalculateProfitOrLoss(Deals DEAL, Rates RATE)
        {
            double MarginBalance = 0;

            if (RATE == null || DEAL == null)
            {
                return(MarginBalance);
            }



            double rateOld = DEAL.RATE;
            double rateNew;

            if (DEAL.BUY)
            {
                rateNew = RATE.BID;
            }
            else
            {
                rateNew = RATE.ASK;
            }

            //double OnePip = Math.Pow(10, -RATE.Decimals);
            //double PipValue = (OnePip / rateCurrent) * CONTRACT;
            //double SpreadRatePips = Math.Round((rateCurrent - rateOld) / OnePip, 0);
            //double ProfitOrLost = SpreadRatePips * PipValue;// *rateCurrent; WTF ?


            double spread       = Math.Round((rateNew - rateOld), RATE.Decimals);
            double ProfitOrLost = DEAL.CONTRACT * spread;


            MarginBalance = ProfitOrLost;

            return(MarginBalance);
        }
Example #15
0
        public List <string> GetLiquids(List <string> LSProducts, OpenRatesBlotter ORBlotter, double minPercentage, int deep, double spreadFactor, TimeFrame TFrame)
        {
            List <string> LSLiquidProducts = new List <string>();

            foreach (string product in ARCHIVE.GetProducts())
            {
                Rates             RATE          = ORBlotter.Get(product);
                int               iMinutesFrame = ABBREVIATIONS.ToMinutes(TFrame);
                List <ChartPoint> LCPoints      = ARCHIVE.GetDATA(TFrame, product);


                DateTime DTLast100 = ABBREVIATIONS.GreenwichMeanTime.AddMinutes(-deep * iMinutesFrame);

                List <ChartPoint> LCPLast100 = (from CP in LCPoints where CP.Time > DTLast100 select CP).ToList();

                if (this.LiquidPercentage(LCPLast100, RATE, spreadFactor) > minPercentage)
                {
                    LSLiquidProducts.Add(product);
                }
            }


            return(LSLiquidProducts);
        }
Example #16
0
        public bool Rates(List <string> SLDecodedData, ref OpenRatesBlotter ORBlotter)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            bool ResponseRecived = false;

            int  count       = SLDecodedData.Count;
            int  KEY         = -1;
            bool BlockFound  = false;
            bool UpdateFound = false;
            int  position    = -1;

            int i;

            for (i = 0; i < count; i++)
            {
                string PART   = SLDecodedData[i];
                int    length = PART.Length;
                BlockFound  = false;
                UpdateFound = false;

                if (PART.Contains("BUP") || PART.Contains("DEAL") || PART.Contains("ORD"))
                {
                }


                if ((position = PART.IndexOf("\r")) >= 0)
                {
                    PART            = PART.Substring(position + 1, length - (position + 1));
                    length          = PART.Length;
                    ResponseRecived = true;
                }



                if (length == 0)
                {
                    continue;
                }

                if (!(PART.Contains("/") && length == 7) && (PART[0] == 'S' || PART[0] == '$' || PART[0] == 'R')) //Delimiters !PART.Contains("/") &&
                {
                    string SUB       = PART.Substring(1, length - 1);
                    int    CCY_Token = int.Parse(SUB);

                    if (PART.Contains("R"))
                    {
                        UpdateFound = true;
                    }
                    else
                    {
                        BlockFound = true;
                    }

                    KEY = CCY_Token;
                }


                if (BlockFound)
                {
                    if (SLDecodedData.Count <= (i + 9))
                    {
                        break;
                    }

                    Rates RATE = new AsmodatForexEngineAPI.Rates();

                    RATE.CCY_Token = KEY;
                    RATE.CCY_Pair  = SLDecodedData[i + 1];
                    RATE.BID       = double.Parse(SLDecodedData[i + 2]);
                    RATE.ASK       = double.Parse(SLDecodedData[i + 3]);
                    RATE.HIGH      = double.Parse(SLDecodedData[i + 4]);
                    RATE.LOW       = double.Parse(SLDecodedData[i + 5]);
                    RATE.Dealable  = false;
                    RATE.American  = false;
                    if (SLDecodedData[i + 6] == "D")
                    {
                        RATE.Dealable = true;
                    }
                    if (SLDecodedData[i + 7] == "A")
                    {
                        RATE.American = true;
                    }
                    RATE.Decimals = int.Parse(SLDecodedData[i + 8]);
                    RATE.CLOSE    = double.Parse(SLDecodedData[i + 9]);

                    ORBlotter.Add(RATE);

                    i += 9;
                }
                else if (UpdateFound)
                {
                    if (SLDecodedData.Count <= (i + 4))
                    {
                        break;
                    }

                    double BID      = double.Parse(SLDecodedData[i + 1]);
                    double ASK      = double.Parse(SLDecodedData[i + 2]);
                    bool   Dealable = false;
                    if (SLDecodedData[i + 3] == "D")
                    {
                        Dealable = true;
                    }
                    DateTime Time;
                    try
                    {
                        Time = DateTime.ParseExact(SLDecodedData[i + 4], "MM/dd/yyyy HH:mm:ss", null);// "02/06/2014 11:39:01"
                    }
                    catch
                    {
                        try
                        {
                            Time = DateTime.ParseExact(SLDecodedData[i + 9], "MM/dd/yyyy HH:mm:ss", null);// "02/06/2014 11:39:01"
                        }
                        catch
                        {
                            i += 1;
                            break;
                        }
                    }

                    Rates RATE = ORBlotter.Get(KEY);

                    RATE.BID      = BID;
                    RATE.ASK      = ASK;
                    RATE.Dealable = Dealable;
                    RATE.Time     = Time;

                    ORBlotter.Add(RATE);

                    i += 4;
                }
            }

            return(ResponseRecived);
        }
Example #17
0
        public double CheckSimilarity(Rates RATE, int position, int deep, int ahead, double[] DAWeightFacotrs) //symilarity must be above 60%
        {
            string    product   = RATE.CCY_Pair;
            TimeFrame TFrame    = TimeFrame.ONE_MINUTE;
            int       iDecimals = RATE.Decimals;
            double    dPipValue = Math.Pow(10, -iDecimals);


            List <ChartPoint> LCPoints          = ARCHIVE.GetDATA(TFrame, product, 0, position);
            List <ChartPoint> LCPointsSpecified = ARCHIVE.GetDATA(TFrame, product, position - deep, deep);
            List <ChartPoint> LCPointsAll       = ARCHIVE.GetDATA(TFrame, product, 0, position + ahead);

            List <double> LDSetChange = (from CP in LCPointsAll select Math.Round(CP.Change, iDecimals)).ToList();
            List <double> LDSetPeak   = (from CP in LCPointsAll select Math.Round(CP.Peak, iDecimals)).ToList();
            List <double> LDSetBase   = (from CP in LCPointsAll select Math.Round(CP.Base, iDecimals)).ToList();


            ChartPointsPredition CPsPrediction    = new ChartPointsPredition();
            ChartPointsPredition CPsPredictionNow = new ChartPointsPredition();
            double dSymilMax = 90;
            double dSymilMin = 50;

            do
            {
                double dSymil = (dSymilMax + dSymilMin) / 2;

                ChartPointsPredition CPsP = null;    // this.PredictNextSpecified(product, LCPoints, LCPointsSpecified, TFrame, iDecimals, dSymil, ahead, DAWeightFacotrs);
                if (CPsP.Prognosis(1) != ChartPointsPredition.Kind.Uncertain)
                {
                    CPsPredictionNow = CPsP;
                }

                if (CPsP.Matches < 10)
                {
                    dSymilMax = dSymil;
                }
                else
                {
                    dSymilMin = dSymil;
                }


                if ((dSymilMax - dSymilMin <= 1) || (CPsPredictionNow.Matches >= 10 && CPsPredictionNow.Matches < 50 && CPsPredictionNow.Analised))
                {
                    CPsPrediction = CPsPredictionNow;
                    break;
                }
            } while (true);

            if (CPsPrediction.Matches == 0)
            {
                return(0);
            }

            double dSimChange = this.Compare(LDSetChange, CPsPrediction.LDChange, position);
            double dSimPeak   = this.Compare(LDSetPeak, CPsPrediction.LDPeak, position);
            double dSimBase   = this.Compare(LDSetBase, CPsPrediction.LDBase, position);
            double dSubSim    = (dSimChange * dSimPeak * dSimBase) / (100 * 100);



            return(dSubSim);
        }
Example #18
0
        private void TimrAutoTraderSquare_Tick(object sender, EventArgs e)
        {
            if (ODBlotter.COUNT == 0)
            {
                return;
            }
            else
            {
                TimeFrame    TFrame = TimeFrame.ONE_MINUTE;
                List <Deals> LDeals = ODBlotter.GetData.ToList();

                for (int i = 0; i < LDeals.Count; i++)
                {
                    Deals  DEAL    = LDeals[i];
                    string product = DEAL.PRODUCT;
                    List <ChartPointsPredition> LCPsPSimulated = this.LCPsPTestSelected.OrderByDescending(CPsP => CPsP.Resolution).ToList();
                    ChartPointsPredition        CPsPrediction  = null;
                    List <Rates> LRAll = ORBlotter.Archive.TryGet(product);

                    for (int i2 = 0; i2 < LCPsPSimulated.Count; i2++)
                    {
                        if (LCPsPSimulated[i2].Product == product)
                        {
                            CPsPrediction = LCPsPSimulated[i2];
                            break;
                        }
                    }



                    double dMinDeal = 0, dMaxDeal = 0;
                    if (!this.Extrema(DEAL, 10, ref dMinDeal, ref dMaxDeal))
                    {
                        return;
                    }

                    bool   bBUY                 = DEAL.BUY;
                    Rates  RATE                 = ORBlotter.Get(DEAL.PRODUCT);
                    double onePip               = Math.Pow(10, -RATE.Decimals);
                    int    iSpread              = ANALYSIS.SpreadPips(DEAL, RATE.Decimals, true) + 2;
                    double dLevel               = (double)iSpread;
                    bool   bLooseWarning        = false;
                    double dGainLoosePercentage = 75;
                    double dStartSpread         = (double)(DEAL.ASK - DEAL.BID) / onePip;

                    if (CPsPrediction != null && CPsPrediction.IsActual)
                    {
                        if ((bBUY && CPsPrediction.Type == ChartPointsPredition.Kind.Down) ||
                            (!bBUY && CPsPrediction.Type == ChartPointsPredition.Kind.Up))
                        {
                            DEAL.LooseWaring     = true;
                            dGainLoosePercentage = 85;
                        }
                        else if ((!bBUY && CPsPrediction.Type == ChartPointsPredition.Kind.Down) ||
                                 (bBUY && CPsPrediction.Type == ChartPointsPredition.Kind.Up))
                        {
                            dGainLoosePercentage = 60;
                        }
                    }

                    if (bBUY)
                    {
                        double dPLMax = (double)(dMaxDeal - DEAL.ASK) / onePip;
                        double dPLNow = (double)(RATE.BID - DEAL.ASK) / onePip;



                        if (dPLMax > 0 && dPLNow > 0)
                        {
                            double dGainPercentage = ((double)(dPLNow + dStartSpread) / (dPLMax + dStartSpread)) * 100;

                            if (dGainPercentage < dGainLoosePercentage || DEAL.LooseWaring)
                            {
                                bLooseWarning = true;
                            }
                        }
                    }
                    else//sell for bid, buy for ask
                    {
                        double dPLMin = (double)(DEAL.BID - dMinDeal) / onePip;
                        double dPLNow = (double)(DEAL.BID - RATE.ASK) / onePip;


                        if (dPLMin > 0 && dPLNow > 0)
                        {
                            double dGainPercentage = ((double)(dPLNow + dStartSpread) / (dPLMin + dStartSpread)) * 100;

                            if (dGainPercentage < dGainLoosePercentage || DEAL.LooseWaring)
                            {
                                bLooseWarning = true;
                            }
                        }
                    }

                    if (bLooseWarning)
                    {
                        this.CloseDeal(DEAL);
                        Thread ThrdBeep = new Thread(delegate() { Console.Beep(200, 50); Console.Beep(200, 50); }); ThrdBeep.Start();
                    }
                    return;
                }
            }
        }
Example #19
0
        private void CloseDeal(Deals DEAL)
        {
            if (!OSBlotter.IsLoaded)
            {
                return;
            }

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            var SETTINGS = OSBlotter.Get(DEAL.PRODUCT);

            string       Rate;
            string       BuySell;
            string       PRODUCT       = DEAL.PRODUCT;
            string       Amount        = Math.Abs(DEAL.CONTRACT).ToString();
            int          productsCount = ODBlotter.Count(PRODUCT);
            DealResponse INFO          = null;

            if (DEAL.BUY)
            {
                BuySell = "S";
            }
            else
            {
                BuySell = "B";
            }



            int   timeout = 0;
            Rates RATE    = ORBlotter.Get(PRODUCT);

            do
            {
                timeout = 0;

                if (DEAL.BUY)
                {
                    Rate = ABBREVIATIONS.ToString(RATE.BID, RATE.Decimals); //BID.ToString();
                }
                else
                {
                    Rate = ABBREVIATIONS.ToString(RATE.ASK, RATE.Decimals);  //ASK.ToString();
                }
                INFO = CEDT_TreadingService.InstantExecution(TOKEN, PRODUCT, BuySell, Amount, Rate, ACCOUNT.SqueringHazard);

                if (INFO.ErrorNo != "")
                {
                    timeout = RATE.WaitForUpdate(2000);
                    if (timeout < 0)
                    {
                        TsslInfo.Text = "Rate does not changed in 2s"; return;
                    }
                    else
                    {
                        TsslInfo.Text = "Time needed for rate to update: " + timeout + " [ms]";
                    }
                }
            } while (timeout != 0);



            double dPL = INFO.OutgoingMarginRealizedInBase;

            ACCOUNT.ClosedBalance += dPL;
            PLSum += dPL;

            Margin BALANCE = CEDT_TreadingService.GetMarginBlotter(TOKEN).Output[0];

            TsslInfo.Text = "Profit Or Loss: Session [" + PLSum + "] USD | Current: Real " + (double.Parse(BALANCE.MarginBalance) - ACCOUNT.ClosedBalanceOld) + ", Predicted " + dPL;

            this.UpdateDeals();
            DATABASE.Save_Account(ACCOUNT);
            this.UpdateAccount();
        }
Example #20
0
        private bool Action(string PRODUCT, bool BUY)
        {
            if (!OSBlotter.IsLoaded)
            {
                return(false);
            }

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
            var SETTINGS  = OSBlotter.Get(PRODUCT); // CEDC_Configuration.GetProductSetting(TOKEN, PRODUCT); //Product settings - minimum lot etc //var b5 = CEDT_TreadingService.GetPositionBlotter(TOKEN); //Summary position for all currencies - all positions
            int OrderSize = int.Parse(SETTINGS.OrderSize);

            if (PRODUCT == "XAU/USD")
            {
                OrderSize *= 10;
            }

            DealResponse INFO;

            // double cost = this.ToUSD(PRODUCT, BUY, OrderSize);

            string Rate;
            string BuySell;

            if (BUY)
            {
                BuySell = "B";
            }
            else
            {
                BuySell = "S";
            }

            bool  bDealSucced = true;
            int   timeout;
            Rates RATE = ORBlotter.Get(PRODUCT);

            do
            {
                timeout = 0;
                if (BUY)
                {
                    Rate = ABBREVIATIONS.ToString(RATE.ASK, RATE.Decimals);    // BID.ToString();
                }
                else
                {
                    Rate = ABBREVIATIONS.ToString(RATE.BID, RATE.Decimals);                                                               //ASK.ToString();
                }
                INFO = CEDT_TreadingService.InstantExecution(TOKEN, PRODUCT, BuySell, OrderSize.ToString(), Rate, ACCOUNT.OpeningHazard); // var INFO = CEDT_TreadingService.DealRequest(TOKEN, PRODUCT, BuySell, OrderSize.ToString(), Rate); //quick // CEDT_TreadingService.DealRequestAtBest(TOKEN, PRODUCT, BuySell, "100000"); //execute whatever but slow

                if (INFO.ErrorNo != "")
                {
                    timeout = RATE.WaitForUpdate(2000);
                    if (timeout < 0)
                    {
                        TsslInfo.Text = "Rate does not changed in 2s, Timeout Error !"; bDealSucced = false; break;
                    }
                    else
                    {
                        TsslInfo.Text = "Time needed for rate to update: " + timeout + " [ms]";
                    }
                }
            } while (timeout != 0);



            if (bDealSucced)
            {
                this.UpdateDeals();
                Deals DEAL = ODBlotter.Get(INFO.dealId);
                if (DEAL != null)
                {
                    double dPipValue = Math.Pow(10, -RATE.Decimals);
                    DEAL.BID = RATE.BID;
                    DEAL.ASK = RATE.ASK;
                    ODBlotter.Add(DEAL);
                }


                this.UpdateAccount();
            }


            return(bDealSucced);
        }
Example #21
0
        public double WeightFactor(Rates RATE, int position, int deep, int ahead, bool averange, double step, double range, int setID) //symilarity must be above 60%
        {
            string    product   = RATE.CCY_Pair;
            TimeFrame TFrame    = TimeFrame.ONE_MINUTE;
            int       iDecimals = RATE.Decimals;
            double    dPipValue = Math.Pow(10, -iDecimals);


            List <ChartPoint> LCPoints          = ARCHIVE.GetDATA(TFrame, product, 0, position);
            List <ChartPoint> LCPointsSpecified = ARCHIVE.GetDATA(TFrame, product, position - deep, deep);
            List <ChartPoint> LCPointsAll       = ARCHIVE.GetDATA(TFrame, product, 0, position + ahead);

            List <double> LDSetChange = (from CP in LCPointsAll select Math.Round(CP.Change, iDecimals)).ToList();
            List <double> LDSetPeak   = (from CP in LCPointsAll select Math.Round(CP.Peak, iDecimals)).ToList();
            List <double> LDSetBase   = (from CP in LCPointsAll select Math.Round(CP.Base, iDecimals)).ToList();

            //double dTopSubSim = 0;
            //

            List <double> LDWFactors     = new List <double>();
            List <double> LDSymilarities = new List <double>();

            double[] DAWeightFactor = new double[5];

            for (double dWF = -step * range; dWF <= step * range; dWF += step)
            {
                DAWeightFactor[setID] = dWF;

                ChartPointsPredition CPsPrediction    = new ChartPointsPredition();
                ChartPointsPredition CPsPredictionNow = new ChartPointsPredition();
                double dSymilMax = 90;
                double dSymilMin = 50;

                do
                {
                    double dSymil = (dSymilMax + dSymilMin) / 2;

                    ChartPointsPredition CPsP = null;// this.PredictNextSpecified(product, LCPoints, LCPointsSpecified, TFrame, iDecimals, dSymil, ahead, DAWeightFactor);
                    if (CPsP.Prognosis(1) != ChartPointsPredition.Kind.Uncertain)
                    {
                        CPsPredictionNow = CPsP;
                    }

                    if (CPsP.Matches < 10)
                    {
                        dSymilMax = dSymil;
                    }
                    else
                    {
                        dSymilMin = dSymil;
                    }


                    if ((dSymilMax - dSymilMin <= 1) || (CPsPredictionNow.Matches >= 10 && CPsPredictionNow.Matches < 50 && CPsPredictionNow.Analised))
                    {
                        CPsPrediction = CPsPredictionNow;
                        break;
                    }
                } while (true);

                if (CPsPrediction.Matches == 0)
                {
                    continue;
                }

                double dSimChange = this.Compare(LDSetChange, CPsPrediction.LDChange, position);
                double dSimPeak   = this.Compare(LDSetPeak, CPsPrediction.LDPeak, position);
                double dSimBase   = this.Compare(LDSetBase, CPsPrediction.LDBase, position);
                double dSubSim    = (dSimChange * dSimPeak * dSimBase) / (100 * 100);

                LDWFactors.Add(dWF);
                LDSymilarities.Add(dSubSim);
            }

            double dLESum   = 0;
            double dGESum   = 0;
            int    iGECount = 0;
            int    iLECount = 0;

            for (int i = 0; i < LDWFactors.Count; i++)
            {
                if (LDWFactors[i] > 0)
                {
                    dGESum += LDSymilarities[i];
                    ++iGECount;
                }
                else if (LDWFactors[i] < 0)
                {
                    dLESum += LDSymilarities[i];
                    ++iLECount;
                }
            }

            double dGES = dGESum / iGECount;
            double dLES = dLESum / iLECount;

            double dTobWF     = 0;
            double dTopSubSim = 0;

            if (!averange)
            {
                for (int i = 0; i < LDWFactors.Count; i++)
                {
                    if (((dGES > dLES) && LDWFactors[i] > 0 && LDSymilarities[i] > dTopSubSim) ||
                        ((dGES < dLES) && LDWFactors[i] < 0 && LDSymilarities[i] > dTopSubSim))
                    {
                        dTopSubSim = LDSymilarities[i];
                        dTobWF     = LDWFactors[i];
                    }
                }
            }
            else
            {
                double dSumWF       = 0;
                double dSumWeightWF = 0;
                for (int i = 0; i < LDWFactors.Count; i++)
                {
                    if ((dGES > dLES && LDWFactors[i] > 0) || (dGES < dLES && LDWFactors[i] < 0))
                    {
                        dSumWF       += LDWFactors[i] * LDSymilarities[i];
                        dSumWeightWF += LDSymilarities[i];
                        dTobWF        = dSumWF / dSumWeightWF;
                    }
                }
            }



            return(dTobWF);
        }