Esempio n. 1
0
        private void SetPositionSize(double bidPrice, double askPrice)
        {
            double balance = 0, risk = 0;

            if (tbBalance.Text.Length > 0)
            {
                if (!Double.TryParse(tbBalance.Text, out balance))
                {
                    return;
                }
            }
            if (tbRiskPcnt.Text.Length > 0)
            {
                if (!Double.TryParse(tbRiskPcnt.Text, out risk))
                {
                    return;
                }
            }
            if (balance > 0 && risk > 0)
            {
                var stopLoss = GetAlignedStopLoss(bidPrice);
                if (!stopLoss.HasValue)
                {
                    return;
                }

                var stopValue = StopSlip + stopLoss.Value;
                PositionSize = _posController.CalculatePosition(bidPrice, stopValue, risk, balance, MainWnd.Controller, _instrument);

                lblBidPrice.ToolTip = MainWnd.Controller.ToStringPrice(bidPrice - stopValue, _instrument);
                lblAskPrice.ToolTip = MainWnd.Controller.ToStringPrice(askPrice + stopValue, _instrument);
            }
            else
            {
                PositionSize = 0;
            }
        }