public void PopulateReview(TradeReview review)
        {
            TransactionBLL   tBLL  = new TransactionBLL(_unit);
            TradePositionBLL tpBll = new TradePositionBLL(_unit);
            IndicatorBLL     iBll  = new IndicatorBLL(_unit);
            TickerBLL        tkBll = new TickerBLL(_unit);

            OutPosition pos = tpBll.GetOutPositionById(review.TradePositionId);

            Transaction entryTr = tBLL.GetByID(pos.EntryTransactionId);

            Entity.Indicator entryInd = iBll.GetIndicatorByShareDate(pos.ShareId, entryTr.TradingDate);
            Ticker           entryT   = tkBll.GetTickerByDate(pos.ShareId, entryTr.TradingDate);

            iBll.PopulateIndicatorWithTicker(entryInd, entryT);

            review.IsEntryLong = pos.Size > 0 ? true : false;

            if (entryInd.BB_Low.HasValue && entryInd.BB_High.HasValue)
            {
                review.BBEntryPercent = 100 * (entryTr.Price - entryInd.BB_Low.Value) / (entryInd.BB_High.Value - entryInd.BB_Low.Value);
            }

            review.EntryPercent = 100 * (entryTr.Price - entryInd.Low.Value) / (entryInd.High.Value - entryInd.Low.Value);

            if (pos.ExitTransactionId.HasValue)
            {
                Transaction      exitTr  = new TransactionBLL(_unit).GetByID(pos.ExitTransactionId.Value);
                Entity.Indicator exitInd = new IndicatorBLL(_unit).GetIndicatorByShareDate(pos.ShareId, exitTr.TradingDate);
                Ticker           exitT   = tkBll.GetTickerByDate(pos.ShareId, exitTr.TradingDate);
                iBll.PopulateIndicatorWithTicker(exitInd, exitT);

                if (exitInd.BB_Low.HasValue && exitInd.BB_High.HasValue)
                {
                    review.BBExitPercent = 100 * (exitTr.Price - exitInd.BB_Low.Value) / (exitInd.BB_High.Value - exitInd.BB_Low.Value);
                }

                review.ExitPercent = 100 * (exitTr.Price - exitInd.Low.Value) / (exitInd.High.Value - exitInd.Low.Value);

                review.DaysSpan = pos.Days;
                review.Diff     = pos.Diff;
                review.Diff_Per = pos.Diff_Per;
            }
        }
Пример #2
0
        public void ProcessAccountPositions(int accountId)
        {
            List <TradePosition> tpList = tpBll.GetOutstandingPositions(accountId);
            Account acc           = aBll.GetByID(accountId);
            int     dateToProcess = this.GetDateToProcess(acc);

            foreach (TradePosition tp in tpList)
            {
                int startDate = this.GetPositionStartDate(tp);


                List <Screen2.Entity.Indicator> iList = this.GetIndicatorsForTrade(tp, dateToProcess);
                Transaction tr = trBll.GetByID(tp.EntryTransactionId);

                if (iList != null && iList.Count > 0)
                {
                    foreach (Screen2.Entity.Indicator ind in iList)
                    {
                        if (ind.TradingDate > tr.TradingDate)
                        {
                            if (tp.Size > 0)
                            {
                                if (tp.Stop.HasValue && tp.Stop.Value >= ind.Low && tp.Stop.Value <= ind.High)
                                {
                                    this.ProcessExitPosition(tp, ind, true);
                                    break;
                                }
                                else if (tp.Limit.HasValue && tp.Limit.Value >= ind.Low && tp.Limit.Value <= ind.High)
                                {
                                    this.ProcessExitPosition(tp, ind, false);
                                    break;
                                }
                                else
                                {
                                    tpBll.UpdatePositionValue(tp, ind);
                                }
                            }
                            else
                            {
                                if (tp.Stop.HasValue && tp.Stop.Value >= ind.Low && tp.Stop.Value <= ind.High)
                                {
                                    this.ProcessExitPosition(tp, ind, true);
                                    break;
                                }
                                else if (tp.Limit.HasValue && tp.Limit.Value <= ind.High && tp.Limit.Value >= ind.Low)
                                {
                                    this.ProcessExitPosition(tp, ind, false);
                                    break;
                                }
                                else
                                {
                                    tpBll.UpdatePositionValue(tp, ind);
                                }
                            }
                        }

                        if (ind.TradingDate == tr.TradingDate)
                        {
                            if (tp.Size > 0)
                            {
                                if (tp.Stop.HasValue && tp.Stop.Value >= ind.Low && tp.Stop.Value <= ind.High &&
                                    ind.Close < ind.Open)
                                {
                                    this.ProcessExitPosition(tp, ind, true);
                                    break;
                                }
                                else if (tp.Limit.HasValue && tp.Limit.Value >= ind.Low && tp.Limit.Value <= ind.High &&
                                         ind.Close > ind.Open)
                                {
                                    this.ProcessExitPosition(tp, ind, false);
                                    break;
                                }
                                else
                                {
                                    tpBll.UpdatePositionValue(tp, ind);
                                }
                            }
                            else
                            {
                                if (tp.Stop.HasValue && tp.Stop.Value >= ind.Low && tp.Stop.Value <= ind.High &&
                                    ind.Close > ind.Open)
                                {
                                    this.ProcessExitPosition(tp, ind, true);
                                    break;
                                }
                                else if (tp.Limit.HasValue && tp.Limit.Value <= ind.High && tp.Limit.Value >= ind.Low &&
                                         ind.Close < ind.Open)
                                {
                                    this.ProcessExitPosition(tp, ind, false);
                                    break;
                                }
                                else
                                {
                                    tpBll.UpdatePositionValue(tp, ind);
                                }
                            }
                        }
                    }
                }
            }
        }