Beispiel #1
0
 /// <summary>
 /// Called on each bar update event (incoming tick)
 /// </summary>
 protected override void OnBarUpdate()
 {
     // Use this method for calculating your indicator values. Assign a value to each
     // plot below by replacing 'Close[0]' with your own formula.
     if (CurrentBar < Lenght)
     {
         Trend.Set(true);
         UpTrend.Set(Close[0]);
         DownTrend.Set(Close[0]);
         return;
     }
     ;
     if (Close[0] > DownTrend[1])
     {
         Trend.Set(true);
     }
     else
     if (Close[0] < UpTrend[1])
     {
         Trend.Set(false);
     }
     else
     {
         Trend.Set(Trend[1]);
     }
     if (Trend[0] && !Trend[1])
     {
         UpTrend.Set(Median[0] - ATR(Lenght)[0] * Multiplier);
         UpTrend.Set(1, DownTrend[1]);
         if (ShowArrows)
         {
             DrawArrowUp(CurrentBar.ToString(), true, 0, UpTrend[0] - TickSize, Color.Blue);
         }
     }
     else
     if (!Trend[0] && Trend[1])
     {
         DownTrend.Set(Median[0] + ATR(Lenght)[0] * Multiplier);
         DownTrend.Set(1, UpTrend[1]);
         if (ShowArrows)
         {
             DrawArrowDown(CurrentBar.ToString(), true, 0, DownTrend[0] + TickSize, Color.Red);
         }
     }
     else
     if (Trend[0])
     {
         UpTrend.Set((Median[0] - ATR(Lenght)[0] * Multiplier) > UpTrend[1] ? (Median[0] - ATR(Lenght)[0] * Multiplier) : UpTrend[1]);
     }
     else
     {
         DownTrend.Set((Median[0] + ATR(Lenght)[0] * Multiplier) < DownTrend[1] ? (Median[0] + ATR(Lenght)[0] * Multiplier) : DownTrend[1]);
     }
 }
        protected override void OnBarUpdate()
        {
            if (CurrentBar < 1)
            {
                if (_smooth > 1 && _avg == null)
                    switch (_maType)
                    {
                        case MovingAverageType.SMA:
                            _avg = SMA(Input, _smooth);
                            break;
                        case MovingAverageType.SMMA:
                            _avg = SMMA(Input, _smooth);
                            break;
                        case MovingAverageType.TMA:
                            _avg = TMA(Input, _smooth);
                            break;
                        case MovingAverageType.WMA:
                            _avg = WMA(Input, _smooth);
                            break;
                        case MovingAverageType.VWMA:
                            _avg = VWMA(Input, _smooth);
                            break;
                        case MovingAverageType.TEMA:
                            _avg = TEMA(Input, _smooth);
                            break;
                        case MovingAverageType.HMA:
                            _avg = HMA(Input, _smooth);
                            break;
                        case MovingAverageType.VMA:
                            _avg = VMA(Input, _smooth, _smooth);
                            break;
						case MovingAverageType.JMA:
							_avg = JurikJMA(Input, 0, _smooth);
							break;
                        default:
                            _avg = EMA(Input, _smooth);
                            break;
                    }
                else
                    _avg = Input;

                _trend.Set(true);
                UpTrend.Set(Input[0]);
                DownTrend.Set(Input[0]);
                return;
            }

            switch (_smode)
            {
                case SuperTrendMode.ATR:
                    _offset = ATR(_length)[0] * Multiplier;
                    break;
                case SuperTrendMode.Adaptive:
                    _offset = ATR(_length)[0] * HomodyneDiscriminator(Input)[0] / 10;
                    break;
                default:
                    _offset = Dtt(_length, Multiplier);
                    break;
            }

            if (FirstTickOfBar)
                _prevColor = _tempColor;

            _trend.Set(Close[0] > DownTrend[1] ? true : Close[0] < UpTrend[1] ? false : _trend[1]);

            if (_trend[0] && !_trend[1])
            {
                _th = High[0];
                UpTrend.Set(Math.Max(_avg[0] - _offset, _tl));
                if (Plots[0].PlotStyle == PlotStyle.Line) UpTrend.Set(1, DownTrend[1]);
                _tempColor = _barColorUp;
                if (ShowArrows)
                    DrawArrowUp(CurrentBar.ToString(), true, 0, UpTrend[0] - TickSize, _barColorUp);
                if(PlayAlert && _thisbar != CurrentBar)
                {
                    _thisbar = CurrentBar;
                    PlaySound(LongAlert);
                }
            }
            else
                if (!_trend[0] && _trend[1])
                {
                    _tl = Low[0];
                    DownTrend.Set(Math.Min(_avg[0] + _offset, _th));
                    if (Plots[1].PlotStyle == PlotStyle.Line) DownTrend.Set(1, UpTrend[1]);
                    _tempColor = _barColorDown;
                    if (ShowArrows)
                        DrawArrowDown(CurrentBar.ToString(), true, 0, DownTrend[0] + TickSize, _barColorDown);
                    if (PlayAlert && _thisbar != CurrentBar)
                    {
                        _thisbar = CurrentBar;
                        PlaySound(ShortAlert);
                    }
                }
                else
                {
                    if (_trend[0])
                    {
                        UpTrend.Set((_avg[0] - _offset) > UpTrend[1] ? (_avg[0] - _offset) : UpTrend[1]);
                        _th = Math.Max(_th, High[0]);
                    }
                    else
                    {
                        DownTrend.Set((_avg[0] + _offset) < DownTrend[1] ? (_avg[0] + _offset) : DownTrend[1]);
                        _tl = Math.Min(_tl, Low[0]);
                    }
                    RemoveDrawObject(CurrentBar.ToString());
                    _tempColor = _prevColor;
                }

            if (!_colorBars) 
                return;

            CandleOutlineColor = _tempColor;

            BarColor = Open[0] < Close[0] && ChartControl.ChartStyleType == ChartStyleType.CandleStick
                           ? Color.Transparent
                           : _tempColor;
        }
Beispiel #3
0
        protected override void OnBarUpdate()
        {
            if (CurrentBar == 0)
            {
                trend.Set(true);
                UpTrend.Set(Input[0]);
                DownTrend.Set(Input[0]);
                return;
            }

            switch (smode)
            {
            case SuperTrendMode.ATR: offset = ATR(length)[0] * Multiplier;                                                 break;

            case SuperTrendMode.Adaptive: offset = ATR(length)[0] * HomodyneDiscriminator(Input)[0] / 10;     break;

            default: offset = Dtt(length, Multiplier);                                                             break;
            }

            if (FirstTickOfBar)
            {
                prevColor = tempColor;
            }

            trend.Set(Close[0] > DownTrend[1] || !(Close[0] < UpTrend[1]) && trend[1]);

            if (trend[0] && !trend[1])
            {
                th = High[0];
                UpTrend.Set(Math.Max(avg[0] - offset, tl));
                if (Plots[0].PlotStyle == PlotStyle.Line)
                {
                    UpTrend.Set(1, DownTrend[1]);
                }
                tempColor = barColorUp;
                if (ShowArrows)
                {
                    DrawArrowUp(CurrentBar.ToString(CultureInfo.InvariantCulture), true, 0, UpTrend[0] - TickSize, barColorUp);
                }
                if (thisbar != CurrentBar)
                {
                    thisbar = CurrentBar;
                    if (PlayAlert)
                    {
                        PlaySound(LongAlert);
                    }
                    if (SendEmail && !string.IsNullOrEmpty(mailFrom) && !string.IsNullOrEmpty(mailTo))
                    {
                        SendMail(mailFrom, mailTo, "SuperTrend Long Signal", string.Format("{0}: {1} {2} {3} chart", Time[0], Instrument.FullName, Bars.Period.Value, Bars.Period.Id));
                    }
                }
            }
            else if (!trend[0] && trend[1])
            {
                tl = Low[0];
                DownTrend.Set(Math.Min(avg[0] + offset, th));
                if (Plots[1].PlotStyle == PlotStyle.Line)
                {
                    DownTrend.Set(1, UpTrend[1]);
                }
                tempColor = barColorDown;
                if (ShowArrows)
                {
                    DrawArrowDown(CurrentBar.ToString(CultureInfo.InvariantCulture), true, 0, DownTrend[0] + TickSize, barColorDown);
                }
                if (thisbar != CurrentBar)
                {
                    thisbar = CurrentBar;
                    if (PlayAlert)
                    {
                        PlaySound(ShortAlert);
                    }
                    if (SendEmail && !string.IsNullOrEmpty(mailFrom) && !string.IsNullOrEmpty(mailTo))
                    {
                        SendMail(mailFrom, mailTo, "SuperTrend Short Signal", string.Format("{0}: {1} {2} {3} chart", Time[0], Instrument.FullName, Bars.Period.Value, Bars.Period.Id));
                    }
                }
            }
            else
            {
                if (trend[0])
                {
                    UpTrend.Set((avg[0] - offset) > UpTrend[1] ? (avg[0] - offset) : UpTrend[1]);
                    th = Math.Max(th, High[0]);
                }
                else
                {
                    DownTrend.Set((avg[0] + offset) < DownTrend[1] ? (avg[0] + offset) : DownTrend[1]);
                    tl = Math.Min(tl, Low[0]);
                }
                RemoveDrawObject(CurrentBar.ToString(CultureInfo.InvariantCulture));
                tempColor = prevColor;
            }

            if (!colorBars)
            {
                return;
            }

            CandleOutlineColor = tempColor;
            BarColor           = Open[0] < Close[0] && ChartControl.ChartStyleType == ChartStyleType.CandleStick ? Color.Transparent : tempColor;
        }