Example #1
0
        protected override void NewBar()
        {
            _frInd.ReInit();

            DTime = Bars[Bars.Range.To - 1].Time;
            ci    = Bars.Range.To - 1;
            TrailActiveOrders();
//=========  Рисуем линию  начала торгов Европы =============================================================================
            if (DTime.Hour == 7 && DTime.Minute == 00)
            {
                var vl1 = Tools.Create <VerticalLine>(); vl1.Time = Bars[Bars.Range.To - 1].Time; vl1.Color = Color.Aqua; vl1.Width = 2;
            }

            if (DTime.Hour < 6)
            {
                torg7 = false; torg12 = false;
            }

//====  Fractal ====================================================================================
            if (_frInd.TopSeries[Bars.Range.To - 5] > 0)
            {
                frUp = Bars[Bars.Range.To - 5].High; FU3 = FU2; FU2 = FU1; FU1 = frUp;
            }
            if (_frInd.BottomSeries[Bars.Range.To - 5] > 0)
            {
                frDown = Bars[Bars.Range.To - 5].Low; FD3 = FD2; FD2 = FD1; FD1 = frDown;
            }
//=== КОРЕКЦИЯ ===========================================================================================================
            if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Closed)
            {
                posGuidBuy = Guid.Empty;
            }
            if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Closed)
            {
                posGuidSell = Guid.Empty;                                                                                                         // Event occurs on every new bar
            }
//=== Запрет повторных операций ===========================================================================================
            if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Active)
            {
                torg7 = false; torg12 = false;
            }
            if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Active)
            {
                torg7 = false;  torg12 = false;
            }                                                                                                                                            // Event occurs on every new bar
//=== КОРЕКЦИЯ ===========================================================================================================
            if (DTime.Hour == 7 && DTime.Minute == 00)
            {
                torg7 = true; Print("===================     6:45 ==============================");
            }
            if (DTime.Hour == 11 && DTime.Minute == 55)
            {
                torg12 = true;       Print("===================     11:55 ============================");
            }

            if (DTime.Hour == 11 && DTime.Minute == 40)
            {
                Print("===================     11:40 ==============================");
                torg7 = false;
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Active)
                {
                    var res = Trade.CloseMarketPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Active)
                {
                    var res = Trade.CloseMarketPosition(posGuidBuy); if (res.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }

                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                {
                    var res = Trade.CancelPendingPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending)
                {
                    var res = Trade.CancelPendingPosition(posGuidBuy); if (res.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
            }
            if (DTime.Hour == 17 && DTime.Minute == 45)
            {
                Print("===================     17:45 ==============================");
                torg12 = false;
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Active)
                {
                    var res = Trade.CloseMarketPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Active)
                {
                    var res = Trade.CloseMarketPosition(posGuidBuy); if (res.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }

                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                {
                    var res = Trade.CancelPendingPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending)
                {
                    var res = Trade.CancelPendingPosition(posGuidBuy); if (res.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
            }

            //=== PARABOLIC ===========================================================================================================
            if (torg7)
            {
                // Parabolic выше цены
                if (posGuidSell == Guid.Empty)
                {
                    if (posGuidBuy == Guid.Empty)
                    {
                        var result1 = Trade.OpenPendingPosition(Instrument.Id,
                                                                ExecutionRule.BuyStop, 0.1, pr1, 0, Stops.InPips(SL1, null), null, null, null);
                        if (result1.IsSuccessful)
                        {
                            posGuidBuy = result1.Position.Id;
                        }
                    }
                    if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending)
                    {
                        SL2 = Math.Round(pr1 - SL1 * Instrument.Point, Instrument.PriceScale);
                        var result = Trade.UpdatePendingPosition(posGuidBuy, 0.1, pr1, SL2, null);
                        if (result.IsSuccessful)
                        {
                            posGuidBuy = result.Position.Id;
                        }
                    }
                }
                // Parabolic Ниже цены
                if (posGuidBuy == Guid.Empty)
                {
                    if (posGuidSell == Guid.Empty)
                    {
                        var result1 = Trade.OpenPendingPosition(Instrument.Id,
                                                                ExecutionRule.SellStop, 0.1, pr1, 0, Stops.InPips(SL1, null), null, null, null);
                        if (result1.IsSuccessful)
                        {
                            posGuidSell = result1.Position.Id;
                        }
                    }
                    if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                    {
                        SL2 = Math.Round(pr1 + SL1 * Instrument.Point, Instrument.PriceScale);
                        var result = Trade.UpdatePendingPosition(posGuidSell, 0.1, pr1, SL2, null);
                        if (result.IsSuccessful)
                        {
                            posGuidSell = result.Position.Id;
                        }
                    }
                }
            }
//=== PARABOLIC ===========================================================================================================
//=== PARABOLIC ===========================================================================================================
            if (torg12)
            {
                // Parabolic выше цены
                if (Bars[Bars.Range.To - 1].High < pr1 && posGuidSell == Guid.Empty)
                {
                    if (posGuidBuy == Guid.Empty)
                    {
                        var result1 = Trade.OpenPendingPosition(Instrument.Id,
                                                                ExecutionRule.BuyStop, 0.1, pr1, 0, Stops.InPips(SL1, null), null, null, null);
                        if (result1.IsSuccessful)
                        {
                            posGuidBuy = result1.Position.Id;
                        }
                    }
                    if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending)
                    {
                        SL2 = Math.Round(pr1 - SL1 * Instrument.Point, Instrument.PriceScale);
                        var result = Trade.UpdatePendingPosition(posGuidBuy, 0.1, pr1, SL2, null);
                        if (result.IsSuccessful)
                        {
                            posGuidBuy = result.Position.Id;
                        }
                    }
                }
                // Parabolic Ниже цены
                if (Bars[Bars.Range.To - 1].Low > pr1 && posGuidBuy == Guid.Empty)
                {
                    if (posGuidSell == Guid.Empty)
                    {
                        var result1 = Trade.OpenPendingPosition(Instrument.Id,
                                                                ExecutionRule.SellStop, 0.1, pr1, 0, Stops.InPips(SL1, null), null, null, null);
                        if (result1.IsSuccessful)
                        {
                            posGuidSell = result1.Position.Id;
                        }
                    }
                    if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                    {
                        SL2 = Math.Round(pr1 + SL1 * Instrument.Point, Instrument.PriceScale);
                        var result = Trade.UpdatePendingPosition(posGuidSell, 0.1, pr1, SL2, null);
                        if (result.IsSuccessful)
                        {
                            posGuidSell = result.Position.Id;
                        }
                    }
                }
            }
            if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).Pips > 50)
            {
                tr = true;
            }
            if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).Pips > 50)
            {
                tr = true;
            }
            if (tr)
            {
                TrailActiveOrders();
            }
        }
Example #2
0
        protected override void NewBar()
        {
            _frInd.ReInit();
            DTime = Bars[Bars.Range.To - 1].Time;
            ci    = Bars.Range.To - 1;


//====== ВВЕРХУ ПИК =====================================================================================================================
            if (_frInd.TopSeries[Bars.Range.To - 5] > 0 && Up)
            {                     // ВВЕРХУ
                Up  = false;
                m9  = m8; m8 = m7; m7 = m6; m6 = m5; m5 = m4; m4 = m3; m3 = m2; m2 = m1; m1 = _frInd.TopSeries[Bars.Range.To - 5];
                mt8 = mt7; mt7 = mt6; mt6 = mt5; mt5 = mt4; mt4 = mt3; mt3 = mt2; mt2 = mt1; mt1 = Bars[Bars.Range.To - 5].Time;
            }
//==== ВНИЗУ ПИК ======================================================================================================================
            if (_frInd.BottomSeries[Bars.Range.To - 5] > 0 && !Up)
            {                     // ВНИЗУ
                Up  = true;
                m9  = m8; m8 = m7; m7 = m6; m6 = m5; m5 = m4; m4 = m3; m3 = m2; m2 = m1; m1 = _frInd.BottomSeries[Bars.Range.To - 5];
                mt8 = mt7; mt7 = mt6; mt6 = mt5; mt5 = mt4; mt4 = mt3; mt3 = mt2; mt2 = mt1; mt1 = Bars[Bars.Range.To - 5].Time;
            }

//===================================================================================================================================
            //  Патерн 5-0
            if ((m4 - m3) / (m4 - m5) >= 0.13 && (m4 - m3) / (m4 - m5) <= 0.618 &&
                (m2 - m3) / (m4 - m3) >= 1.618 && (m2 - m3) / (m4 - m3) >= 2.24 &&
                (m2 - m1) / (m2 - m3) >= 0.5 && (m2 - m1) / (m2 - m3) >= 0.886 && fst != m1)
            {
                Print("Патерн 5-0 - {0} - {1}", DTime, Instrument.Name); fst = m1;
                var toolPolyLine = Tools.Create <PolyLine>();
                toolPolyLine.Color = Color.Red;
                toolPolyLine.Width = 4;
                toolPolyLine.AddPoint(new ChartPoint(DTime, Bars[Bars.Range.To - 1].Close));
                toolPolyLine.AddPoint(new ChartPoint(mt1, m1));
                toolPolyLine.AddPoint(new ChartPoint(mt2, m2));
                toolPolyLine.AddPoint(new ChartPoint(mt3, m3));
                toolPolyLine.AddPoint(new ChartPoint(mt4, m4));
                toolPolyLine.AddPoint(new ChartPoint(mt5, m5));
                toolPolyLine.AddPoint(new ChartPoint(mt6, m6));
                var toolText = Tools.Create <Text>(); toolText.Color = Color.White;        toolText.FontSize = 14; toolText.Point = new ChartPoint(DTime, Bars[Bars.Range.To - 1].High);
                toolText.Caption = "Патерн 5-0 ";
                //var vline = Tools.Create<VerticalLine>(); vline.Color=Color.Red; vline.Time=DTime;
            }
            //  Летучая мышь №2 :
            if ((m4 - m3) / (m4 - m5) >= 0.382 && (m4 - m3) / (m4 - m5) <= 0.5 &&
                (m4 - m3) / (m2 - m3) >= 0.382 && (m4 - m3) / (m2 - m3) >= 0.886 &&
                (m2 - m1) / (m2 - m3) >= 2.0 && (m2 - m1) / (m2 - m3) >= 3.618 &&
                (m4 - m1) / (m4 - m5) >= 1.13 && fst != m1)
            {
                Print("Летучая мышь №2 - {0} - {1}", DTime, Instrument.Name); fst = m1;
                var toolPolyLine = Tools.Create <PolyLine>();
                toolPolyLine.Color = Color.Blue;
                toolPolyLine.Width = 4;
                toolPolyLine.AddPoint(new ChartPoint(DTime, Bars[Bars.Range.To - 1].Close));
                toolPolyLine.AddPoint(new ChartPoint(mt1, m1));
                toolPolyLine.AddPoint(new ChartPoint(mt2, m2));
                toolPolyLine.AddPoint(new ChartPoint(mt3, m3));
                toolPolyLine.AddPoint(new ChartPoint(mt4, m4));
                toolPolyLine.AddPoint(new ChartPoint(mt5, m5));
                toolPolyLine.AddPoint(new ChartPoint(mt6, m6));
                var toolText = Tools.Create <Text>(); toolText.Color = Color.White;        toolText.FontSize = 14; toolText.Point = new ChartPoint(DTime, Bars[Bars.Range.To - 1].High);
                toolText.Caption = "Летучая мышь №2 ";
                //var vline = Tools.Create<VerticalLine>(); vline.Color=Color.Red; vline.Time=DTime;
            }
            //  Глубокий краб:
            if ((m4 - m3) / (m4 - m5) >= 0.382 && (m4 - m3) / (m4 - m5) <= 0.886 &&
                (m4 - m3) / (m2 - m3) >= 0.382 && (m4 - m3) / (m2 - m3) >= 0.886 &&
                (m2 - m1) / (m2 - m3) >= 2.240 && (m2 - m1) / (m2 - m3) >= 3.618 &&
                (m4 - m1) / (m4 - m5) >= 1.618 && fst != m1)
            {
                Print("Глубокий краб: - {0} - {1}", DTime, Instrument.Name); fst = m1;
                var toolPolyLine = Tools.Create <PolyLine>();
                toolPolyLine.Color = Color.SeaGreen;
                toolPolyLine.Width = 4;
                toolPolyLine.AddPoint(new ChartPoint(DTime, Bars[Bars.Range.To - 1].Close));
                toolPolyLine.AddPoint(new ChartPoint(mt1, m1));
                toolPolyLine.AddPoint(new ChartPoint(mt2, m2));
                toolPolyLine.AddPoint(new ChartPoint(mt3, m3));
                toolPolyLine.AddPoint(new ChartPoint(mt4, m4));
                toolPolyLine.AddPoint(new ChartPoint(mt5, m5));
                toolPolyLine.AddPoint(new ChartPoint(mt6, m6));
                var toolText = Tools.Create <Text>(); toolText.Color = Color.SeaGreen;     toolText.FontSize = 14; toolText.Point = new ChartPoint(DTime, Bars[Bars.Range.To - 1].High);
                toolText.Caption = "Глубокий краб";
                //var vline = Tools.Create<VerticalLine>(); vline.Color=Color.Red; vline.Time=DTime;
            }

            // Идеальный краб :
            if ((m4 - m3) / (m4 - m5) >= 0.618 && (m4 - m3) / (m4 - m5) <= 0.886 &&
                (m4 - m3) / (m2 - m3) >= 0.500 && (m4 - m3) / (m2 - m3) >= 0.618 &&
                (m2 - m1) / (m2 - m3) >= 2.00 && (m2 - m1) / (m2 - m3) >= 3.140 &&
                (m4 - m1) / (m4 - m5) >= 1.618 && fst != m1)
            {
                Print("Идеальный краб : - {0} - {1}", DTime, Instrument.Name); fst = m1;
                var toolPolyLine = Tools.Create <PolyLine>();
                toolPolyLine.Color = Color.Yellow;
                toolPolyLine.Width = 4;
                toolPolyLine.AddPoint(new ChartPoint(DTime, Bars[Bars.Range.To - 1].Close));
                toolPolyLine.AddPoint(new ChartPoint(mt1, m1));
                toolPolyLine.AddPoint(new ChartPoint(mt2, m2));
                toolPolyLine.AddPoint(new ChartPoint(mt3, m3));
                toolPolyLine.AddPoint(new ChartPoint(mt4, m4));
                toolPolyLine.AddPoint(new ChartPoint(mt5, m5));
                toolPolyLine.AddPoint(new ChartPoint(mt6, m6));
                var toolText = Tools.Create <Text>(); toolText.Color = Color.Yellow;       toolText.FontSize = 14; toolText.Point = new ChartPoint(DTime, Bars[Bars.Range.To - 1].High);
                toolText.Caption = "Идеальный краб";
                //var vline = Tools.Create<VerticalLine>(); vline.Color=Color.Red; vline.Time=DTime;
            }
            // Бабочка Гартли
            if ((m4 - m3) / (m4 - m5) >= 0.618 && (m4 - m3) / (m4 - m5) <= 0.886 &&
                (m4 - m3) / (m2 - m3) >= 0.382 && (m4 - m3) / (m2 - m3) >= 0.886 &&
                (m2 - m1) / (m2 - m3) >= 1.270 && (m2 - m1) / (m2 - m3) >= 1.618 &&
                (m4 - m1) / (m4 - m5) >= 0.786 && fst != m1)
            {
                Print("Бабочка Гартли: - {0} - {1}", DTime, Instrument.Name); fst = m1;
                var toolPolyLine = Tools.Create <PolyLine>();
                toolPolyLine.Color = Color.Violet;
                toolPolyLine.Width = 4;
                toolPolyLine.AddPoint(new ChartPoint(DTime, Bars[Bars.Range.To - 1].Close));
                toolPolyLine.AddPoint(new ChartPoint(mt1, m1));
                toolPolyLine.AddPoint(new ChartPoint(mt2, m2));
                toolPolyLine.AddPoint(new ChartPoint(mt3, m3));
                toolPolyLine.AddPoint(new ChartPoint(mt4, m4));
                toolPolyLine.AddPoint(new ChartPoint(mt5, m5));
                toolPolyLine.AddPoint(new ChartPoint(mt6, m6));
                var toolText = Tools.Create <Text>(); toolText.Color = Color.Violet;       toolText.FontSize = 14; toolText.Point = new ChartPoint(DTime, Bars[Bars.Range.To - 1].High);
                toolText.Caption = "Бабочка Гартли";
                //var vline = Tools.Create<VerticalLine>(); vline.Color=Color.Red; vline.Time=DTime;
            }
            // Бабочка Песавенто
            if ((m4 - m3) / (m4 - m5) >= 0.786 && (m4 - m3) / (m4 - m5) <= 0.886 &&
                (m4 - m3) / (m2 - m3) >= 0.382 && (m4 - m3) / (m2 - m3) >= 0.886 &&
                (m2 - m1) / (m2 - m3) >= 1.618 && (m2 - m1) / (m2 - m3) >= 2.618 &&
                (m4 - m1) / (m4 - m5) >= 1.270 && (m4 - m1) / (m4 - m5) >= 1.618 && fst != m1)
            {
                Print("Бабочка Песавенто : - {0} - {1}", DTime, Instrument.Name);  fst = m1;
                var toolPolyLine = Tools.Create <PolyLine>();
                toolPolyLine.Color = Color.DeepPink;
                toolPolyLine.Width = 4;
                toolPolyLine.AddPoint(new ChartPoint(DTime, Bars[Bars.Range.To - 1].Close));
                toolPolyLine.AddPoint(new ChartPoint(mt1, m1));
                toolPolyLine.AddPoint(new ChartPoint(mt2, m2));
                toolPolyLine.AddPoint(new ChartPoint(mt3, m3));
                toolPolyLine.AddPoint(new ChartPoint(mt4, m4));
                toolPolyLine.AddPoint(new ChartPoint(mt5, m5));
                toolPolyLine.AddPoint(new ChartPoint(mt6, m6));
                var toolText = Tools.Create <Text>(); toolText.Color = Color.DeepPink;     toolText.FontSize = 14; toolText.Point = new ChartPoint(DTime, Bars[Bars.Range.To - 1].High);
                toolText.Caption = "Бабочка Песавенто";
                //var vline = Tools.Create<VerticalLine>(); vline.Color=Color.Red; vline.Time=DTime;
            }
            // 3 движния
            if ((m1 - m2) / (m3 - m2) >= 1.270 && (m1 - m2) / (m3 - m2) <= 1.618 &&
                (m3 - m4) / (m5 - m4) >= 1.270 && (m3 - m4) / (m5 - m4) <= 1.618 && fst != m1)
            {
                Print("3 движения : - {0} - {1}", DTime, Instrument.Name); fst = m1;
                var toolPolyLine = Tools.Create <PolyLine>();
                toolPolyLine.Color = Color.DarkRed;
                toolPolyLine.Width = 4;
                toolPolyLine.AddPoint(new ChartPoint(DTime, Bars[Bars.Range.To - 1].Close));
                toolPolyLine.AddPoint(new ChartPoint(mt1, m1));
                toolPolyLine.AddPoint(new ChartPoint(mt2, m2));
                toolPolyLine.AddPoint(new ChartPoint(mt3, m3));
                toolPolyLine.AddPoint(new ChartPoint(mt4, m4));
                toolPolyLine.AddPoint(new ChartPoint(mt5, m5));
                toolPolyLine.AddPoint(new ChartPoint(mt6, m6));
                var toolText = Tools.Create <Text>(); toolText.Color = Color.DarkRed;      toolText.FontSize = 14; toolText.Point = new ChartPoint(DTime, Bars[Bars.Range.To - 1].High);
                toolText.Caption = "3 движения :";
                //var vline = Tools.Create<VerticalLine>(); vline.Color=Color.Red; vline.Time=DTime;
            }
        }