protected override void CalcBar()
        {
            barNumber.Value = BarsOfData(BasedOnData).CurrentBar;

            if (barNumber.Value > barNumber[1])
            {
                double rank = Formula(this);
                MyPortfolioData["RankStrategyR"] = rank;

                if (TraceOutput)
                {
                    Output.WriteLine("CurrentBar = {0}. Put MyIndicator value = {1} for symbol {2}.", Bars.CurrentBar, rank, Bars.Info.Name);
                }
            }

            buy.Send();
            sellshort.Send();

            // money management
            double moneyCostForInvestPerCntrct = this.CalcMoneyForEntryPerCntrct(Bars.CloseValue, Portfolio.MarginPerContract) +
                                                 this.CalcMoneyForEntryPerCntrct(Bars.CloseValue, Portfolio.MaxPotentialLossPerContract);

            if (moneyCostForInvestPerCntrct < 0)
            {
                ExecControl.Abort("Error! Price = {0}, PMargin = {1}, PMaxPLoss = {2}", Bars.CloseValue, Portfolio.MarginPerContract, Portfolio.MaxPotentialLossPerContract);
            }

            MyPortfolioData[PortfolioHelpFunctions.MoneyCostForInvestPerCtrct] = this.FromSymbolToPortfolioCurrency(moneyCostForInvestPerCntrct);
        }
        protected override void CalcBar()
        {
            if (Environment.ApplicationCode != EApplicationCode.Portfolio)
            {
                ExecControl.Abort("Signal can be applied in portfolio only.");
            }

            MyPortfolioData["RotationalValue"] = myFormula(myLength, 0);

            buy.Send();
            sell.Send();

            // money management
            double entryprice = this.EntryPrice() == 0 ? Bars.CloseValue : this.EntryPrice();
            double moneyCostForInvestPerCntrct =
                this.CalcMoneyForEntryPerCntrct(entryprice, Portfolio.MarginPerContract) +
                this.CalcMoneyForEntryPerCntrct(entryprice, Portfolio.MaxPotentialLossPerContract);

            if (moneyCostForInvestPerCntrct < 0)
            {
                ExecControl.Abort("Error! Price = {0}, PMargin = {1}, PMaxPLoss = {2}", entryprice, Portfolio.MarginPerContract, Portfolio.MaxPotentialLossPerContract);
            }

            MyPortfolioData[PortfolioHelpFunctions.MoneyCostForInvestPerCtrct] = this.FromSymbolToPortfolioCurrency(moneyCostForInvestPerCntrct);

            // exits
            CurSpecOrdersMode = ESpecOrdersMode.PerPosition;
            GenerateStopLoss(StopLossPcntsOfPortfolio * .01 * this.PortfolioEquity());
            GenerateProfitTarget(ProfitTargetPcntsOfPortfolio * .01 * this.PortfolioEquity());
        }
        protected override void StartCalc()
        {
            if (Environment.ApplicationCode != EApplicationCode.Portfolio)
            {
                ExecControl.Abort("Signal can be applied in portfolio only.");
            }

            m_KRatio.NumberOfDataBarsInCalendarYear = 252;
        }
Exemplo n.º 4
0
        protected override void CalcBar()
        {
            Ratio.Value = Bars.CloseValue / BarsOfData(2).CloseValue;
            if (Bars.CurrentBar < Length)
            {
                return;
            }
            double contracts = this.PortfolioEquity() * PercentEquity / 100;

            if (Bars.CurrentBar > 1)
            {
                if (PublicFunctions.DoubleLess(m_expAvgRatioVal + m_stdDevRatioVal, Ratio.Value))
                {
                    if (!PublicFunctions.DoubleEquals(m_cur_pos, -1))
                    {
                        m_cur_pos = -1;
                        m_short.Send((int)contracts);
                    }
                }
                else
                if (PublicFunctions.DoubleGreater(m_expAvgRatioVal - m_stdDevRatioVal, Ratio.Value))
                {
                    if (!PublicFunctions.DoubleEquals(m_cur_pos, 1))
                    {
                        m_cur_pos = 1;
                        m_long.Send((int)contracts);
                    }
                }
                else
                {
                    m_cur_pos = 0;
                    m_lx.Send();
                    m_sx.Send();
                }
            }

            m_expAvgRatioVal = m_expAvgRatio.Value;
            m_stdDevRatioVal = Ratio.StandardDeviationCustom(Length, 1);

            if (Environment.ApplicationCode == EApplicationCode.Portfolio)
            {
                int slaveIdx = this.GetFirstStrategyIndexBySymbolName(BarsOfData(2).Info.Name);
                if (slaveIdx < 0)
                {
                    ExecControl.Abort(@"specified slave trader on instrument ""{0}"" not found", BarsOfData(2).Info.Name);
                }

                double money = Math.Abs(m_cur_pos * contracts) * Bars.CloseValue * Bars.Info.BigPointValue;

                if (PublicFunctions.DoubleGreater(money, 0))
                {
                    money = this.FromSymbolToPortfolioCurrency(money);
                }

                PortfolioStrategies[slaveIdx].PortfolioData[MasterMoney] = -m_cur_pos * money;
            }
        }
 protected override void StartCalc()
 {
     if (Environment.ApplicationCode != EApplicationCode.Portfolio)
     {
         ExecControl.Abort("Portfolio Rank Money Management Signal can be applied for MCPortfolio application only.");
     }
     if (PortfolioStrategies.Count < BuyBestX + SellWorstY)
     {
         ExecControl.Abort("Portfolio Rank Monem Management Signal, please check inputs, BuyBestX + SellWorstY should be less or equal to tradeable Instruments number");
     }
 }
Exemplo n.º 6
0
        protected override void StartCalc()
        {
            triggerTime = TimeSpan.Parse(TriggerTime);

            if (Environment.ApplicationCode != EApplicationCode.Portfolio)
            {
                ExecControl.Abort("Signal can be applied in portfolio only.");
            }

            m_KRatio.NumberOfDataBarsInCalendarYear = 1; //252;
        }
Exemplo n.º 7
0
        protected override void StartCalc()
        {
            // In this method it is specified that the signal is calculated in Portfolio Trader.
            if (Environment.ApplicationCode != EApplicationCode.Portfolio)
            {
                ExecControl.Abort("The signal can be used in MultiCharts Portfolio Trader only.");
            }

            // and initialize the function
            m_RSI.price  = Bars.Close;
            m_RSI.length = RSI_Length;
        }
Exemplo n.º 8
0
        protected override void StartCalc()
        {
            if (Environment.ApplicationCode != EApplicationCode.Portfolio)                                  // Verification: the signal is only for the Portfolio Trader
            {
                ExecControl.Abort("The signal can be used in MultiCharts Portfolio Trader only.");
            }

            if (PortfolioStrategies.Count < MaxBest + MaxWorst)                                             // Verification: sum of the inputs should be not more than the total number of the traded symbols
            {
                throw new Exception("Portfolio RSIRankEx_MM Signal, please check inputs, MaxBest + MaxWorst should be less or equal to the number of tradeable instruments");
            }

            if (Bars.Request.TimeZone != RequestTimeZone.Local)
            {
                throw new Exception("The signal can be used only with Local time zone set.");               // Verification: only Local time zone
            }
        }
        protected override void StartCalc()
        {
            CommonPortfolioData["RankStrategyApplied"] = "true";

            if (!IsExist(BasedOnData))
            {
                ExecControl.Abort("Portfolio Rank Signal Base needs datastream {0}." + BasedOnData);
            }
            if (Environment.ApplicationCode != EApplicationCode.Portfolio)
            {
                ExecControl.Abort("Portfolio Rank Signal Base can be applied for MCPortfolio application only.");
            }

            if (TraceOutput)
            {
                Output.Clear();
            }
        }
        protected override void CalcBar()
        {
            if (Environment.ApplicationCode != EApplicationCode.Portfolio)
            {
                ExecControl.Abort("Signal can be applied (as money management) in portfolio only.");
            }
            if (PortfolioStrategies.Count < BuyBestX + SellWorstY)
            {
                ExecControl.Abort(
                    "Portfolio has no enough instruments: instruments number = {0}; BuyBestX = {1}; SellWorstY = {2}",
                    PortfolioStrategies.Count, BuyBestX, SellWorstY);
            }

            this.StrategiesDenyEntriesAll();

            bestStrategies.Clear();
            worstStrategies.Clear();

            for (int idx = 0; idx < PortfolioStrategies.Count; idx++)
            {
                double value = PortfolioStrategies[idx].PortfolioData["RotationalValue"].safe_cast2double();
                bestStrategies.Add(idx, value);
                worstStrategies.Add(idx, value);
                if (TraceOutput)
                {
                    Output.WriteLine("{0}. For {1} strategy value = {2}", Bars.CurrentBar, idx, value);
                }
            }

            bestStrategies  = bestStrategies.OrderByDescending(elem => elem.Value).ToDictionary(x => x.Key, y => y.Value);
            worstStrategies = worstStrategies.OrderBy(elem => elem.Value).ToDictionary(x => x.Key, y => y.Value);

            if (TraceOutput)
            {
                foreach (var bestElem in bestStrategies)
                {
                    Output.WriteLine("{0}. Best = {1}:{2}.", Bars.CurrentBar, bestElem.Key, bestElem.Value);
                }
            }

            var inLongStrategies = new List <int>();

            this.StrategiesInLong(ref inLongStrategies);

            for (int idx = 0; idx < BuyBestX; idx++)
            {
                if (!inLongStrategies.Contains(bestStrategies.Keys.ElementAt(idx)))
                {
                    PortfolioStrategies[bestStrategies.Keys.ElementAt(idx)].AllowEntriesLong = true;
                }
            }

            var inShortStrategies = new List <int>();

            this.StrategiesInShort(ref inShortStrategies);

            for (int idx = 0; idx < SellWorstY; idx++)
            {
                if (!inShortStrategies.Contains(worstStrategies.Keys.ElementAt(idx)))
                {
                    PortfolioStrategies[worstStrategies.Keys.ElementAt(idx)].AllowEntriesShort = true;
                }
            }

            // money management
            if (UsePortfolioMoneyPcnt)
            {
                for (int idx = 0; idx < BuyBestX; idx++)
                {
                    PortfolioStrategies[bestStrategies.Keys.ElementAt(idx)].EntryContracts =
                        this.CalcContractsForEntry(PortfolioMoneyPcntForEntry, bestStrategies.Keys.ElementAt(idx));
                }

                for (int idx = 0; idx < SellWorstY; idx++)
                {
                    PortfolioStrategies[worstStrategies.Keys.ElementAt(idx)].EntryContracts =
                        this.CalcContractsForEntry(PortfolioMoneyPcntForEntry, worstStrategies.Keys.ElementAt(idx));
                }
            }
        }