Ejemplo n.º 1
0
        /// <summary>
        /// Parto dalle ultime candele daily e le disegno ogni volta
        /// </summary>
        /// <param name="index"></param>
        private void _drawLevelFromDailyBar()
        {
            // --> Prelevo le candele daily
            Bars BarsDaily = MarketData.GetBars(TimeFrame.Daily);

            int index = BarsDaily.Count - 1;

            // --> eseguo un ciclo aretroso per disegnare le ultime candele
            for (int i = 0; i < DayShow; i++)
            {
                // --> Il numero di candele da visualizzare potrebbero essere troppe
                try
                {
                    DateTime today = BarsDaily[index - i].OpenTime;
                    // --> FirstCandleOfTheDay.OpenTime;
                    // --> Facendo attenzione al Venerdì ?
                    DateTime tomorrow = today.AddDays(1);

                    string rangeFlag = today.ToString();

                    Chart.DrawTrendLine("High" + rangeFlag, today, BarsDaily[index - i].High, tomorrow, BarsDaily[index - i].High, Color.FromName(ColorHigh), TicknessBox, LineStyleBox);
                    Chart.DrawTrendLine("Low" + rangeFlag, today, BarsDaily[index - i].Low, tomorrow, BarsDaily[index - i].Low, Color.FromName(ColorLow), TicknessBox, LineStyleBox);
                } catch
                {
                }
            }
        }
Ejemplo n.º 2
0
        protected override void Initialize()
        {
            try
            {
                // Initialize and create nested indicators
                Print("Initializing Zone PullBack indicator");

                Print("Running mode: {0}", RunningMode);
                Print("IsBackTesting: {0}", IsBacktesting);

                _fastMA            = Indicators.MovingAverage(Source, 21, MovingAverageType.Exponential);
                _mediumMA          = Indicators.MovingAverage(Source, 55, MovingAverageType.Exponential);
                _slowMA            = Indicators.MovingAverage(Source, 89, MovingAverageType.Simple);
                _latestSignalIndex = 0;
                _maRangeBuffer     = Symbol.PipSize * 4;
                var dailySeries = MarketData.GetBars(TimeFrame.Daily);

                if (LongTermTrendFilter)
                {
                    _dailyFastMA   = Indicators.ExponentialMovingAverage(dailySeries.ClosePrices, 21);
                    _dailyMediumMA = Indicators.ExponentialMovingAverage(dailySeries.ClosePrices, 55);
                }

                Print("Finished initializing");
            }
            catch (Exception ex)
            {
                Print("Failed initialization: {0}", ex);
                throw;
            }
        }
Ejemplo n.º 3
0
        protected override void Initialize()
        {
            // Initialize and create nested indicators
            _fastMA   = Indicators.MovingAverage(SourceSeries, FastPeriodParameter, MovingAverageType.Exponential);
            _mediumMA = Indicators.MovingAverage(SourceSeries, MediumPeriodParameter, MovingAverageType.Exponential);
            _slowMA   = Indicators.MovingAverage(SourceSeries, SlowPeriodParameter, MovingAverageType.Exponential);

            var higherSeries = MarketData.GetBars(TimeFrame.Hour);

            _higherTimeframeMA = Indicators.MovingAverage(higherSeries.ClosePrices, FastPeriodParameter, MovingAverageType.Exponential);
        }
Ejemplo n.º 4
0
        protected override void OnStart()
        {
            longBars  = MarketData.GetBars(longTimeFrame);
            shortBars = MarketData.GetBars(shortTimeFrame);

            shortEMAfast   = Indicators.ExponentialMovingAverage(shortBars.ClosePrices, ShortMAFastPeriod);   //green
            shortEMAmedium = Indicators.ExponentialMovingAverage(shortBars.ClosePrices, ShortMAMediumPeriod); //blue
            shortEMAslow   = Indicators.ExponentialMovingAverage(shortBars.ClosePrices, ShortMASlowPeriod);   //red

            longEMAfast = Indicators.ExponentialMovingAverage(longBars.ClosePrices, LongMAFastPeriod);        //green
            longEMAslow = Indicators.ExponentialMovingAverage(longBars.ClosePrices, LongMASlowPeriod);        //red

            SimpleScalpingTrades = new List <SimpleScalpingTrade>();

            Positions.Closed     += Positions_Closed;
            PendingOrders.Filled += PendingOrders_Filled;
        }
Ejemplo n.º 5
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;
            }
        }
        protected override void OnStart()
        {
            Print("開始");

            fileFullPath = System.IO.Path.Combine(para_filePath, fileName);
            WriteCsvFile(csvHeader);
            Print(csvHeader);

            foreach (var baseSymbol in Symbols)
            {
                foreach (var subSymbol in Symbols)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(baseSymbol);
                    sb.Append(",");
                    sb.Append(subSymbol);
                    sb.Append(",");

                    foreach (var timeFrame in timeFrames)
                    {
                        //メインシンボルとサブシンボルのバーの数を少ないほうに合わせる
                        int barCount = System.Math.Min(MarketData.GetBars(timeFrame, baseSymbol).Count, MarketData.GetBars(timeFrame, subSymbol).Count);

                        //メインシンボルとサブシンボルの終値のリストを作成する
                        var closePriceOfBaseSymbol = new List <double>();
                        var closePriceOfSubSymbol  = new List <double>();

                        for (int i = 0; i < barCount; i++)
                        {
                            closePriceOfBaseSymbol.Add(MarketData.GetBars(timeFrame, baseSymbol).ClosePrices.Last(i));
                            closePriceOfSubSymbol.Add(MarketData.GetBars(timeFrame, subSymbol).ClosePrices.Last(i));
                        }
                        //相関係数を算出する
                        sb.Append(ComputeCoeff(closePriceOfBaseSymbol, closePriceOfSubSymbol));
                        sb.Append(",");
                    }
                    WriteCsvFile(sb.ToString());
                }
            }
            Print("終了");
        }
        protected override void Initialize()
        {
            color1  = Color.FromHex(lineColor1);
            series1 = MarketData.GetBars(timeframe1);
            ma1     = Indicators.MovingAverage(series1.ClosePrices, Period1, MAType1);
            val1    = ma1.Result.LastValue;
            if (Visibility1 == true)
            {
                Chart.DrawTrendLine("Extension1", series1.OpenTimes.LastValue, val1, MarketData.GetBars(TimeFrame.Minute).OpenTimes.LastValue, val1, color1, Thickness1, LineStyle1);
            }

            color2  = Color.FromHex(lineColor2);
            series2 = MarketData.GetBars(timeframe2);
            ma2     = Indicators.MovingAverage(series2.ClosePrices, Period2, MAType2);
            val2    = ma2.Result.LastValue;
            if (Visibility2 == true)
            {
                Chart.DrawTrendLine("Extension2", series2.OpenTimes.LastValue, val2, MarketData.GetBars(TimeFrame.Minute).OpenTimes.LastValue, val2, color2, Thickness2, LineStyle2);
            }



            color3  = Color.FromHex(lineColor3);
            series3 = MarketData.GetBars(timeframe3);
            ma3     = Indicators.MovingAverage(series3.ClosePrices, Period3, MAType3);
            val3    = ma3.Result.LastValue;
            if (Visibility3 == true)
            {
                Chart.DrawTrendLine("Extension3", series3.OpenTimes.LastValue, val3, MarketData.GetBars(TimeFrame.Minute).OpenTimes.LastValue, val3, color3, Thickness3, LineStyle3);
            }


            color4  = Color.FromHex(lineColor4);
            series4 = MarketData.GetBars(timeframe4);
            ma4     = Indicators.MovingAverage(series4.ClosePrices, Period4, MAType4);
            val4    = ma4.Result.LastValue;
            if (Visibility4 == true)
            {
                Chart.DrawTrendLine("Extension4", series4.OpenTimes.LastValue, val4, MarketData.GetBars(TimeFrame.Minute).OpenTimes.LastValue, val4, color4, Thickness4, LineStyle4);
            }
        }
Ejemplo n.º 8
0
        private void processSymbol(string symbolName)
        {
            Print("Processing symbol: {0}", symbolName);
            var symbolSeries = MarketData.GetBars(TimeFrame.Hour, symbolName).ClosePrices;


            var signals = Indicators.MacdCrossOver(symbolSeries, 26, 12, 9).Signal;
            var macd    = Indicators.MacdCrossOver(symbolSeries, 26, 12, 9).MACD;

            var macdHasCrossedAboveSignal = macd.HasCrossedAbove(signals, 1);
            var macdHasCrossedBelowSignal = macd.HasCrossedBelow(signals, 1);


            var ma50  = Indicators.SimpleMovingAverage(symbolSeries, 50).Result;
            var ma100 = Indicators.SimpleMovingAverage(symbolSeries, 100).Result;

            var isBearish = false;
            var isBullish = false;

            if (ma50.Last(0) > ma100.Last(0) && ma50.Last(1) > ma100.Last(1))
            {
                isBullish = true;
            }
            if (ma50.Last(0) < ma100.Last(0) && ma50.Last(1) < ma100.Last(1))
            {
                isBearish = true;
            }

            Print("Bearish: {0}, Bullish: {1}, CrossedAboveSignal: {2},CrossedBelowSignal: {3} {4}", isBearish, isBullish, macdHasCrossedAboveSignal, macdHasCrossedBelowSignal, symbolName);

            if (isBearish && macdHasCrossedBelowSignal)
            {
                message += symbolName + " : " + "SELL" + "\n\n";
            }
            if (isBullish && macdHasCrossedAboveSignal)
            {
                message += symbolName + " : " + "BUY" + "\n\n";
            }
        }
Ejemplo n.º 9
0
        private string checkForPullBack(Position pos)
        {
            Print("Checking pull back for symbol: {0}", pos.SymbolName);
            var symbolSeries = MarketData.GetBars(TimeFrame.Hour, pos.SymbolName).ClosePrices;


            var signals = Indicators.MacdCrossOver(symbolSeries, 26, 12, 9).Signal;
            var macd    = Indicators.MacdCrossOver(symbolSeries, 26, 12, 9).MACD;

            var macdHasCrossedAboveSignal = macd.HasCrossedAbove(signals, 0);
            var macdHasCrossedBelowSignal = macd.HasCrossedBelow(signals, 0);

            if (pos.TradeType == TradeType.Buy && macdHasCrossedBelowSignal)
            {
                return("WARNING!!");
            }
            if (pos.TradeType == TradeType.Sell && macdHasCrossedAboveSignal)
            {
                return("WARNING!!");
            }

            return(null);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Parto dalle ultime candele personalizzate e le disegno ogni volta
        /// </summary>
        /// <param name="index"></param>
        private void _drawLevelFromCustomBar()
        {
            // --> Prelevo le candele daily
            Bars BarsCustom = MarketData.GetBars(CandleTimeFrame);

            int index = BarsCustom.Count - 1;

            // --> Potrei non avere un numero sufficiente di candele
            if (index < CandleShow || index < 1)
            {
                return;
            }

            // --> eseguo un ciclo aretroso per disegnare le ultime candele
            for (int i = 0; i < CandleShow; i++)
            {
                // --> Il numero di candele da visualizzare potrebbero essere troppe
                try
                {
                    // --> TimeSpan DiffTime = BarsCustom[index - i].OpenTime.Subtract(BarsCustom[(index - i) - 1].OpenTime); // <-- Strategia da valutare

                    DateTime thisCandle = BarsCustom[index - i].OpenTime;
                    DateTime nextCandle = (i == 0) ? thisCandle.AddMinutes(_getTimeFrameCandleInMinutes(CandleTimeFrame)) : BarsCustom[index - i + 1].OpenTime;

                    string rangeFlag  = thisCandle.ToString();
                    string RangeColor = (BarsCustom[index - i].Close > BarsCustom[index - i].Open) ? ColorHigh : ColorLow;

                    switch (MyCandleMode)
                    {
                    case CandleMode.HighLow:

                        if (Boxed)
                        {
                            ChartRectangle MyBox = Chart.DrawRectangle("HighLow" + rangeFlag, thisCandle, BarsCustom[index - i].High, nextCandle, BarsCustom[index - i].Low, Color.FromArgb(Opacity, Color.FromName(RangeColor)), TicknessBox, LineStyleBox);

                            MyBox.IsFilled = FillBox;
                        }
                        else
                        {
                            Chart.DrawTrendLine("High" + rangeFlag, thisCandle, BarsCustom[index - i].High, nextCandle, BarsCustom[index - i].High, Color.FromName(ColorHigh), TicknessBox, LineStyleBox);
                            Chart.DrawTrendLine("Low" + rangeFlag, thisCandle, BarsCustom[index - i].Low, nextCandle, BarsCustom[index - i].Low, Color.FromName(ColorLow), TicknessBox, LineStyleBox);
                        }

                        break;

                    case CandleMode.OpenClose:

                        if (Boxed)
                        {
                            ChartRectangle MyBox = Chart.DrawRectangle("OpenClose" + rangeFlag, thisCandle, BarsCustom[index - i].Open, nextCandle, BarsCustom[index - i].Close, Color.FromArgb(Opacity, Color.FromName(RangeColor)), TicknessBox, LineStyleBox);

                            MyBox.IsFilled = FillBox;
                        }
                        else
                        {
                            Chart.DrawTrendLine("Open" + rangeFlag, thisCandle, BarsCustom[index - i].Open, nextCandle, BarsCustom[index - i].Open, Color.FromName(ColorHigh), TicknessBox, LineStyleBox);
                            Chart.DrawTrendLine("Close" + rangeFlag, thisCandle, BarsCustom[index - i].Close, nextCandle, BarsCustom[index - i].Close, Color.FromName(ColorLow), TicknessBox, LineStyleBox);
                        }

                        break;
                    }
                } catch
                {
                }
            }
        }
Ejemplo n.º 11
0
        private void SetValue(IndicatorDataSeries View, int index, string CROSSSymbol, string[] cross)
        {
            double crosspips = 0.0;

            // --> Devo fare un ciclio per valutare i cross

            foreach (string onecross in cross)
            {
                try
                {
                    double opendayprice = GetOpenDayPrice(onecross);

                    Symbol tmpcross = Symbols.GetSymbol(onecross);

                    Bars tmpcrosssr = MarketData.GetBars(TimeFrame, tmpcross.Name);

                    int index2 = tmpcrosssr.OpenTimes.GetIndexByExactTime(Bars.OpenTimes[index]);

                    if (tmpcrosssr.OpenTimes[index2].Hour == EndOfDay && tmpcrosssr.OpenTimes[index2].Minute >= 0 && tmpcrosssr.OpenTimes[index2].Minute <= 1)
                    {
                        SetOpenDayPrice(onecross, tmpcrosssr.OpenPrices[index2]);
                        opendayprice = tmpcrosssr.OpenPrices[index2];
                    }

                    if (opendayprice == -1)
                    {
                        havecurr = 1;
                        return;
                    }

                    double tmpcrosspips = 0.0;

                    if (onecross.IndexOf(CROSSSymbol) == 0)
                    {
                        if (tmpcrosssr.ClosePrices[index2] > opendayprice)
                        {
                            tmpcrosspips = (tmpcrosssr.ClosePrices[index2] - opendayprice) / tmpcross.PipSize;
                            crosspips   += tmpcrosspips;
                        }
                        else if (opendayprice > tmpcrosssr.ClosePrices[index2])
                        {
                            tmpcrosspips = (opendayprice - tmpcrosssr.ClosePrices[index2]) / tmpcross.PipSize;
                            crosspips   -= tmpcrosspips;
                        }
                    }
                    else if (onecross.IndexOf(CROSSSymbol) > 0)
                    {
                        if (tmpcrosssr.ClosePrices[index2] > opendayprice)
                        {
                            tmpcrosspips = (tmpcrosssr.ClosePrices[index2] - opendayprice) / tmpcross.PipSize;
                            crosspips   -= tmpcrosspips;
                        }
                        else if (opendayprice > tmpcrosssr.ClosePrices[index2])
                        {
                            tmpcrosspips = (opendayprice - tmpcrosssr.ClosePrices[index2]) / tmpcross.PipSize;
                            crosspips   += tmpcrosspips;
                        }
                    }
                    else
                    {
                        Print(string.Format("Error : {0} not exist", CROSSSymbol));
                    }
                } catch (Exception)
                {
                    //Print(string.Format("Errore : {0}", exc.Message));
                }
            }

            View[index] = crosspips;
            havecurr    = 1;

            DrawLabel(CROSSSymbol, View[index]);
        }
Ejemplo n.º 12
0
        public override void Calculate(int index)
        {
            DateTime open = MarketData.GetBars(Chart.TimeFrame).OpenTimes.LastValue;

            open = open.AddSeconds(-open.Second);
            open = open.AddMilliseconds(-open.Millisecond);

            DateTime now = Server.TimeInUtc;

            now = now.AddSeconds(-now.Second);
            now = now.AddMilliseconds(-now.Millisecond);

            int res = DateTime.Compare(open, now);

            if (res == 0)
            {
                Chart.RemoveObject("Extension1");
                Chart.RemoveObject("Extension2");
                Chart.RemoveObject("Extension3");
                Chart.RemoveObject("Extension4");
                if (Visibility1 == true)
                {
                    series1 = MarketData.GetBars(timeframe1);
                    ma1     = Indicators.MovingAverage(series1.ClosePrices, Period1, MAType1);
                    Chart.DrawTrendLine("Extension1", series1.OpenTimes.LastValue, val1, MarketData.GetBars(TimeFrame.Minute).OpenTimes.LastValue, val1, color1, Thickness1, LineStyle1);

                    DateTime now1 = Server.TimeInUtc;
                    now1 = now1.AddSeconds(-now1.Second);
                    now1 = now1.AddMilliseconds(-now1.Millisecond);

                    DateTime open1 = series1.OpenTimes.LastValue;
                    open1 = open1.AddSeconds(-open1.Second);
                    open1 = open1.AddMilliseconds(-open1.Millisecond);

                    int res1 = DateTime.Compare(open1, now1);

                    if (res1 == 0)
                    {
                        val1 = ma1.Result.LastValue;
                    }
                }

                if (Visibility2 == true)
                {
                    series2 = MarketData.GetBars(timeframe2);
                    ma2     = Indicators.MovingAverage(series2.ClosePrices, Period2, MAType2);
                    Chart.DrawTrendLine("Extension2", series2.OpenTimes.LastValue, val2, MarketData.GetBars(TimeFrame.Minute).OpenTimes.LastValue, val2, color2, Thickness2, LineStyle2);

                    DateTime now2 = Server.TimeInUtc;
                    now2 = now2.AddSeconds(-now2.Second);
                    now2 = now2.AddMilliseconds(-now2.Millisecond);

                    DateTime open2 = series2.OpenTimes.LastValue;
                    open2 = open2.AddSeconds(-open2.Second);
                    open2 = open2.AddMilliseconds(-open2.Millisecond);

                    int res2 = DateTime.Compare(open2, now2);

                    if (res2 == 0)
                    {
                        val2 = ma2.Result.LastValue;
                    }
                }

                if (Visibility3 == true)
                {
                    series3 = MarketData.GetBars(timeframe3);
                    ma3     = Indicators.MovingAverage(series3.ClosePrices, Period3, MAType3);
                    Chart.DrawTrendLine("Extension3", series3.OpenTimes.LastValue, val3, MarketData.GetBars(TimeFrame.Minute).OpenTimes.LastValue, val3, color3, Thickness3, LineStyle3);

                    DateTime now3 = Server.TimeInUtc;
                    now3 = now3.AddSeconds(-now3.Second);
                    now3 = now3.AddMilliseconds(-now3.Millisecond);

                    DateTime open3 = series3.OpenTimes.LastValue;
                    open3 = open3.AddSeconds(-open3.Second);
                    open3 = open3.AddMilliseconds(-open3.Millisecond);

                    int res3 = DateTime.Compare(open3, now3);

                    if (res3 == 0)
                    {
                        val3 = ma3.Result.LastValue;
                    }
                }

                if (Visibility4 == true)
                {
                    series4 = MarketData.GetBars(timeframe4);
                    ma4     = Indicators.MovingAverage(series4.ClosePrices, Period4, MAType4);
                    Chart.DrawTrendLine("Extension4", series4.OpenTimes.LastValue, val4, MarketData.GetBars(TimeFrame.Minute).OpenTimes.LastValue, val4, color4, Thickness4, LineStyle4);

                    DateTime now4 = Server.TimeInUtc;
                    now4 = now4.AddSeconds(-now4.Second);
                    now4 = now4.AddMilliseconds(-now4.Millisecond);

                    DateTime open4 = series4.OpenTimes.LastValue;
                    open4 = open4.AddSeconds(-open4.Second);
                    open4 = open4.AddMilliseconds(-open4.Millisecond);

                    int res4 = DateTime.Compare(open4, now4);

                    if (res4 == 0)
                    {
                        val4 = ma4.Result.LastValue;
                    }
                }
            }

            var index1 = GetIndexByDate(series1, Bars.OpenTimes[index]);

            if (index1 != -1)
            {
                MA1[index] = ma1.Result[index1];
            }

            var index2 = GetIndexByDate(series2, Bars.OpenTimes[index]);

            if (index2 != -1)
            {
                MA2[index] = ma2.Result[index2];
            }

            var index3 = GetIndexByDate(series3, Bars.OpenTimes[index]);

            if (index3 != -1)
            {
                MA3[index] = ma3.Result[index3];
            }

            var index4 = GetIndexByDate(series4, Bars.OpenTimes[index]);

            if (index4 != -1)
            {
                MA4[index] = ma4.Result[index4];
            }
        }
        private void _drawLevelFromCustomBar()
        {
            // --> Prelevo le candele scelte
            Bars BarsCustom = MarketData.GetBars(PivotTimeFrame);

            int index = BarsCustom.Count - 1;

            // --> Potrei non avere un numero sufficiente di candele
            if (index < 1 || (BarsCustom[index].Close == BarsCustom[index].Open))
            {
                return;
            }



            try
            {
                // --> TimeSpan DiffTime = BarsCustom[index - i].OpenTime.Subtract(BarsCustom[(index - i) - 1].OpenTime); // <-- Strategia da valutare

                DateTime thisCandle = BarsCustom[index].OpenTime;
                DateTime nextCandle = thisCandle.AddMinutes(_getTimeFrameCandleInMinutes(PivotTimeFrame));

                double high  = BarsCustom[index - 1].High;
                double low   = BarsCustom[index - 1].Low;
                double close = BarsCustom[index - 1].Close;

                double pivot = (high + low + close) / 3;

                double r1 = pivot + (Fibo1 * (high - low));
                double s1 = pivot - (Fibo1 * (high - low));

                double r2 = pivot + (Fibo2 * (high - low));
                double s2 = pivot - (Fibo2 * (high - low));

                double r3 = pivot + (Fibo3 * (high - low));
                double s3 = pivot - (Fibo3 * (high - low));

                Chart.DrawTrendLine("pivot ", thisCandle, pivot, nextCandle, pivot, Color.FromName(PivotColor.ToString("G")), 1, LineStyle.DotsVeryRare);
                Chart.DrawTrendLine("r1 ", thisCandle, r1, nextCandle, r1, Color.FromName(ResistanceColor.ToString("G")), 1, LineStyle.DotsRare);
                Chart.DrawTrendLine("r2 ", thisCandle, r2, nextCandle, r2, Color.FromName(ResistanceColor.ToString("G")), 1, LineStyle.Lines);
                Chart.DrawTrendLine("r3 ", thisCandle, r3, nextCandle, r3, Color.FromName(ResistanceColor.ToString("G")), 1, LineStyle.Solid);
                Chart.DrawTrendLine("s1 ", thisCandle, s1, nextCandle, s1, Color.FromName(SupportColor.ToString("G")), 1, LineStyle.DotsRare);
                Chart.DrawTrendLine("s2 ", thisCandle, s2, nextCandle, s2, Color.FromName(SupportColor.ToString("G")), 1, LineStyle.Lines);
                Chart.DrawTrendLine("s3 ", thisCandle, s3, nextCandle, s3, Color.FromName(SupportColor.ToString("G")), 1, LineStyle.Solid);

                if (!ShowLabels)
                {
                    return;
                }

                Chart.DrawText("Lpivot ", "P", nextCandle, pivot, Color.FromName(PivotColor.ToString("G"))).VerticalAlignment = VerticalAlignment.Center;
                Chart.DrawText("Lr1 ", "R1", nextCandle, r1, Color.FromName(ResistanceColor.ToString("G"))).VerticalAlignment = VerticalAlignment.Center;
                Chart.DrawText("Lr2 ", "R2", nextCandle, r2, Color.FromName(ResistanceColor.ToString("G"))).VerticalAlignment = VerticalAlignment.Center;
                Chart.DrawText("Lr3 ", "R3", nextCandle, r3, Color.FromName(ResistanceColor.ToString("G"))).VerticalAlignment = VerticalAlignment.Center;
                Chart.DrawText("Ls1 ", "S1", nextCandle, s1, Color.FromName(SupportColor.ToString("G"))).VerticalAlignment    = VerticalAlignment.Center;
                Chart.DrawText("Ls2 ", "S2", nextCandle, s2, Color.FromName(SupportColor.ToString("G"))).VerticalAlignment    = VerticalAlignment.Center;
                Chart.DrawText("Ls3 ", "S3", nextCandle, s3, Color.FromName(SupportColor.ToString("G"))).VerticalAlignment    = VerticalAlignment.Center;
            }
            catch
            {
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Parto dalle ultime candele personalizzate e le disegno ogni volta
        /// </summary>
        /// <param name="index"></param>
        private void _drawPivot()
        {
            // --> Prelevo le candele di riferimento
            Bars barsCustom  = MarketData.GetBars(CandleTimeFrame);
            int  minimumBars = 3;

            int index = barsCustom.Count - 1;

            // --> Potrei non avere un numero sufficiente di candele
            if (index < CandleShow || index < minimumBars)
            {
                return;
            }

            // --> eseguo un ciclo aretroso per disegnare le ultime candele
            for (int i = 0; i < CandleShow; i++)
            {
                // --> Il numero di candele da visualizzare potrebbero essere troppe
                try
                {
                    DateTime thisCandle = barsCustom[index - i].OpenTime;
                    DateTime nextCandle = (i == 0) ? thisCandle.AddMinutes(_getTimeFrameCandleInMinutes(CandleTimeFrame)) : barsCustom[index - i + 1].OpenTime;

                    // --> Prelevo il range della candela precedente, su di esso costruisco il pivot
                    double pivotRange = Math.Round(barsCustom[index - i - 1].High - barsCustom[index - i - 1].Low, Symbol.Digits);

                    // --> Devo sapere se bullish o bearish, bullish se flat
                    bool lastIsBearish = barsCustom[index - i - 1].Close < barsCustom[index - i - 1].Open;

                    double pivot618 = Math.Round((pivotRange / 100) * 61.8, Symbol.Digits);

                    double goldPivot         = (lastIsBearish) ? barsCustom[index - i - 1].Low + pivot618 : barsCustom[index - i - 1].High - pivot618;
                    double lastLevel         = (lastIsBearish) ? barsCustom[index - i - 1].Low + pivotRange : barsCustom[index - i - 1].High - pivotRange;
                    double oppositeLastLevel = (!lastIsBearish) ? barsCustom[index - i - 1].Low + pivotRange : barsCustom[index - i - 1].High - pivotRange;

                    string rangeFlag              = thisCandle.ToString();
                    string lastLevelColor         = (lastLevel < goldPivot) ? ColorBear : ColorBull;
                    string oppositeLastLevelColor = (oppositeLastLevel < goldPivot) ? ColorBear : ColorBull;

                    if (_canDraw())
                    {
                        Chart.DrawTrendLine("GoldPivot" + rangeFlag, thisCandle, goldPivot, nextCandle, goldPivot, Color.FromName(ColorPivot), TicknessBox, LineStyleBox);
                        Chart.DrawTrendLine("LastLevel" + rangeFlag, thisCandle, lastLevel, nextCandle, lastLevel, Color.FromName(lastLevelColor), TicknessBox, LineStyleBox);
                        Chart.DrawTrendLine("OppositeLastLevel" + rangeFlag, thisCandle, oppositeLastLevel, nextCandle, oppositeLastLevel, Color.FromName(oppositeLastLevelColor), TicknessBox, LineStyleBox);

                        if (ShowLabel && i == 0)
                        {
                            double bullishLevel = (lastLevel > oppositeLastLevel) ? lastLevel : oppositeLastLevel;
                            double bearishLevel = (lastLevel < oppositeLastLevel) ? lastLevel : oppositeLastLevel;

                            double midBuyDistance  = (bullishLevel - goldPivot) / 2;
                            double midSellDistance = (goldPivot - bearishLevel) / 2;

                            Chart.DrawText("BuyZone", string.Format("Buy Zone ( {0} )", CandleTimeFrame), nextCandle, goldPivot + midBuyDistance, Color.FromName(ColorBull));
                            Chart.DrawText("SellZone", string.Format("Sell Zone ( {0} )", CandleTimeFrame), nextCandle, goldPivot - midSellDistance, Color.FromName(ColorBear));

                            Chart.DrawText("Bullish", string.Format("Bullish ( {0} {1} )", bullishLevel, CandleTimeFrame), nextCandle, bullishLevel, Color.FromName(ColorBull));
                            Chart.DrawText("Bearish", string.Format("Bearish ( {0} {1} )", bearishLevel, CandleTimeFrame), nextCandle, bearishLevel, Color.FromName(ColorBear));
                            Chart.DrawText("Pivot", string.Format("Pivot ( {0} {1} )", goldPivot, CandleTimeFrame), nextCandle, goldPivot, Color.FromName(ColorPivot));
                        }
                    }
                }
                catch
                {
                }
            }
        }