public static bool SetCurrentPosition(int ticket, int type, double lots, double price, DateTime opentime, double stoploss, double takeprofit, double profit, string comment)
        {
            bool changed = false;

            if (positionType != type ||
                positionLots != lots ||
                positionOpenPrice != price ||
                positionStopLoss != stoploss ||
                positionTakeProfit != takeprofit ||
                positionComment != comment)
            {
                changed = true;
            }

            positionTicket     = ticket;
            positionType       = type;
            positionLots       = lots;
            positionOpenPrice  = price;
            positionOpenTime   = opentime;
            positionStopLoss   = stoploss;
            positionTakeProfit = takeprofit;
            positionProfit     = profit;
            positionComment    = comment;

            DateTime barOpenTime = Time[Bars - 1];

            if (!barStats.ContainsKey(barOpenTime))
            {
                barStats.Add(barOpenTime, new BarStats(barOpenTime, PositionDirection, positionOpenPrice, positionLots));
            }
            else
            {
                barStats[barOpenTime].PositionDir   = PositionDirection;
                barStats[barOpenTime].PositionPrice = positionOpenPrice;
                barStats[barOpenTime].PositionLots  = positionLots;
            }

            if (changed && Configs.PlaySounds)
            {
                SoundPositionChanged.Play();
            }

            return(changed);
        }
Exemple #2
0
        public static bool SetCurrentPosition(int ticket, int type, double lots, double price, DateTime opentime,
                                              double stoploss, double takeprofit, double profit, string comment)
        {
            bool changed = PositionType != type ||
                           Math.Abs(PositionLots - lots) > Epsilon ||
                           Math.Abs(PositionOpenPrice - price) > Epsilon ||
                           Math.Abs(PositionStopLoss - stoploss) > Epsilon ||
                           Math.Abs(PositionTakeProfit - takeprofit) > Epsilon ||
                           PositionComment != comment;

            PositionTicket     = ticket;
            PositionType       = type;
            PositionLots       = lots;
            PositionOpenPrice  = price;
            PositionOpenTime   = opentime;
            PositionStopLoss   = stoploss;
            PositionTakeProfit = takeprofit;
            PositionProfit     = profit;
            PositionComment    = comment;

            DateTime barOpenTime = Time[Bars - 1];

            if (!barStats.ContainsKey(barOpenTime))
            {
                barStats.Add(barOpenTime, new BarStats(barOpenTime, PositionDirection, PositionOpenPrice, PositionLots));
            }
            else
            {
                barStats[barOpenTime].PositionDir   = PositionDirection;
                barStats[barOpenTime].PositionPrice = PositionOpenPrice;
                barStats[barOpenTime].PositionLots  = PositionLots;
            }

            if (changed && Configs.PlaySounds)
            {
                SoundPositionChanged.Play();
            }

            return(changed);
        }