Пример #1
0
        /// <summary>
        /// Generato ad ogni tick, vengono effettuati i calcoli dell'indicatore
        /// </summary>
        /// <param name="index">L'indice della candela in elaborazione</param>
        public override void Calculate(int index)
        {
            // --> Si esce se non ci sono le condizioni per continuare
            if (!ItsOk)
            {
                return;
            }


            Symbol CROSS      = Symbols.GetSymbol(MySymbol);
            Bars   CROSS_Bars = MarketData.GetBars(TimeFrame, CROSS.Name);

            // --> Potrei avere un indice diverso perchè non carico le stesse barre
            int CROSS_Index = CROSS_Bars.GetIndexByDate(Bars.OpenTimes[index]);

            if (CROSS_Index < 0)
            {
                return;
            }

            ExponentialMovingAverage CROSS_ema         = Indicators.ExponentialMovingAverage(CROSS_Bars.ClosePrices, MyEMAPeriod);
            ExponentialMovingAverage Current_CROSS_ema = Indicators.ExponentialMovingAverage(Bars.ClosePrices, MyEMAPeriod);

            double CROSSpips = 0;

            // --> Devo uniformare il numero di pips, i digits saranno di sicuro diversi
            CROSSpips     = CROSS.DigitsToPips(Math.Round(CROSS_Bars.ClosePrices[CROSS_Index] - CROSS_ema.Result[CROSS_Index], CROSS.Digits));
            Result[index] = Math.Round(Current_CROSS_ema.Result[index] + Symbol.PipsToDigits(CROSSpips), Symbol.Digits);

            if (!ShowLabel)
            {
                return;
            }

            string CROSStext = string.Format("  ‹ {0} {1:0.00} ( {2:0.00000} )", CROSS.Name, CROSSpips, CROSS_Bars.ClosePrices[CROSS_Index]);

            if (CanDraw)
            {
                ChartText ThisLabel = Chart.DrawText(CROSS.Name, CROSStext, index, Result[index], Color.FromName(LabelColor.ToString()));
                ThisLabel.VerticalAlignment = VerticalAlignment.Center;
            }
        }