public double ConvertToUSD(Deals DEAL)
 {
     return(this.ConvertToUSD(DEAL.PRODUCT, DEAL.BUY, DEAL.CONTRACT));
 }
        private void TimrControls_Tick(object sender, EventArgs e)
        {
            int InLbxPairs = LbxCCYPairs.Items.Count;
            int InLbxDeals = LbxDealsOpened.Items.Count;

            List <Rates> LRATES  = ORBlotter.GetData;
            List <Deals> LDEALS  = ODBlotter.GetData;
            int          LRCount = LRATES.Count;


            if (InLbxPairs < LRCount)
            {
                if (InLbxPairs > 0)
                {
                    LbxCCYPairs.Items.Clear();
                }


                for (int i = 0; i < LRCount; i++)
                {
                    LbxCCYPairs.Items.Add(LRATES[i].CCY_Pair);
                }
            }

            if (LbxDealsOpened.SelectedIndex >= 0)
            {
                Deals DEAL = ODBlotter.Get(LbxDealsOpened.SelectedItem.ToString());

                TbxDealPair.Text = DEAL.PRODUCT;

                if (DEAL.BUY)
                {
                    TbxDealKind.Text = "BUY ";
                }
                else
                {
                    TbxDealKind.Text = "SELL";
                }

                TbxDealProfitOrLoss.Text = AUTOTREADER.ConvertToUSD(DEAL.PRODUCT, DEAL.BUY, ACCOUNT.CalculateProfitOrLoss(DEAL, ORBlotter.Get(DEAL.PRODUCT))) + "";

                ChartPointPredition CPP = AUTOTREADER.TryGet(DEAL.PRODUCT, TimeFrame.ONE_MINUTE);


                if (CPP == null || CPP.Type == ChartPointPredition.Kind.Uncertain || !CPP.IsActual)
                {
                    TbxDealPredictionKind.Text       = "Uncertain";
                    TbxDealPredictionPercentage.Text = "";
                    TbxDealPredictionValue.Text      = "";
                }
                else
                {
                    if (CPP.Type == ChartPointPredition.Kind.Average)
                    {
                        TbxDealPredictionKind.Text = "Average";
                    }
                    else if (CPP.Type == ChartPointPredition.Kind.Down)
                    {
                        TbxDealPredictionKind.Text = "Down";
                    }
                    else if (CPP.Type == ChartPointPredition.Kind.Up)
                    {
                        TbxDealPredictionKind.Text = "Up";
                    }

                    TbxDealPredictionPercentage.Text = Math.Round(CPP.Propability, 2).ToString();
                    TbxDealPredictionValue.Text      = Math.Round(CPP.Change, 5).ToString();
                }
            }



            if (this.IsConnected())
            {
                this.UpdateMargin();
                this.UpdateAction();
            }

            if (!OSBlotter.IsLoaded)
            {
                BtnAutoTrader.Enabled = false;
                BtnBuy.Enabled        = false;
                BtnClose.Enabled      = false;
                BtnSell.Enabled       = false;
            }
            else
            {
                BtnAutoTrader.Enabled = true;
                BtnBuy.Enabled        = true;
                BtnClose.Enabled      = true;
                BtnSell.Enabled       = true;
            }
        }
Beispiel #3
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);
        }
Beispiel #4
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();
        }
Beispiel #5
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;
                }
            }
        }