Beispiel #1
0
 protected override void Initialize()
 {
     FastMA = Indicators.MovingAverage(MarketSeries.Close, Fast_Period, MA_Type);
     SlowMA = Indicators.MovingAverage(MarketSeries.Open, Slow_Period, MA_Type);
     ATR    = Indicators.AverageTrueRange(14, MovingAverageType.Simple);
     count  = MarketSeries.Open.Count;
 }
Beispiel #2
0
 protected override void Initialize()
 {
     _trend            = new int[1];
     _upBuffer         = CreateDataSeries();
     _downBuffer       = CreateDataSeries();
     _averageTrueRange = Indicators.AverageTrueRange(Period, MovingAverageType.WilderSmoothing);
 }
Beispiel #3
0
 protected override void OnStart()
 {
     Positions.Opened += OnPositionOpen;
     tm            = new TradeManager(this);
     _announceTime = Convert.ToDateTime(AnnounceDateTime);
     _atr          = Indicators.AverageTrueRange(14, MovingAverageType.Simple);
 }
        protected override void OnStart()
        {
            Print("Lot sizing rule: {0}", LotSizingRule);

            var symbolLeverage = Symbol.DynamicLeverage[0].Leverage;

            Print("Symbol leverage: {0}", symbolLeverage);

            var realLeverage = Math.Min(symbolLeverage, Account.PreciseLeverage);

            Print("Account leverage: {0}", Account.PreciseLeverage);

            Init(true,
                 false,
                 InitialStopLossRuleValues.None,
                 InitialStopLossInPips,
                 TrailingStopLossRule,
                 TrailingStopLossInPips,
                 LotSizingRule,
                 TakeProfitRuleValues.None,
                 0,
                 0,
                 false,
                 false,
                 DynamicRiskPercentage,
                 BarsToAllowTradeToDevelop);

            _atr    = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
            _spring = Indicators.GetIndicator <Spring>(SourceSeries, 89, 55, 21, SendEmailAlerts, PlayAlertSound, ShowMessage,
                                                       SignalBarRangeMultiplier, MaFlatFilter, BreakoutFilter, MinimumBarsForLowestLow, SwingHighStrength, BigMoveFilter);
            _minimumBuffer      = Symbol.PipSize * 6;
            _timeFrameInMinutes = GetTimeFrameInMinutes();
        }
Beispiel #5
0
        protected override void Initialize()
        {
            if (EnableATRInfo)
            {
                atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
            }

            if (EnableD1)
            {
                seriesD1 = MarketData.GetSeries(TimeFrame.Daily);
                macdD1   = Indicators.MacdCrossOver(seriesD1.Close, 26, 12, 9);
                mmD1     = Indicators.ExponentialMovingAverage(seriesD1.Close, 200);
            }

            if (EnableH4)
            {
                seriesH4 = MarketData.GetSeries(TimeFrame.Hour4);
                macdH4   = Indicators.MacdCrossOver(seriesH4.Close, 26, 12, 9);
                mmH4     = Indicators.ExponentialMovingAverage(seriesH4.Close, 200);
            }

            if (EnableH1)
            {
                seriesH1 = MarketData.GetSeries(TimeFrame.Hour);
                macdH1   = Indicators.MacdCrossOver(seriesH1.Close, 26, 12, 9);
                mmH1     = Indicators.ExponentialMovingAverage(seriesH1.Close, 200);
            }

            if (EnableM5)
            {
                seriesM5 = MarketData.GetSeries(TimeFrame.Minute5);
                macdM5   = Indicators.MacdCrossOver(seriesM5.Close, 26, 12, 9);
                mmM5     = Indicators.ExponentialMovingAverage(seriesM5.Close, 200);
            }
        }
 protected override void OnStart()
 {
     // Put your initialization logic here
     config    = LoadConfiguration <Config.OneCandleToWinConfig>(ExpandConfigFilePath(ConfigurationFilePath));
     IsRunning = false;
     atr       = Indicators.AverageTrueRange(14, MovingAverageType.Simple);
 }
        //-----------------------------------------------------------------------------------------------
        // SCALPER SIGNAL FUNCTION ----------------------------------------------------------------------
        //-----------------------------------------------------------------------------------------------
        private void SignalScalper_Main(int index)
        {
            if (!NewBar(index) || (index < 6))
            {
                return;
            }

            ATR = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);

            double bs = BuySignal(index);
            double ss = SellSignal(index);

            if (bs > 0)
            {
                BuyIndicator[index]      = bs;
                SignalBarHigh[index - 3] = MarketSeries.High[index - 3];
                SignalBarLow[index - 3]  = MarketSeries.Low[index - 3];
                ChartObjects.DrawLine("SignalBar" + (index - 3), index - 3, SignalBarHigh[index - 3], index - 3, SignalBarLow[index - 3], Colors.Gold, 3, LineStyle.Solid);
            }
            else if (ss > 0)
            {
                SellIndicator[index]     = ss;
                SignalBarHigh[index - 3] = MarketSeries.High[index - 3];
                SignalBarLow[index - 3]  = MarketSeries.Low[index - 3];
                ChartObjects.DrawLine("SignalBar" + (index - 3), index - 3, SignalBarHigh[index - 3], index - 3, SignalBarLow[index - 3], Colors.Gold, 3, LineStyle.Solid);
            }
        }
Beispiel #8
0
        protected override void OnStart()
        {
            Positions.Opened += OnPositionOpen;
            tm = new TradeManager(this);
            tm.PrintTestMessage();

            IndAtr = Indicators.AverageTrueRange(14, MovingAverageType.Simple);
            IndSMA = Indicators.SimpleMovingAverage(SMASource, SMAPeriod);
            IndSAR = Indicators.ParabolicSAR(SARMINAF, SARMAXAF);
            IndDMS = Indicators.DirectionalMovementSystem(DMSPeriod);

            /*
             * ===============================================================================================
             * DETERMINE STOP LOSS AND TAKE PROFIT VALUES
             * ===============================================================================================
             */
            if (TrailingStopTrigger == 0 || IncludeTrailingStop == false)
            {
                Vstop_loss = null;
            }
            else
            {
                Vstop_loss = TrailingStopTrigger;
            }
            // TAKE PROFIT
            // IF SET TO 0 OR USER HAS NOT INCLUDED TAKE PROFIT - SET TO NULL
            if (TakeProfitTrigger == 0 || IncludeTakeProfit == false)
            {
                Vtake_profit = null;
            }
            else
            {
                Vtake_profit = TakeProfitTrigger;
            }
        }
Beispiel #9
0
        protected override void Initialize()
        {
            // Summary
            YesterdayKeyLevels = Business.KeyLevels.GetYesterdaysKeyLevels(Account.BrokerName, Symbol.Code);

            if (YesterdayKeyLevels != null)
            {
                YesterdayKeyLevels.CalculateDaily();

                // Write Summary
                string Summary = Symbol.Code.ToString() + ": Yesterday's (" + YesterdayKeyLevels.Date.ToShortDateString() + ") Open: " + YesterdayKeyLevels.Open.ToString() + ", Close: " + YesterdayKeyLevels.Close.ToString() + ", High: " + YesterdayKeyLevels.High.ToString() + ", Low: " + YesterdayKeyLevels.Low.ToString();
                ChartObjects.DrawText("Previous", Summary, StaticPosition.BottomRight, Colors.Red);

                // Calculate ATR
                var ATRSeries        = MarketData.GetSeries(TimeFrame.Daily);
                AverageTrueRange ATR = Indicators.AverageTrueRange(ATRSeries, 5, MovingAverageType.Simple);
                ChartObjects.DrawText("ATR", "ATR: " + ATR.Result.LastValue.ToString("0.##") + ", 15% ATR: " + (ATR.Result.LastValue * 0.15).ToString("0.##") + ",30% ATR: " + (ATR.Result.LastValue * 0.3).ToString("0.##") + "", StaticPosition.TopRight, Colors.Red);

                // DAILY
                //  ChartObjects.DrawHorizontalLine("DailyHigh", YesterdayKeyLevels.High,  Colors.Green, 1, LineStyle.LinesDots);
                //  ChartObjects.DrawHorizontalLine("DailyLow", YesterdayKeyLevels.Low, Colors.Green, 1, LineStyle.LinesDots);
                // ChartObjects.DrawHorizontalLine("DailyCLose", YesterdayKeyLevels.Close, Colors.Green, 1, LineStyle.LinesDots);



                // Daily Levels

                P = ((YesterdayKeyLevels.High + YesterdayKeyLevels.Low + YesterdayKeyLevels.Close) / 3);

                R1 = ((2 * P) - YesterdayKeyLevels.Low);
                R2 = (P + YesterdayKeyLevels.High - YesterdayKeyLevels.Low);
                R3 = (YesterdayKeyLevels.High + 2 * (P - YesterdayKeyLevels.Low));

                S1 = ((2 * P) - YesterdayKeyLevels.High);
                S2 = (P - YesterdayKeyLevels.High + YesterdayKeyLevels.Low);
                S3 = YesterdayKeyLevels.Low - 2 * (YesterdayKeyLevels.High - P);

                CBOL = ((YesterdayKeyLevels.High - YesterdayKeyLevels.Low) * 1.1 / 2 + YesterdayKeyLevels.Close);
                CBOS = YesterdayKeyLevels.Close - (YesterdayKeyLevels.High - YesterdayKeyLevels.Low) * 1.1 / 2;



                //WP = ((WeeklyHigh + WeeklyLow + WeeklyClose) / 3);
                //MP = ((MonthlyHigh + MonthlyLow + MonthlyClose) / 3);



                // WEEKLY
                // ChartObjects.DrawHorizontalLine("WeeklyHigh", WeeklyHigh, Colors.Green, 1, LineStyle.Lines);
                //ChartObjects.DrawHorizontalLine("WeeklyLow", WeeklyLow, Colors.Red, 1, LineStyle.Lines);
                //   ChartObjects.DrawHorizontalLine("WeeklyClose", WeeklyClose, Colors.DeepSkyBlue, 1, LineStyle.LinesDots);


                // MONTHLY
                //ChartObjects.DrawHorizontalLine("MonthlyHigh", MonthlyHigh, Colors.Green, 3, LineStyle.Lines);
                //ChartObjects.DrawHorizontalLine("MonthlyLow", MonthlyLow, Colors.Red, 3, LineStyle.Lines);
                //   ChartObjects.DrawHorizontalLine("MonthlyClose", MonthlyClose, Colors.DarkGray, 1, LineStyle.LinesDots);
            }
        }
Beispiel #10
0
 protected override void Initialize()
 {
     // Initialize and create nested indicators
     _fastMA = Indicators.MovingAverage(Source, FastPeriodParameter, MovingAverageType.Exponential);
     _slowMA = Indicators.MovingAverage(Source, SlowPeriodParameter, MovingAverageType.Exponential);
     _swingHighLowIndicator = Indicators.GetIndicator <SwingHighLow>(Bars.HighPrices, Bars.LowPrices, SwingHighStrength);
     _atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
 }
Beispiel #11
0
 protected override void OnStart()
 {
     fastMa   = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
     mediumMa = Indicators.MovingAverage(SourceSeries, mediumPeriods, MAType);
     slowMa   = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
     atr      = Indicators.AverageTrueRange(atrPeriod, MAType);
     bBand    = Indicators.BollingerBands(SourceSeries, bBandPeriods, bBandDeviations, MAType);
 }
Beispiel #12
0
        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;
            Positions.Opened += OnPositionsOpened;

            atr = Indicators.AverageTrueRange(atrPeriod, MovingAverageType.Simple);
            InitialZoneRecovery();
        }
Beispiel #13
0
        protected override void Initialize()
        {
            _atr    = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
            _buffer = Symbol.PipSize * 5;
            //_fastMA = Indicators.ExponentialMovingAverage(SourceSeries, FastMAPeriod);

            //var h4 = MarketData.GetSeries(TimeFrame.Hour4);
            //_slowMA = Indicators.ExponentialMovingAverage(h4.Close, H4Periods);
        }
Beispiel #14
0
 protected override void OnStart()
 {
     i_TrendMovingAverage   = Indicators.SimpleMovingAverage(MarketSeries.Close, (int)_TrendSMA);
     i_Intermediate_SMA     = Indicators.SimpleMovingAverage(MarketData.GetSeries(TimeFrame.Hour4).Close, (int)_DailyIntermediateTrend_SMA);
     i_RSI_StopLoss         = Indicators.RelativeStrengthIndex(MarketSeries.Close, (int)_wRSI_StopLossMA);
     i_TriggerMovingAverage = Indicators.SimpleMovingAverage(MarketSeries.Close, (int)_SlowSMATrigger);
     i_Average_True_Range   = Indicators.AverageTrueRange((int)_ATR_MA, MovingAverageType.Simple);
     i_RSI = Indicators.RelativeStrengthIndex(MarketSeries.Close, (int)_cRSI_MA);
 }
Beispiel #15
0
 protected override void OnStart()
 {
     //fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
     //mediumMa = Indicators.MovingAverage(SourceSeries, mediumPeriods, MAType);
     //slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
     atr   = Indicators.AverageTrueRange(atrPeriod, MAType);
     bBand = Indicators.BollingerBands(SourceSeries, bBandPeriods, bBandDeviations, MAType);
     _kama = Indicators.GetIndicator <KAMASignal>(Source, Fast, Slow, Period);
 }
Beispiel #16
0
        protected override void OnStart()
        {
            dc1 = Indicators.DonchianChannel(dcPeriod1);
            dc2 = Indicators.DonchianChannel(dcPeriod2);

            ema1 = Indicators.ExponentialMovingAverage(MarketSeries.Close, emaPeriod1);
            ema2 = Indicators.ExponentialMovingAverage(MarketSeries.Close, emaPeriod2);

            atr = Indicators.AverageTrueRange(atrPeriod, MovingAverageType.Exponential);
        }
Beispiel #17
0
        // other filter indicator 1


        // other filter indicator 2


        // exit indicator

/*
 *          private HeikenAshiDirection i_ha;
 */


        #endregion

        #region cTrader events

        protected override void OnStart()
        {
            // Instantiate Indicators
            i_atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
            i_obv = Indicators.OnBalanceVolume(Source);
            //i_ha = Indicators.GetIndicator<HeikenAshiDirection>();


            Positions.Opened += PositionsOnOpened;
            Positions.Closed += PositionsOnClosed;
        }
        protected override void OnStart()
        {
            _maCrossIndicator = Indicators.GetIndicator <MACrossOver>(SourceSeries, SlowPeriodParameter, MediumPeriodParameter, FastPeriodParameter, false, false, false);
            _fastMA           = Indicators.MovingAverage(SourceSeries, FastPeriodParameter, MovingAverageType.Exponential);
            _mediumMA         = Indicators.MovingAverage(SourceSeries, MediumPeriodParameter, MovingAverageType.Exponential);
            _slowMA           = Indicators.MovingAverage(SourceSeries, SlowPeriodParameter, MovingAverageType.Exponential);
            _rsi = Indicators.RelativeStrengthIndex(SourceSeries, 14);
            _atr = Indicators.AverageTrueRange(Bars, 14, MovingAverageType.Exponential);

            Print("Take Longs: {0}", TakeLongsParameter);
            Print("Take Shorts: {0}", TakeShortsParameter);
            Print("Initial SL rule: {0}", InitialStopLossRule);
            Print("Initial SL in pips: {0}", InitialStopLossInPips);
            Print("Trailing SL rule: {0}", TrailingStopLossRule);
            Print("Trailing SL in pips: {0}", TrailingStopLossInPips);
            Print("Lot sizing rule: {0}", LotSizingRule);
            Print("Take profit rule: {0}", TakeProfitRule);
            Print("Take profit in pips: {0}", TakeProfitInPips);
            Print("Minutes to wait after position closed: {0}", MinutesToWaitAfterPositionClosed);
            Print("Move to breakeven: {0}", MoveToBreakEven);
            Print("Close half at breakeven: {0}", CloseHalfAtBreakEven);
            Print("MA Cross Rule: {0}", MaCrossRule);
            Print("H4MA: {0}", H4MaPeriodParameter);
            Print("Recording: {0}", RecordSession);
            Print("Enter at Market: {0}", EnterAtMarket);
            Print("BarsToAllowTradeToDevelop: {0}", BarsToAllowTradeToDevelop);

            Init(TakeLongsParameter,
                 TakeShortsParameter,
                 InitialStopLossRule,
                 InitialStopLossInPips,
                 TrailingStopLossRule,
                 TrailingStopLossInPips,
                 LotSizingRule,
                 TakeProfitRule,
                 TakeProfitInPips,
                 MinutesToWaitAfterPositionClosed,
                 MoveToBreakEven,
                 CloseHalfAtBreakEven,
                 DynamicRiskPercentage,
                 BarsToAllowTradeToDevelop);

            Notifications.SendEmail("*****@*****.**", "*****@*****.**", "MA Cross Over robot initialized", "This is a test");

            if (RecordSession)
            {
                _runId = SaveRunToDatabase();
                if (_runId <= 0)
                {
                    throw new InvalidOperationException("Run Id was <= 0!");
                }
            }
        }
Beispiel #19
0
 protected override void Initialize()
 {
     //Algoline here
     _trendlong             = new int[1];
     _trendshort            = new int[1];
     _upBufferlong          = CreateDataSeries();
     _downBufferlong        = CreateDataSeries();
     _upBuffershort         = CreateDataSeries();
     _downBuffershort       = CreateDataSeries();
     _averageTrueRangelong  = Indicators.AverageTrueRange(LongPeriod, MovingAverageType.WilderSmoothing);
     _averageTrueRangeshort = Indicators.AverageTrueRange(ShortPeriod, MovingAverageType.WilderSmoothing);
 }
Beispiel #20
0
        protected override void Initialize()
        {
            // Initialize and create nested indicators
            Print("Initializing Resistence Break indicator");

            _swingHighLowIndicator = Indicators.GetIndicator <SwingHighLow>(Bars.ClosePrices, Bars.ClosePrices, SwingHighStrength);
            _atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
            _latestSignalIndex = 0;

            Print("Finished initializing");

            //GoToTestDate();
        }
Beispiel #21
0
 protected override void Initialize()
 {
     _atr       = Indicators.AverageTrueRange(lookBack, MovingAverageType.Exponential);
     _shortExit = CreateDataSeries();
     _longExit  = CreateDataSeries();
     isTick     = MarketSeries.TimeFrame.ToString() == "Tick" ? true : false;
     if (isTick)
     {
         //intantiate bid/ask buffers
         _bids = new CircularBuffer <double>(lookBack);
         _asks = new CircularBuffer <double>(lookBack);
     }
 }
Beispiel #22
0
        protected override void OnTick()
        {
            double averageTrueRange = 100000 * Indicators.AverageTrueRange(MarketSeries, 5, MovingAverageType.VIDYA).Result.Last(0);

            TradeType?tradeType = signal();

            if (tradeType.HasValue)
            {
                ExecuteMarketOrder(tradeType.Value, Symbol, InitialVolume, _instanceLabel, 100, 100, 2);
            }

            SetTrailingStop(averageTrueRange);

            ZeroLoss();
        }
Beispiel #23
0
        protected override void Initialize()
        {
            series1m    = MarketData.GetSeries(TimeFrame.Minute);
            series5m    = MarketData.GetSeries(TimeFrame.Minute5);
            series15m   = MarketData.GetSeries(TimeFrame.Minute15);
            series60m   = MarketData.GetSeries(TimeFrame.Hour);
            seriesdaily = MarketData.GetSeries(TimeFrame.Daily);

            atr      = Indicators.AverageTrueRange(21, MovingAverageType.Exponential);
            atr1m    = Indicators.AverageTrueRange(series1m, 21, MovingAverageType.Exponential);
            atr5m    = Indicators.AverageTrueRange(series5m, 21, MovingAverageType.Exponential);
            atr15m   = Indicators.AverageTrueRange(series15m, 21, MovingAverageType.Exponential);
            atr60m   = Indicators.AverageTrueRange(series60m, 21, MovingAverageType.Exponential);
            atrdaily = Indicators.AverageTrueRange(seriesdaily, 21, MovingAverageType.Exponential);
        }
Beispiel #24
0
        protected override void OnStart()
        {
            hmafast      = Indicators.GetIndicator <HMAfast>(5);
            hmaslow      = Indicators.GetIndicator <HMAslow>(31);
            _macd        = Indicators.MacdHistogram(LongCycle, ShortCycle, Period);
            HmaDaySeries = MarketData.GetSeries(TimeFrame.Hour4);
            hmaSignal    = Indicators.GetIndicator <HMASignals>(HmaDaySeries, 21, false, false, 3, false, 24);

            var dailySeries = MarketData.GetSeries(TimeFrame.Daily);

            atr = Indicators.AverageTrueRange(dailySeries, 20, MovingAverageType.Simple);

            Positions.Opened += PositionsOnOpened;
            Positions.Closed += PositionsOnClosed;
        }
Beispiel #25
0
        protected override void OnTimer()
        {
            if (!ordersPlaced && (Time.Minute == NewsMinute - 1 || (NewsMinute == 0 && Time.Minute == 59)) && Time.Second >= 56)
            {
                AverageTrueRange averageTrueRange = Indicators.AverageTrueRange(ATRPeriod, MovingAverageType.Exponential);
                double           LegSize          = Math.Max((averageTrueRange.Result.LastValue * 10000) * ATRMultiplier, MinLegSize);

                // take the $ value to be risked, convert into lots using the pip value of the current pair, then
                // convert that in volume for cTrader, then normalize it so that we dont get wierd fractional volumes,
                // in volume must always be a multiple of 1000
                long volume = ((long)((Risk / (LegSize * 2)) / Symbol.PipValue) / 1000) * 1000;

                PlaceStopOrderAsync(TradeType.Buy, Symbol, volume, Symbol.Bid + (LegSize * Symbol.PipSize), "NTBUY", LegSize * 2, RiskReward * LegSize);
                PlaceStopOrderAsync(TradeType.Sell, Symbol, volume, Symbol.Bid - (LegSize * Symbol.PipSize), "NTBUY", (LegSize * 2), RiskReward * LegSize);
                ordersPlaced = true;
            }
        }
Beispiel #26
0
        protected override void OnStart()
        {
            Init(InitialStopLossRuleParameter, InitialSLPipsParameter, LotSizingRuleParameter, TrailingStopLossRuleParameter, TrailingSLPipsParameter, MoveToBreakEvenParameter, TakeLongsParameter, TakeShortsParameter);
            base.OnStart();
            _fastMA   = Indicators.MovingAverage(SourceSeries, 50, MovingAverageType.Exponential);
            _mediumMA = Indicators.MovingAverage(SourceSeries, 100, MovingAverageType.Exponential);
            _slowMA   = Indicators.MovingAverage(SourceSeries, 240, MovingAverageType.Weighted);
            _atr      = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);

            ValidateThresholds();

            double currentHigh  = MarketSeries.High[1];
            double currentClose = MarketSeries.Close[1];
            double currentLow   = MarketSeries.Low[1];

            Print("HLC: {0},{1},{2}", currentHigh, currentLow, currentClose);
        }
Beispiel #27
0
        protected override void OnStart()
        {
            barId             = MarketSeries.Close.Count;
            pendingOrderBarId = barId;

            rseries = MarketData.GetSeries(MarketSeries.SymbolCode, TimeFrame.Day2);

            lmm50  = Indicators.ExponentialMovingAverage(MarketSeries.Close, 50);
            rmm200 = Indicators.SimpleMovingAverage(rseries.Close, 200);

            lmacd = Indicators.MacdCrossOver(MarketSeries.Close, 26, 12, 9);
            rmacd = Indicators.MacdCrossOver(rseries.Close, 26, 12, 9);

            atr = Indicators.AverageTrueRange(MarketSeries, 14, MovingAverageType.Simple);
            Positions.Closed += PositionsOnClosed;
            Positions.Opened += PositionsOnOpened;
        }
        /// <summary>
        /// CALLED WHEN THE ROBOT FIRST STARTS, IT IS ONLY CALLED ONCE.
        /// </summary>
        protected override void OnStart()
        {
            // CONSTRUCT THE INDICATORS
            _rsi = Indicators.RelativeStrengthIndex(RSISource, RSIPeriod);

            _smaHIGH = Indicators.SimpleMovingAverage(HighSMASource, HighSMAPeriod);
            _smaLOW  = Indicators.SimpleMovingAverage(LowSMASource, LowSMAPeriod);

            _mom = Indicators.MomentumOscillator(MOMSource, MOMPeriod);

            _atr = Indicators.AverageTrueRange(ATRPeriod, MovingAverageType.Simple);

            _md = MarketData.GetMarketDepth(Symbol);

            _rvi = Indicators.GetIndicator <RelativeVigorIndex>(RVIPeriod, MovingAverageType.Simple);

            tm = new TradeManager(this);
        }
        /// <summary>
        /// Viene generato all'avvio dell'indicatore, si inizializza l'indicatore
        /// </summary>
        protected override void Initialize()
        {
            // --> Stampo nei log la versione corrente
            Print("{0} : {1}", NAME, VERSION);

            DeTrended = Indicators.DetrendedPriceOscillator(Bars.ClosePrices, Period, MAType);
            EMASmooth = Indicators.ExponentialMovingAverage(DeTrended.Result, Smooth);
            MA        = Indicators.MovingAverage(Bars.ClosePrices, Period, MAType);
            SAR       = Indicators.ParabolicSAR(0.02, 0.2);
            ATR       = Indicators.AverageTrueRange(Period, MAType);

            K = Symbol.PipsToDigits(K);

            // --> Inizializzo i parametri grafici
            _updateCandleSize();

            // --> Ridisegno tutte le candele ogni volta che cambia lo zoom
            Chart.ZoomChanged += _repaint;
        }
        public override void Calculate(int index)
        {
            // --> Abbiamo bisogno di 3 candele per essere sicuri
            if (index < 3)
            {
                return;
            }

            // --> Gli indicatori che ci indicano il trend e il suo movimento
            DetrendedPriceOscillator Faster = Indicators.DetrendedPriceOscillator(Source, Period, MAType);
            DetrendedPriceOscillator Slower = Indicators.DetrendedPriceOscillator(Source, Period * 2, MAType);
            AverageTrueRange         ATR    = Indicators.AverageTrueRange(ATRPeriod, ATRMAType);

            // --> Imposto la logica della strategia
            bool LongFilterSlow = Slower.Result.LastValue > K;
            bool LongFilterFast = Faster.Result.LastValue > K;
            bool LongCross      = Faster.Result.Last(1) > K && Faster.Result.Last(2) < -K && Faster.Result.Last(3) <= -K;

            bool ShortFilterSlow = Slower.Result.LastValue < -K;
            bool ShortFilterFast = Faster.Result.LastValue < -K;
            bool ShortCross      = Faster.Result.Last(1) < -K && Faster.Result.Last(2) > K && Faster.Result.Last(3) >= K;

            bool LongCrossSlower  = Slower.Result.Last(1) > K && Slower.Result.Last(2) < -K;
            bool ShortCrossSlower = Slower.Result.Last(1) < -K && Slower.Result.Last(2) > K;

            string SignalName = String.Format("{0}-{1}", NAME, index);

            // --> Se è attivato l'ATR con il periodo superiore a zero allora ne controllo la condizione
            if (ATRPeriod > 0 && ATR.Result.LastValue <= ATRK)
            {
                return;
            }

            if ((LongFilterFast && LongCrossSlower) || (LongFilterSlow && LongCross))
            {
                Chart.DrawIcon(SignalName, ChartIconType.UpArrow, index, Bars.LowPrices[index], ColorLong);
            }
            else if ((ShortFilterFast && ShortCrossSlower) || (ShortFilterSlow && ShortCross))
            {
                Chart.DrawIcon(SignalName, ChartIconType.DownArrow, index, Bars.HighPrices[index], ColorShort);
            }
        }