Пример #1
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar <= BarsRequired)
            {
                return;
            }

            _macd = MACD_ZeroLag_Colors(1, MACDFast, MACDSlow, MACDSmooth, 0);
            _rsi  = RSI(RSIPeriod, RSISmooth);

            // P(_macd.MacdUp + " " + _macd.MacdDn);
            if (IsFlat)
            {
                LookForEntry();
            }
            else
            {
                LookForStop();
                LookForExit();
            }



            if (!IsFlat)
            {
                ManageTradeByTrailingATR();
                PositionPrice.Set(_positionPrice);
                StopLoss.Set(_lossLevel);
            }
        }
Пример #2
0
        protected void LookForEntry()
        {
            if (_macd.MacdUp[0] == 0 && Rising(_rsi) && Rising(_macd.Avg))
            {
                _tradeState    = TradeState.InitialStop;
                _lossLevel     = Low[0] - TickSize * _mmInitialSL;
                _positionPrice = Close[0];
                PositionPrice.Set(_positionPrice);
                StopLoss.Set(_lossLevel);
                SetSignal(1, "going long");
                return;
            }

            if (_macd.MacdDn[0] == 0 && Falling(_rsi) && Falling(_macd.Avg))
            {
                _tradeState    = TradeState.InitialStop;
                _lossLevel     = High[0] + TickSize * _mmInitialSL;
                _positionPrice = Close[0];
                PositionPrice.Set(_positionPrice);
                StopLoss.Set(_lossLevel);
                SetSignal(-1, "going short");
                return;
            }
        }