예제 #1
0
        protected override void NewBar()
        {
            _wprInd.ReInit();
            ci = Bars.Range.To - 1;
//========== Если появился пик зигзага  ================================================================================================
            if (_wprInd.MainIndicatorSeries[ci] > 0)
            {                // Значения 3 значений - для определения направления
                zz3 = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[ci];
                zi2 = zi1;  zi1 = ci;
                Print("{0} - {1} {2}", Bars[ci].Time, zz1 < zz2, zz3 < zz2);
//======================= ПИК - ВЕШИНА ВВЕРХУ
                if (zz2 < zz3 && zz2 < zz1)
                {
                    zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zz2;
                    zzi5 = zzi4; zzi4 = zzi3; zzi3 = zzi2; zzi2 = zzi1; zzi1 = zi2;
                    var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Red; vr.Time = Bars[zzi1].Time;
                }
                if (zz2 > zz3 && zz2 > zz1)
                {
                    zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zz2;
                    zzi5 = zzi4; zzi4 = zzi3; zzi3 = zzi2; zzi2 = zzi1; zzi1 = zi2;
                    var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Blue; vr.Time = Bars[zzi1].Time;
                }
            }
        }
예제 #2
0
        protected override void NewBar()
        {
            _wprInd.ReInit();

            //Print("{0} - {1}",Bars[Bars.Range.To-1].Time,_ftoInd.FisherSeries[Bars.Range.To-1]);

            if (_frInd.TopSeries[Bars.Range.To - 5] > 0)
            {
                frUp = Bars[Bars.Range.To - 5].High; frUpL = Bars[Bars.Range.To - 5].Low; frUp_Time = Bars[Bars.Range.To - 5].Time;
            }
            if (_frInd.BottomSeries[Bars.Range.To - 5] > 0)
            {
                frDown = Bars[Bars.Range.To - 5].Low; frDownH = Bars[Bars.Range.To - 5].High; frDown_Time = Bars[Bars.Range.To - 5].Time;
            }
            // ВВЕРХ
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] < 0 && _ftoInd.FisherSeries[Bars.Range.To - 1] > 0 && _ftoInd.FisherSeries[Bars.Range.To - 1] - _ftoInd.FisherSeries[Bars.Range.To - 2] > 0.35)
            {
                var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Red; vr.Time = Bars[Bars.Range.To - 1].Time; vr.Width = 3;

                Print("UP {0} - {1} - {2} = {3}", Bars[Bars.Range.To - 1].Time, _ftoInd.FisherSeries[Bars.Range.To - 2], _ftoInd.FisherSeries[Bars.Range.To - 1], _ftoInd.FisherSeries[Bars.Range.To - 1] - _ftoInd.FisherSeries[Bars.Range.To - 2]);
            }
            // ВНИЗ
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] > 0 && _ftoInd.FisherSeries[Bars.Range.To - 1] < 0 && _ftoInd.FisherSeries[Bars.Range.To - 2] - _ftoInd.FisherSeries[Bars.Range.To - 1] > 0.35)
            {
                var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Blue; vr.Time = Bars[Bars.Range.To - 1].Time; vr.Width = 3;
                Print("DOWN {0} - {1} - {2} = {3}", Bars[Bars.Range.To - 1].Time, _ftoInd.FisherSeries[Bars.Range.To - 2], _ftoInd.FisherSeries[Bars.Range.To - 1], _ftoInd.FisherSeries[Bars.Range.To - 2] - _ftoInd.FisherSeries[Bars.Range.To - 1]);
            }
        }
예제 #3
0
//===============================================================================================================================
        protected void Patern123()
        {
            _wprInd.ReInit();
            //Print("Patern123 - Function {0} k={1} ZigZag={2}",Bars[Bars.Range.To-1].Time,k,_wprInd.MainIndicatorSeries[Bars.Range.To-1]);
//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzt3 = zzt2;      zzt2 = zzt1;  zzt1 = Bars.Range.To - 1;
                //Print("Patern123 - Function {0} z1={1} z2={2} z3={3}",Bars[Bars.Range.To-1].Time,zz1,zz2,zz3);
//====== ВВЕРХУ ПИК =====================================================================================================================
                if (zz3 < zz2 && zz2 > zz1)
                {                 // ВВЕРХУ
                    zzi8 = zzi7; zzi7 = zzi6; zzi6 = zzi5; zzi5 = zzi4; zzi4 = zzi3; zzi3 = zzi2; zzi2 = zzi1; zzi1 = zzt2;
                    zzd8 = zzd7; zzd7 = zzd6; zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zz2;
                    //Print("ВВЕРХУ  {0}",Bars[Bars.Range.To].Time);
                    ot = zzd2 + ((zzd3 - zzd2) * 0.5);
                    if (zzd6 > zzd8 && zzd4 > zzd6 && zzd4 > zzd2 && zzd3 > zzd1)              // ВВЕРХУ
                    {
                        Print("BLUE ВВЕРХУ {0} - 1-{1} 2-{2} 3-{3} 4-{4} 5-{5} 6-{6} 7-{7} 8-{8}", Bars[Bars.Range.To].Time, zzd1, zzd2, zzd3, zzd4, zzd5, zzd6, zzd7, zzd8);
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Blue;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi8].Time, zzd8));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi7].Time, zzd7));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi6].Time, zzd6));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi5].Time, zzd5));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi4].Time, zzd4));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi3].Time, zzd3));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi2].Time, zzd2));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi1].Time, zzd1));
                    }
                }
//==== ВНИЗУ ПИК ======================================================================================================================
                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    zzi8 = zzi7; zzi7 = zzi6; zzi6 = zzi5; zzi5 = zzi4; zzi4 = zzi3; zzi3 = zzi2; zzi2 = zzi1; zzi1 = zzt2;
                    zzd8 = zzd7; zzd7 = zzd6; zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zz2;
                    //Print("ВНИЗУ {0}",Bars[Bars.Range.To].Time);
                    ot = zzd2 - ((zzd2 - zzd3) * 0.5);
                    if (zzd6 < zzd8 && zzd4 < zzd6 && zzd4 < zzd2 && zzd3 < zzd1)                // ВНИЗУ
                    {
                        Print("RED ВНИЗУ {0} - 1-{1} 2-{2} 3-{3} 4-{4} 5-{5} 6-{6} 7-{7} 8-{8}", Bars[Bars.Range.To].Time, zzd1, zzd2, zzd3, zzd4, zzd5, zzd6, zzd7, zzd8);
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Red;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi8].Time, zzd8));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi7].Time, zzd7));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi6].Time, zzd6));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi5].Time, zzd5));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi4].Time, zzd4));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi3].Time, zzd3));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi2].Time, zzd2));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi1].Time, zzd1));
                    }
                }
            }
        }
예제 #4
0
 protected override void NewBar()
 {
     _wprInd.ReInit();
     if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
     {
         var toolVerticalLine = Tools.Create <VerticalLine>();
         toolVerticalLine.Time  = Bars[Bars.Range.To - 1].Time;
         toolVerticalLine.Color = Color.Red;
     }
 }
예제 #5
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();
//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;
//====== ВВЕРХУ ПИК =====================================================================================================================
                if (zz3 < zz2 && zz2 > zz1)
                {                       // ВВЕРХУ
                    zzd5    = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu5    = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    vy.Time = Bars[Bars.Range.To - 1].Time;
                    Print("ВЕРХ - {0} {1} {2} {3} - {4}", Bars[Bars.Range.To - 1].Time, zzu2 > zzu4, zzu3 > zzu1, Math.Round((zzu3 - zzu2) / (zzu3 - zzu4) * 100, 0), (zzu3 - zzu4) > (zzu3 - zzu2) * 2);
                    if (zzu2 > zzu4 &&
                        zzu3 > zzu1 &&
                        (zzu3 - zzu4) > (zzu3 - zzu2) * 2
                        )                    // ВВЕРХУ
                    {
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Red;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd4].Time, Bars[zzd4].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd3].Time, Bars[zzd3].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd2].Time, Bars[zzd2].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd1].Time, Bars[zzd1].High));
                    }
                }
//==== ВНИЗУ ПИК ======================================================================================================================
                if (zz3 > zz2 && zz2 < zz1)
                {                       // ВНИЗУ
                    zzd5    = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu5    = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    vy.Time = Bars[Bars.Range.To - 1].Time;
                    Print("ВНИЗ - {0} {1} {2} {3} - {4}", Bars[Bars.Range.To - 1].Time, zzu4 > zzu2, zzu1 > zzu3, Math.Round((zzu2 - zzu3) / (zzu4 - zzu3) * 100, 0), (zzu4 - zzu3) > (zzu2 - zzu3) * 2);

                    if (zzu4 > zzu2 &&
                        zzu1 > zzu3 &&
                        (zzu4 - zzu3) > (zzu2 - zzu3) * 2
                        )                       //  ВНИЗУ
                    {
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Blue;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd4].Time, Bars[zzd4].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd3].Time, Bars[zzd3].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd2].Time, Bars[zzd2].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd1].Time, Bars[zzd1].Low));
                    }
                }
//===============================================================================================================================
            }
        }
예제 #6
0
파일: ZZ71.cs 프로젝트: ivan-petrov-ubk/CS
        protected override void NewBar()
        {
            _wprInd.ReInit();
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 2] > 0)
            {             // Всі точки перегину зиззага
                if (Instrument.Name.EndsWith("JPY"))
                {
                    kor2 = 0.001 * Pt;
                }
                else
                {
                    kor2 = 0.00001 * Pt;
                }
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 2];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 2;

                if (zz3 > zz2 && zz2 < zz1)
                {
                    zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                }
                if (zz3 < zz2 && zz2 > zz1)
                {
                    zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                }



                if (Bars[zzd2].Low > Bars[zzi1].Low && Bars[zzd2].High < Bars[zzd1].High && Bars[zzi1].High <Bars[zzd1].High && Bars[zzd3].Low - Bars[zzi1].Low> kor2)
                {           //Print("Ввверху Максимум");
                    vr.Time = Bars[zzd2].Time;
                    vb.Time = Bars[zzd1].Time;
                    vy.Time = Bars[zzi1].Time;
                    if (Bars[zzd1].Low != zzU)
                    {
                        zzU = Bars[zzd1].Low;
                        var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1, Bars[zzd1].High - Instrument.Spread, 0, Stops.InPips(SL, TP), Bars[zzd1].Time.AddHours(15), null, null);
                    }
                }

                if (Bars[zzd2].High < Bars[zzi1].High && Bars[zzd1].Low < Bars[zzd2].Low && Bars[zzd1].Low <Bars[zzi1].Low && Bars[zzi1].Low - Bars[zzd3].Low> kor2)
                {                  //Print("Внизу Максимум");
                    vr.Time = Bars[zzd2].Time;
                    vb.Time = Bars[zzd1].Time;
                    vy.Time = Bars[zzi1].Time;
                    if (Bars[zzd1].Low != zzD)
                    {
                        zzD = Bars[zzd1].Low;
                        var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, Bars[zzd1].Low + Instrument.Spread + kor, 0, Stops.InPips(SL, TP), Bars[zzd1].Time.AddHours(15), null, null);
                    }
                }
            }
        }
예제 #7
0
        protected override void NewBar()
        {
            _wprInd.ReInit();
            //=== КОРЕКЦИЯ ===========================================================================================================
            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
            // Print("{0} sFTime={1} sF={2}",Bars[Bars.Range.To-1].Time,timeM15,sF);
            if (sF1 < 0 && sF > 0)           // ВВЕРХ
            {
                var vr1 = Tools.Create <VerticalLine>(); vr1.Color = Color.Red;  vr1.Time = Bars[Bars.Range.To - 1].Time; vr1.Width = 1;
                Print("ВЕРХ - {0} -- {1} {2}", Bars[Bars.Range.To - 1].Time, Math.Round(_ftoInd1.FisherSeries[Bars.Range.To - 2], 3), Math.Round(_ftoInd1.FisherSeries[Bars.Range.To - 1], 3));
                if (_ftoInd1.FisherSeries[Bars.Range.To - 2] < 0 && _ftoInd1.FisherSeries[Bars.Range.To - 1] > 0)
                {
                    Print("----------------- OK ------------------"); var vr3 = Tools.Create <VerticalLine>(); vr3.Color = Color.Olive;  vr3.Time = Bars[Bars.Range.To - 1].Time; vr3.Width = 3;
                    if (posGuidBuy == Guid.Empty)
                    {
                        var result3 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1, Stops.InPips(200, 100), null, null);
                        if (result3.IsSuccessful)
                        {
                            posGuidBuy = result3.Position.Id;
                        }
                    }
                }
            }

            if (sF1 > 0 && sF < 0)           //ВНИЗ
            {
                var vr2 = Tools.Create <VerticalLine>(); vr2.Color = Color.Blue;  vr2.Time = Bars[Bars.Range.To - 1].Time; vr2.Width = 1;
                Print("ВНИЗ - {0} -- {1} {2}", Bars[Bars.Range.To - 1].Time, Math.Round(_ftoInd1.FisherSeries[Bars.Range.To - 2], 3), Math.Round(_ftoInd1.FisherSeries[Bars.Range.To - 1], 3));
                if (_ftoInd1.FisherSeries[Bars.Range.To - 2] > 0 && _ftoInd1.FisherSeries[Bars.Range.To - 1] < 0)
                {
                    Print("----------------- OK ------------------"); var vr = Tools.Create <VerticalLine>(); vr.Color = Color.IndianRed; vr.Time = Bars[Bars.Range.To - 1].Time; vr.Width = 3;
                    if (posGuidSell == Guid.Empty)
                    {
                        var result2 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Bid, -1, Stops.InPips(200, 100), null, null);
                        if (result2.IsSuccessful)
                        {
                            posGuidSell = result2.Position.Id;
                        }
                    }
                }
            }
        }
예제 #8
0
파일: Wolf1.cs 프로젝트: ivan-petrov-ubk/CS
        protected override void NewBar()
        {
            _wprInd.ReInit();

//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;

                if (zz3 < zz2 && zz2 > zz1)
                {                   // ВВЕРХУ
                    zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu6 = zzu5; zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    //dt = ((zzd3-zzd1)/(zzd5-zzd1)) - ((zzu3-zzu1)/(zzu5-zzu1));


                    A  = zzu1 - zzu5; B = zzd5 - zzd1; C = zzd1 * zzu5 - zzd5 * zzu1;
                    dt = Math.Abs(A * zzd3 + B * zzu3 + C) / Math.Sqrt(A * A + B * B);
                    Print("{0} - {1} {2} {3}", dt, Bars[zzd5].Time, Bars[zzd3].Time, Bars[zzd1].Time);

                    /*		if(Math.Abs(dt)<0.02)
                     *          {
                     * var toolTrendLine = Tools.Create<TrendLineRay>();
                     * toolTrendLine.Point1 = new ChartPoint(Bars[zzd5].Time, Bars[zzd5].High);
                     * toolTrendLine.Point2 = new ChartPoint(Bars[zzd1].Time, Bars[zzd1].High);}  */
                }

                if (zz3 > zz2 && zz2 < zz1)
                {                   // ВНИЗУ
                    zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu6 = zzu5; zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;

                    //dt = ((zzd3-zzd1)/(zzd5-zzd1)) - ((zzu3-zzu1)/(zzu5-zzu1));
                    A  = zzu1 - zzu5; B = zzd5 - zzd1; C = zzd1 * zzu5 - zzd5 * zzu1;
                    dt = Math.Abs(A * zzd3 + B * zzu3 + C) / Math.Sqrt(A * A + B * B);
                    Print("{0} - {1} {2} {3}", dt, Bars[zzd5].Time, Bars[zzd3].Time, Bars[zzd1].Time);

                    /*				if(Math.Abs(dt)<0.02)
                     * {
                     * var toolTrendLine = Tools.Create<TrendLineRay>();
                     * toolTrendLine.Point1 = new ChartPoint(Bars[zzd5].Time, Bars[zzd5].Low);
                     * toolTrendLine.Point2 = new ChartPoint(Bars[zzd1].Time, Bars[zzd1].Low);
                     * }  */
                }
            }
//===============================================================================================================================
        }
예제 #9
0
        protected override void NewBar()
        {
            _wprInd.ReInit();
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 2] > 0)
            {             // Всі точки перегину зиззага
                zz3  = zz2;        zz2 = zz1;    zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 2];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 2;
                Print("{0} {1} {2} -- {3}", zz3, zz2, zz1, Bars[Bars.Range.To - 2].Time);
                if (zz3 > zz2 && zz2 < zz1)
                {
                    zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, Bars[zzd1].Low + Instrument.Spread + kor, 0, Stops.InPips(SL, TP), null, null, null);
                }
                if (zz3 < zz2 && zz2 > zz1)
                {
                    zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1, Bars[zzd1].High - Instrument.Spread - kor, 0, Stops.InPips(SL, TP), null, null, null);
                }



                if (Bars[zzd2].Low > Bars[zzi1].Low && Bars[zzd2].High < Bars[zzd1].High && Bars[zzi1].High < Bars[zzd1].High)
                {
                    Print("Ввверху Максимум");
                    vr.Time = Bars[zzd2].Time;
                    vb.Time = Bars[zzd1].Time;
                    vy.Time = Bars[zzi1].Time;
                    //if(Bars[zzd1].Low!=zzU) { zzU=Bars[zzd1].Low;
                    //var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1,  Bars[zzd1].High-Instrument.Spread-kor, 0, Stops.InPips(SL,TP), null, null, null);
                    //	if (result1.IsSuccessful)  posGuidSell=result1.Position.Id;
                    //}
                }


                if (Bars[zzd2].High < Bars[zzi1].High && Bars[zzd1].Low < Bars[zzd2].Low && Bars[zzd1].Low < Bars[zzi1].Low)
                {
                    Print("Внизу Максимум");
                    vr.Time = Bars[zzd2].Time;
                    vb.Time = Bars[zzd1].Time;
                    vy.Time = Bars[zzi1].Time;
                    //	if(Bars[zzd1].Low!=zzD) { zzD=Bars[zzd1].Low;
                    //	var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, Bars[zzd1].Low+Instrument.Spread+kor, 0, Stops.InPips(SL,TP), null, null, null);
                    //	if (result1.IsSuccessful)  posGuidBuy=result1.Position.Id;
                    //	}
                }
            }
        }
예제 #10
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();
//=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }

            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;

                if (zz3 < zz2 && zz2 > zz1)
                {                 // ВВЕРХУ
                    zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("ВВЕРХ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
                    if (zzu1 > zzu2 && zzu3 > zzu2 && zzu1 > zzu3 && zzu2 > zzu4 && zzu3 > zzu4)          // ВВЕРХУ
                    {
                        var vr      = Tools.Create <VerticalLine>(); vr.Color = Color.Red; vr.Time = Bars[zzd1].Time;
                        var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1, zzu1, 0, Stops.InPips(20, 20), Bars[zzd1].Time.AddHours(15), null, null);
                    }
                }

                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("НИЗ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
                    if (zzu4 > zzu2 && zzu3 > zzu1 && zzu2 > zzu3 && zzu4 > zzu3)            //  ВНИЗУ
                    {
                        var vr     = Tools.Create <VerticalLine>(); vr.Color = Color.Blue; vr.Time = Bars[zzd1].Time;
                        var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, zzu1, 0, Stops.InPips(20, 20), Bars[zzd1].Time.AddHours(15), null, null);
                    }
                }
            }
        }
예제 #11
0
      protected override void NewBar()
      {
          _wprInd3.ReInit();
          O1    = Bars[Bars.Range.To - 1].Open;
          C1    = Bars[Bars.Range.To - 1].Close;
          DTime = Bars[Bars.Range.To - 1].Time;
          if (DTime.Hour == 00 && DTime.Minute == 00)
          {
              var highestIndex = Series.Highest(Bars.Range.To, 288, PriceMode.High);
              var highestPrice = Bars[highestIndex].High;
              H1 = highestPrice;
              var lowestIndex = Series.Lowest(Bars.Range.To, 288, PriceMode.Low);
              var lowestPrice = Bars[lowestIndex].Low;
              L1 = lowestPrice;

              Line1.Price = H1;
              Line1.Text  = string.Format("{0}", Math.Round((H1 - L1) * 100000, 0));
              Line2.Price = L1;
          }
      }
예제 #12
0
        protected override void NewBar()
        {
            // Event occurs on every new bar
            _wprInd.ReInit();

            //Print("{0} - {1}",Bars[Bars.Range.To-1].Time, _wprInd.MainIndicatorSeries[Bars.Range.To-1]);
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {              //var vr=Tools.Create<VerticalLine>(); vr.Color=Color.Red; vr.Time=Bars[Bars.Range.To-1].Time;
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;

                if (zz3 < zz2 && zz2 > zz1)               // ВВЕРХУ
                {
                    zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    V    = 1;
                    Print("ВВЕРХ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
                    if (zzu1 > zzu2 && zzu3 > zzu2 && zzu1 > zzu3 && zzu2 > zzu4 && zzu3 > zzu4)  // ВВЕРХУ
                    {
                        var vr      = Tools.Create <VerticalLine>(); vr.Color = Color.Red; vr.Time = Bars[zzd1].Time;
                        var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1, zzu1 + Instrument.Spread - 0.0002, 0, Stops.InPips(200, 200), Bars[zzd1].Time.AddHours(15), null, null);
                    }
                }

                if (zz3 > zz2 && zz2 < zz1)               // ВНИЗУ
                {
                    zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    V    = 2;
                    Print("НИЗ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
                    if (zzu4 > zzu2 && zzu3 > zzu1 && zzu2 > zzu3 && zzu4 > zzu3)    //  ВНИЗУ
                    {
                        var vr     = Tools.Create <VerticalLine>(); vr.Color = Color.Blue; vr.Time = Bars[zzd1].Time;
                        var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, zzu1 - Instrument.Spread + 0.0002, 0, Stops.InPips(200, 200), Bars[zzd1].Time.AddHours(15), null, null);
                    }
                }
            }
        }
예제 #13
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();
//=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }

//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3 = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];


                if (zz3 < zz2 && zz2 > zz1)
                {                 // ВВЕРХУ
                    if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending)
                    {
                        //Print("Buy {0} - Price={1} - SL={2} - TP={3}",Bars[Bars.Range.To-1].Time,zz2-(NKZ*Instrument.Point)+Instrument.Spread,zz2-((NKZ-SL)*Instrument.Point),zz2-((NKZ+TP)*Instrument.Point));
                        var result3 = Trade.UpdatePendingPosition(posGuidBuy, 0.1, zz2 - (NKZ * Instrument.Point) + Instrument.Spread, zz2 - ((NKZ + SL) * Instrument.Point) + Instrument.Spread, zz2 - ((NKZ - TP) * Instrument.Point) + Instrument.Spread);
                        if (result3.IsSuccessful)
                        {
                            posGuidBuy = result3.Position.Id;
                        }
                    }

                    if (posGuidBuy == Guid.Empty)
                    {
                        var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, zz2 - (NKZ * Instrument.Point) + Instrument.Spread, 0, Stops.InPips(SL, TP), null, null, null);
                        if (result.IsSuccessful)
                        {
                            posGuidBuy = result.Position.Id;
                        }
                    }
                }

                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                    {
                        // Print("Sell {0} - Price={1} - SL={2} - TP={3}",Bars[Bars.Range.To-1].Time,zz2+(NKZ*Instrument.Point)-Instrument.Spread,zz2+((NKZ+SL)*Instrument.Point)+Instrument.Spread,zz2+((NKZ-TP)*Instrument.Point));
                        var result2 = Trade.UpdatePendingPosition(posGuidSell, 0.1, zz2 + (NKZ * Instrument.Point) - Instrument.Spread, zz2 + ((NKZ + SL) * Instrument.Point) - Instrument.Spread, zz2 + ((NKZ - TP) * Instrument.Point) - Instrument.Spread);
                        if (result2.IsSuccessful)
                        {
                            posGuidSell = result2.Position.Id;
                        }
                    }

                    if (posGuidSell == Guid.Empty)
                    {
                        var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1, zz2 + (NKZ * Instrument.Point) - Instrument.Spread, 0, Stops.InPips(SL, TP), null, null, null);
                        if (result1.IsSuccessful)
                        {
                            posGuidSell = result1.Position.Id;
                        }
                    }
                }
            }
        }
예제 #14
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();
//=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }

//=== Закрытие всех ордеров если пятница 16:00 (19:00 Kiev) ===========================================================================
            if (Bars[Bars.Range.To - 1].Time.DayOfWeek == DayOfWeek.Friday && Bars[Bars.Range.To - 1].Time.Hour == 16)
            {
                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.Active)
                {
                    var res = Trade.CloseMarketPosition(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 (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                {
                    var res = Trade.CancelPendingPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }
//======================================================================================================================================
            //Значение счетчика прохода фишера через 0  FU - вверх  FD - вниз
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] < 0.3 && _ftoInd.FisherSeries[Bars.Range.To - 1] > 0.3)
            {
                FU = Bars.Range.To; isFU = true;
            }
            else
            {
                isFU = false;
            }
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] > -0.3 && _ftoInd.FisherSeries[Bars.Range.To - 1] < -0.3)
            {
                FD = Bars.Range.To; isFD = true;
            }
            else
            {
                isFD = false;
            }
            // isFMU isFMD - синяя линия пересекла линию фишера
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] < _ftoInd.Ma1Series[Bars.Range.To - 2] && _ftoInd.FisherSeries[Bars.Range.To - 1] > _ftoInd.Ma1Series[Bars.Range.To - 1])
            {
                isFMU = true;
            }
            else
            {
                isFMU = false;
            }
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] > _ftoInd.Ma1Series[Bars.Range.To - 2] && _ftoInd.FisherSeries[Bars.Range.To - 1] < _ftoInd.Ma1Series[Bars.Range.To - 1])
            {
                isFMD = true;
            }
            else
            {
                isFMD = false;
            }
            // isFM2U isFM2D - красная линия пересекла линию фишера
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] < _ftoInd.Ma2Series[Bars.Range.To - 2] && _ftoInd.FisherSeries[Bars.Range.To - 1] > _ftoInd.Ma2Series[Bars.Range.To - 1])
            {
                isFM2U = true;
            }
            else
            {
                isFM2U = false;
            }
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] > _ftoInd.Ma2Series[Bars.Range.To - 2] && _ftoInd.FisherSeries[Bars.Range.To - 1] < _ftoInd.Ma2Series[Bars.Range.To - 1])
            {
                isFM2D = true;
            }
            else
            {
                isFM2D = false;
            }

            // Если красная пересекла линию - закрыть все активные ордера
            if (isFM2U)
            {
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Active)
                {
                    var res3 = Trade.CloseMarketPosition(posGuidSell); if (res3.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }
            if (isFM2D)
            {
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Active)
                {
                    var res1 = Trade.CloseMarketPosition(posGuidBuy); if (res1.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
            }

            // Если фишер пересек 0 линию - закрыть все ордера
            if (isFD)
            {
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Active)
                {
                    var res1 = Trade.CloseMarketPosition(posGuidBuy); if (res1.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending)
                {
                    var res2 = Trade.CancelPendingPosition(posGuidBuy); if (res2.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
            }
            if (isFU)
            {
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Active)
                {
                    var res3 = Trade.CloseMarketPosition(posGuidSell); if (res3.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                {
                    var res4 = Trade.CancelPendingPosition(posGuidSell); if (res4.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }

//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;

                if (zz3 < zz2 && zz2 > zz1)
                {                 // ВВЕРХУ
                    zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu6 = zzu5; zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;

                    if (zzd1 > FD && zzd3 <= FD && zzd3 > FU && zzu1 < zzu3 && zzu1 > zzu2 + (zzu3 - zzu2) * 0.3 && zzu1 < zzu2 + (zzu3 - zzu2) * 0.9)
                    {
                        var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Red; vr.Time = Bars[zzd2].Time; vr.Width = 3;
                        if (posGuidSell == Guid.Empty)
                        {
                            var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellStop, 0.1, zzu2 - 0.0003, 0, Stops.InPips(300, 600), null, null, null);
                            if (result1.IsSuccessful)
                            {
                                posGuidSell = result1.Position.Id;
                            }
                            else
                            {
                                var result2 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1, Stops.InPips(300, 600), null, null);
                                //var result2=Trade.Sell(Instrument.Id, 0.1);
                                if (result2.IsSuccessful)
                                {
                                    posGuidSell = result2.Position.Id;
                                }
                            }
                        }
                    }
                }

                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu6 = zzu5; zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;

                    if (zzd1 > FU && zzd3 <= FU && zzd3 > FD && zzu1 < zzu2 - (zzu2 - zzu3) * 0.3 && zzu1 > zzu2 - (zzu2 - zzu3) * 0.9)

                    {
                        var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Blue; vr.Time = Bars[zzd2].Time; vr.Width = 3;
                        if (posGuidBuy == Guid.Empty)
                        {
                            var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyStop, 0.1, zzu2 + 0.0003, 0, Stops.InPips(200, 600), null, null, null);
                            if (result.IsSuccessful)
                            {
                                posGuidBuy = result.Position.Id;
                            }
                            else
                            {
                                var result3 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1, Stops.InPips(200, 600), null, null);
                                //var result3=Trade.Buy(Instrument.Id, 0.1);
                                if (result3.IsSuccessful)
                                {
                                    posGuidBuy = result3.Position.Id;
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #15
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();

//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;

                if (zz3 < zz2 && zz2 > zz1)
                {                 // 1 - ВВЕРХУ
                    zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu6 = zzu5; zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("ВВЕРХ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
//  Голова и плечи
//  if(zzu3>zzu5 && zzu3>zzu1 && zzu4>zzu6 )

// Патерн 1-2-3  zzu1-пик вверху
//
                    if (zzu3 > zzu1 && zzu5 > zzu3 && zzu4 > zzu2)
                    {
                        //var vr=Tools.Create<VerticalLine>(); vr.Color=Color.Red; vr.Time=Bars[zzd3].Time; vr.Width=4;

                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Blue;
                        toolPolyLine.Width = 4;
                        //toolPolyLine.AddPoint(new ChartPoint(Bars[zzd6].Time, Bars[zzd6].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd5].Time, Bars[zzd5].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd4].Time, Bars[zzd4].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd3].Time, Bars[zzd3].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd2].Time, Bars[zzd2].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd1].Time, Bars[zzd1].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[Bars.Range.To].Time, Bars[Bars.Range.To].Low));

/*			var toolRectangle = Tools.Create<Rectangle>();
 *                  //toolRectangle.BorderColor=Color.Red;
 *                  toolRectangle.Color=Color.Blue;
 *                      toolRectangle.BorderWidth = 4;
 *                  toolRectangle.BorderStyle =LineDashStyle.Solid;
 *              toolRectangle.Point1=new ChartPoint(Bars[zzd6].Time, Bars[zzd3].High);
 *              toolRectangle.Point2=new ChartPoint(Bars[zzd1].Time, Bars[zzd2].Low); */
                    }
                }

                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu6 = zzu5; zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("НИЗ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);

//					if(zzu5>zzu3 && zzu1>zzu3 && zzu6>zzu4)
// Патерн 1-2-3  zzu1-пик ВНИЗУ
//
                    if (zzu2 > zzu4 && zzu1 > zzu3 && zzu3 > zzu5)
                    {
                        //var vr=Tools.Create<VerticalLine>(); vr.Color=Color.Blue; vr.Time=Bars[zzd3].Time; vr.Width=4;

                        /*		var toolRectangle = Tools.Create<Rectangle>();
                         *              toolRectangle.Color=Color.Blue;
                         *          //toolRectangle.BorderColor=Color.Blue;
                         *          toolRectangle.BorderWidth = 4;
                         *          toolRectangle.BorderStyle =LineDashStyle.Solid;
                         *      toolRectangle.Point1=new ChartPoint(Bars[zzd6].Time, Bars[zzd3].Low);
                         *      toolRectangle.Point2=new ChartPoint(Bars[zzd1].Time, Bars[zzd6].High);  */

                        var toolPolyLine1 = Tools.Create <PolyLine>();
                        toolPolyLine1.Color = Color.Black;
                        toolPolyLine1.Width = 4;
                        //toolPolyLine.AddPoint(new ChartPoint(Bars[zzd6].Time, Bars[zzd6].Low));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[zzd5].Time, Bars[zzd5].Low));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[zzd4].Time, Bars[zzd4].High));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[zzd3].Time, Bars[zzd3].Low));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[zzd2].Time, Bars[zzd2].High));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[zzd1].Time, Bars[zzd1].Low));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[Bars.Range.To].Time, Bars[Bars.Range.To].High));
                    }
                }
            }
        }
예제 #16
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();
            DTime = Bars[Bars.Range.To - 1].Time;
            ci    = Bars.Range.To - 1;

            if (_frInd.BottomSeries[Bars.Range.To - 5] > 0)
            {
                frTop = false; frD2 = frD1; frD1 = _frInd.BottomSeries[Bars.Range.To - 5];
            }
            if (_frInd.TopSeries[Bars.Range.To - 5] > 0)
            {
                frTop = true; frU2 = frU1; frU1 = _frInd.TopSeries[Bars.Range.To - 5];
            }
//=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }

//====== BUY  UPDATE STOP  при появлении фрактала =======================================================================================================
            if (posGuidBuy != Guid.Empty && _frInd.BottomSeries[Bars.Range.To - 5] > 0 && frD1 > frD2)
            {
                sl1 = Math.Round(_frInd.BottomSeries[Bars.Range.To - 5] - Instrument.Spread - 0.00020, Instrument.PriceScale);
                Print("UPDATE BUY {0} - frD1={1} frD2={2} sl1={3}", Bars[Bars.Range.To - 1].Time, frD1, frD2, sl1);
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Active)
                {
                    var res3 = Trade.UpdateMarketPosition(posGuidBuy, sl1, null, null);
                    if (res3.IsSuccessful)
                    {
                        posGuidBuy = res3.Position.Id;
                    }
                    else
                    {
                        var res2 = Trade.CloseMarketPosition(posGuidBuy); if (res2.IsSuccessful)
                        {
                            posGuidBuy = Guid.Empty;
                        }
                    }
                }
            }

//===SELL UPDATE STOP   при появлении фрактала ===========================================================================================================
            if (posGuidSell != Guid.Empty && _frInd.TopSeries[Bars.Range.To - 5] > 0 && frU1 < frU2)
            {
                sl2 = Math.Round(_frInd.TopSeries[Bars.Range.To - 5] + Instrument.Spread + 0.00020, Instrument.PriceScale);
                Print("UPDATE SELL {0} - frU1={1} frU2={2} sl2={3}", Bars[Bars.Range.To - 1].Time, frU1, frU2, sl2);
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Active)
                {
                    var result2 = Trade.UpdateMarketPosition(posGuidSell, sl2, null, null);
                    if (result2.IsSuccessful)
                    {
                        posGuidSell = result2.Position.Id;
                    }
                    else
                    {
                        var res0 = Trade.CloseMarketPosition(posGuidSell); if (res0.IsSuccessful)
                        {
                            posGuidSell = Guid.Empty;
                        }
                    }
                }
            }

//====================================================================================================================================
            if (DTime.Hour < 7)
            {
                torg = true;
            }

            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 = 3;
            }

            //=====  ZigZag  =================================================================================================================================

            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0 && DTime.Hour < 7)
            {
                zz3  = zz2; zz2 = zz1; zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzt2 = zzt1; zzt1 = Bars[Bars.Range.To - 1].Time;
                if (zz3 < zz2 && zz2 > zz1)
                {
                    Up1 = true; Upt = zzt2;
                }
                if (zz3 > zz2 && zz2 < zz1)
                {
                    Up1 = false; Upt = zzt2;
                }
            }

            if (DTime.Hour == 7)
            {
                if (posGuidBuy == Guid.Empty && Up1 && torg)
                {
                    torg   = false;
                    frDown = Math.Round(_frInd.BottomSeries[Bars.Range.To - 5], Instrument.PriceScale);
                    Print("{0} Upt={1}", DTime, Upt);
                    var vl2 = Tools.Create <VerticalLine>(); vl2.Time = Upt; vl2.Color = Color.Red;
                    //var vl4 = Tools.Create<VerticalLine>(); vl4.Time=Bars[Bars.Range.To-1].Time; vl4.Color=Color.White;
                    sl1 = Instrument.Ask - (SL * Instrument.Point);
                    if (sl1 < frDown)
                    {
                        sl1 = frDown;
                    }

                    var result1 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1,
                                                           Stops.InPrice(sl1, null), null, null);
                    if (result1.IsSuccessful)
                    {
                        posGuidBuy = result1.Position.Id;
                    }
                    else
                    {
                        var result10 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1,
                                                                Stops.InPips(200, null), null, null);
                        if (result10.IsSuccessful)
                        {
                            posGuidBuy = result10.Position.Id;
                        }
                    }
                }

                if (posGuidSell == Guid.Empty && !Up1 && torg)
                {
                    torg = false;
                    Print("{0} Upt={1}", DTime, Upt);
                    var vl3 = Tools.Create <VerticalLine>(); vl3.Time = Upt; vl3.Color = Color.Blue;
                    //var vl4 = Tools.Create<VerticalLine>(); vl4.Time=Bars[Bars.Range.To-1].Time; vl4.Color=Color.White;
                    frUp = Math.Round(_frInd.TopSeries[Bars.Range.To - 5], Instrument.PriceScale);
                    sl2  = Instrument.Ask + (SL * Instrument.Point);
                    if (sl2 > frUp)
                    {
                        sl2 = frUp;
                    }
                    var result2 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1,
                                                           Stops.InPrice(sl2, null), null, null);
                    if (result2.IsSuccessful)
                    {
                        posGuidSell = result2.Position.Id;
                    }
                    else
                    {
                        var result20 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1,
                                                                Stops.InPips(200, null), null, null);
                        if (result20.IsSuccessful)
                        {
                            posGuidSell = result20.Position.Id;
                        }
                    }
                }
            }
        }
예제 #17
0
        protected override void NewBar()
        {
            var posActiveMine = Trade.GetActivePositions(null, true);

            if (posActiveMine.Length > 1)
            {
                if (posActiveMine[posActiveMine.Length - 1].Type.IsBuy())
                {
                    for (int i = 0; i < posActiveMine.Length - 1; i++)
                    {
                        if (posActiveMine[i].Type.IsSell())
                        {
                            var res = Trade.CloseMarketPosition(posActiveMine[i].Id);
                        }
                    }
                }

                if (posActiveMine[posActiveMine.Length - 1].Type.IsSell())
                {
                    for (int i = 0; i < posActiveMine.Length - 1; i++)
                    {
                        if (posActiveMine[i].Type.IsBuy())
                        {
                            var res = Trade.CloseMarketPosition(posActiveMine[i].Id);
                        }
                    }
                }
            }

            _wprInd.ReInit();
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 2] > 0)
            {             // Всі точки  зиззага
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 2];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 2;
                //  Кут перегибу
                if (zz3 > zz2 && zz2 < zz1)
                {
                    zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                }
                if (zz3 < zz2 && zz2 > zz1)
                {
                    zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                }

                if (Bars[zzd2].Low > Bars[zzi1].Low && Bars[zzd2].High < Bars[zzd1].High && Bars[zzi1].High <Bars[zzd1].High && Bars[zzd3].Low - Bars[zzi1].Low> kor2)
                {           //Print("Вверху Максимум");
                    vr.Time = Bars[zzd2].Time;
                    vb.Time = Bars[zzd1].Time;
                    vy.Time = Bars[zzi1].Time;
                    vw.Time = Bars[Bars.Range.To].Time;
                    if (Bars[zzd1].Low != zzU)
                    {
                        zzU = Bars[zzd1].Low;

                        var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1, Bars[zzd1].High + Instrument.Spread + kor, 0, Stops.InPips(SL, TP), Bars[zzd1].Time.AddHours(15), null, null);
                        XXPrint("{0} SellLimit {1} {2} {3} {4} {5} {6} {7} {8} {9}",
                                Bars[zzd1].Time,
                                Instrument.Name,
                                result1.Position.Number,
                                Math.Round(Bars[zzd1].High - Instrument.Spread - kor * Zn, n),
                                Math.Round(Math.Abs(zz3 - zz2) * Zn, 0),
                                Math.Round(Math.Abs(zz1 - zz2) * Zn, 0),
                                Math.Round(Math.Abs(zz3 - zz1) * Zn, 0),
                                Bars[zzd1 + 1].TickCount,
                                Bars[zzd1].TickCount,
                                Bars[zzd1 - 1].TickCount);
                    }
                }

                if (Bars[zzd2].High < Bars[zzi1].High && Bars[zzd1].Low < Bars[zzd2].Low && Bars[zzd1].Low <Bars[zzi1].Low && Bars[zzi1].Low - Bars[zzd3].Low> kor2)
                {                  //Print("Внизу Максимум");
                    vr.Time = Bars[zzd2].Time;
                    vb.Time = Bars[zzd1].Time;
                    vy.Time = Bars[zzi1].Time;
                    vw.Time = Bars[Bars.Range.To].Time;
                    if (Bars[zzd1].Low != zzD)
                    {
                        zzD = Bars[zzd1].Low;

                        var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, Bars[zzd1].Low - Instrument.Spread - kor, 0, Stops.InPips(SL, TP), Bars[zzd1].Time.AddHours(15), null, null);

                        XXPrint("BuyLimit {0} {1} {2} {3} {4} {5} {6} {7} {8} {9}",
                                Bars[zzd1].Time,
                                result.Position.Number,
                                Math.Round(Bars[zzd1].High - Instrument.Spread - kor * Zn, n),
                                Math.Round(Math.Abs(zz3 - zz2) * Zn, 0),
                                Math.Round(Math.Abs(zz1 - zz2) * Zn, 0),
                                Math.Round(Math.Abs(zz3 - zz1) * Zn, 0),
                                Bars[zzd1 + 1].TickCount,
                                Bars[zzd1].TickCount,
                                Bars[zzd1 - 1].TickCount);
                    }
                }
            }
        }
예제 #18
0
        protected override void NewBar()
        {
            _wprInd.ReInit();
            // ЗАКРИТТЯ ПОЗИЦІЙ !!!
            // ЗНИЗУ ВВЕРХ
            if (_awoInd.SeriesUp[Bars.Range.To - 3] < 0 && _awoInd.SeriesUp[Bars.Range.To - 2] > 0)
            {
                iU = Bars.Range.To - 3; bD = true;
                var vr = Tools.Create <VerticalLine>(); vr.Color = Color.BlueViolet; vr.Time = Bars[iU].Time;
                if (Trade.GetPosition(posGuidSell).State == PositionState.Active)
                {
                    var res = Trade.CloseMarketPosition(posGuidSell);
                    if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }
            // ЗВЕРХУ ВНИЗ
            if (_awoInd.SeriesDown[Bars.Range.To - 3] > 0 && _awoInd.SeriesDown[Bars.Range.To - 2] < 0)
            {
                iD = Bars.Range.To - 3; bU = true;
                var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Black; vr.Time = Bars[iD].Time;
                if (Trade.GetPosition(posGuidBuy).State == PositionState.Active)
                {
                    var res1 = Trade.CloseMarketPosition(posGuidBuy);
                    if (res1.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
            }

            //=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }

            //=== Закрытие всех ордеров если пятница 16:00 (19:00 Kiev) ===========================================================================
            if (Bars[Bars.Range.To - 1].Time.DayOfWeek == DayOfWeek.Friday && Bars[Bars.Range.To - 1].Time.Hour == 16)
            {
                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.Active)
                {
                    var res = Trade.CloseMarketPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }

            /*			// Тренд вниз ы появився Новий ПИК вверх
             *                      if(Bars[zzd2].High>Bars[zzd1].High &&
             *                         Bars[zzd2].High>Bars[zzd3].High &&
             *                               Trade.GetPosition(posGuidSell).State==PositionState.Active)
             *                      {	var res = Trade.CloseMarketPosition(posGuidBuy);
             *              if (res.IsSuccessful) posGuidSell = Guid.Empty;    }
             *                      // Тренд ВВЕРХ ы появился Новий ПИК ВНИЗ
             *                      if(Bars[zzd2].Low>Bars[zzd1].High &&
             *                         Bars[zzd2].High>Bars[zzd3].High &&
             *                               Trade.GetPosition(posGuidSell).State==PositionState.Active)
             *                      {	var res = Trade.CloseMarketPosition(posGuidBuy);
             *              if (res.IsSuccessful) posGuidSell = Guid.Empty;    }
             */

            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {             // Всі точки  зиззага
                vy.Time = Bars[Bars.Range.To - 1].Time;


                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];            // Значення ZigZag
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;                                       // Індекс свічок
                //  Індекси свічок в Куті перегибу

                // ВВЕРХУ
                if (zz3 > zz2 && zz2 < zz1)
                {
                    zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Active)
                    {
                        var res = Trade.CloseMarketPosition(posGuidBuy); if (res.IsSuccessful)
                        {
                            posGuidBuy = Guid.Empty;
                        }
                    }
                }
                // ВНИЗУ
                if (zz3 < zz2 && zz2 > zz1)
                {
                    zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Active)
                    {
                        var res = Trade.CloseMarketPosition(posGuidSell); if (res.IsSuccessful)
                        {
                            posGuidSell = Guid.Empty;
                        }
                    }
                }

                // Тренд ВВЕРХ - індекси свічок zzd1-3
                if (Bars[zzd2].High > Bars[zzd1].High &&
                    Bars[zzd2].High > Bars[zzd3].High &&
                    Bars[zzd1].High > Bars[zzd3].High &&
                    (Bars[zzd2].High - Bars[zzd1].Low) > (Bars[zzd2].High - Bars[zzd3].Low) * 0.236 &&
                    (Bars[zzd2].High - Bars[zzd1].Low) < (Bars[zzd2].High - Bars[zzd3].Low) * 0.8
                    )
                {                       //vr.Time=Bars[zzd1].Time; vb.Time=Bars[zzd2].Time; vg.Time=Bars[zzd3].Time;
                    Print("{0}  Buy={1} iU={2} zzd3={3} zzd2={4} bU={5}", Bars[Bars.Range.To - 1].Time, posGuidBuy, iU, zzd3, zzd2, bU);
                    //var vr=Tools.Create<VerticalLine>(); vr.Color=Color.Red; vr.Time=Bars[zzd1].Time;
                    //Print("BuyStop - {0} - {1}",posGuidBuy,Bars[zzd1].Time);
                    if (posGuidSell == Guid.Empty && zzd3 < iD && zzd2 > iD && bD)
                    {
                        bD = false;
                        var result1 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1, Stops.InPrice(null, null), null, null);
                        if (result1.IsSuccessful)
                        {
                            posGuidSell = result1.Position.Id;
                        }
                    }

                    /* if (posGuidBuy==Guid.Empty && zzd3<iU && zzd2>iU && bU) { bU=false;
                     * //var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyStop, 0.1, Bars[zzd2].High, 0, Stops.InPips(100,100), null, null, null);
                     * var result = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1,Instrument.Bid, -1, Stops.InPrice(Bars[zzd3].Low,null), null, null);
                     *                                               if (result.IsSuccessful)  posGuidBuy=result.Position.Id; } */
                }

                // Тренд ВНИЗ - індекси свічок zzd1-
                if (Bars[zzd3].Low > Bars[zzd2].Low &&
                    Bars[zzd1].Low > Bars[zzd2].Low &&
                    Bars[zzd3].Low > Bars[zzd1].Low &&
                    (Bars[zzd1].High - Bars[zzd2].Low) > (Bars[zzd3].High - Bars[zzd2].Low) * 0.236 &&
                    (Bars[zzd1].High - Bars[zzd2].Low) < (Bars[zzd3].High - Bars[zzd2].Low) * 0.8
                    )
                {                   // vr.Time=Bars[zzd1].Time; vb.Time=Bars[zzd2].Time; vg.Time=Bars[zzd3].Time;
                    // var vr=Tools.Create<VerticalLine>(); vr.Color=Color.Blue; vr.Time=Bars[zzd1].Time;
                    Print("{0}  Sell={1} iD={2} zzd3={3} zzd2={4} bD={5}", Bars[Bars.Range.To - 1].Time, posGuidSell, iD, zzd3, zzd2, bD);

                    if (posGuidBuy == Guid.Empty && zzd3 < iU && zzd2 > iU && bU)
                    {
                        bU = false;
                        //var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyStop, 0.1, Bars[zzd2].High, 0, Stops.InPips(100,100), null, null, null);
                        var result = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1, Stops.InPrice(null, null), null, null);
                        if (result.IsSuccessful)
                        {
                            posGuidBuy = result.Position.Id;
                        }
                    }

                    /*	if (posGuidSell==Guid.Empty && zzd3<iD && zzd2>iD && bD) {  bD=false;
                     *         var result1 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1,Instrument.Ask, -1, Stops.InPrice(Bars[zzd3].High,null), null, null);
                     *                                                       if (result1.IsSuccessful)  posGuidSell=result1.Position.Id; } */
                }
            }
        }
예제 #19
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();
            _ftoInd.ReInit();
            ci = Bars.Range.To - 1;

//=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }
//=== Закрытие всех ордеров если пятница 16:00 (19:00 Kiev) ===========================================================================
            if (Bars[Bars.Range.To - 1].Time.DayOfWeek == DayOfWeek.Friday && Bars[Bars.Range.To - 1].Time.Hour == 16)
            {
                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.Active)
                {
                    var res = Trade.CloseMarketPosition(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 (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                {
                    var res = Trade.CancelPendingPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }

//==========  Значение счетчика прохода фишера через 0  FU - вверх  FD - вниз
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] < 0 && _ftoInd.FisherSeries[Bars.Range.To - 1] > 0)
            {
                isFU = true;
            }
            else
            {
                isFU = false;
            }
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] > 0 && _ftoInd.FisherSeries[Bars.Range.To - 1] < 0)
            {
                isFD = true;
            }
            else
            {
                isFD = false;
            }

/*
 * //========  isFM2U isFM2D - красная линия пересекла линию фишера
 *                      // Sell stop <0
 *                      if ( _ftoInd.FisherSeries[Bars.Range.To-2]<_ftoInd.Ma2Series[Bars.Range.To-2] &&
 *                               _ftoInd.FisherSeries[Bars.Range.To-1]>_ftoInd.Ma2Series[Bars.Range.To-1]) isFU=true; else isFU=false;
 *                      //  Buy stop >0
 *                      if ( _ftoInd.FisherSeries[Bars.Range.To-2]>_ftoInd.Ma2Series[Bars.Range.To-2] &&
 *                               _ftoInd.FisherSeries[Bars.Range.To-1]<_ftoInd.Ma2Series[Bars.Range.To-1]) isFD=true; else isFD=false;
 */
//========== Если фишер пересек линию - закрыть все ордера  =================================================================================
            if (isFD)
            {
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Active)
                {
                    var res1 = Trade.CloseMarketPosition(posGuidBuy); if (res1.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending)
                {
                    var res2 = Trade.CancelPendingPosition(posGuidBuy); if (res2.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
            }
            if (isFU)
            {
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Active)
                {
                    var res3 = Trade.CloseMarketPosition(posGuidSell); if (res3.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                {
                    var res4 = Trade.CancelPendingPosition(posGuidSell); if (res4.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }
//========== Если появился пик зигзага  ================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {                // Значения 3 значений - для определения направления
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;
                //======================= ПИК - ВЕШИНА ВВЕРХУ
                if (zz2 < zz3 && zz2 < zz1)
                {                   // Берем 4 вершины - zzd-индекс zzu-значение
                    //var vr=Tools.Create<VerticalLine>(); vr.Color=Color.Red; vr.Time=Bars[zzi2].Time;
                    zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    // Print("ВВЕРХ {0} 1={1} 2={2} 3={3} 4={4}",Bars[zzd1].Time,zzu1,zzu2,zzu3,zzu4);
                    //===== ВВЕРХ 2 импульса - на втором ^^ отложка лимит
                    //if(zzu1>zzu2 && zzu3>zzu2 && zzu1>zzu3 && zzu2>zzu4 && zzu3>zzu4)
                    if (zzu1 > zzu3 && zzu2 > zzu4 && zzu3 > zzu5)
                    {
                        var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Red; vr.Time = Bars[zzd2].Time;
                        if (posGuidSell == Guid.Empty)
                        {
                            sl1 = (int)(Math.Round(Math.Abs(zzu3 - zzu2), 5) * 100000) - (int)(Math.Round(Math.Abs(zzu1 - Bars[ci].Close), 5) * 100000);
                            //sl1=(int)(Math.Round(Math.Abs(zzu1-Bars[ci].Close),5)*100000);

                            var result1 = Trade.OpenPendingPosition(Instrument.Id,
                                                                    ExecutionRule.SellLimit, 0.1,
                                                                    zzu2 - Instrument.Spread - 0.0002, 0,
                                                                    Stops.InPips(sl1, 50), null, null, null);
                            // var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1,  zzu1+Instrument.Spread-0.0002, 0, Stops.InPips(200,null), null, null, null);
                            if (result1.IsSuccessful)
                            {
                                posGuidSell = result1.Position.Id; zzts2 = zzu3;
                            }
                        }
                    }
                }

                //======================  ПИК - ВЕРШИНА ВВЕРХУ
                if (zz2 > zz3 && zz2 > zz1)
                {                 // Берем 4 вершины - zzd-индекс zzu-значение
                    //var vr=Tools.Create<VerticalLine>(); vr.Color=Color.Blue; vr.Time=Bars[zzi2].Time;
                    zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;

                    // Print("НИЗ {0} 1={1} 2={2} 3={3} 4={4}",Bars[zzd1].Time,zzu1,zzu2,zzu3,zzu4);
                    //===== ВНИЗ 2 импульса - на втором ^^ отложка лимит
                    // if(zzu4>zzu2 && zzu3>zzu1 && zzu2>zzu3 && zzu4>zzu3)
                    if (zzu4 > zzu2 && zzu5 > zzu3 && zzu3 > zzu1)
                    {
                        var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Blue; vr.Time = Bars[zzd2].Time;
                        if (posGuidBuy == Guid.Empty)
                        {
                            sl1 = (int)(Math.Round(Math.Abs(zzu3 - zzu2), 5) * 100000);
                            sl1 = (int)(Math.Round(Math.Abs(zzu3 - zzu2), 5) * 100000) - (int)(Math.Round(Math.Abs(zzu1 - Bars[ci].Close), 5) * 100000);
                            var result = Trade.OpenPendingPosition(Instrument.Id,
                                                                   ExecutionRule.BuyLimit, 0.1,
                                                                   zzu2 + Instrument.Spread + 0.0002, 0,
                                                                   Stops.InPips(sl1, 100), null, null, null);

                            if (result.IsSuccessful)
                            {
                                posGuidBuy = result.Position.Id; zztb2 = zzu3;
                            }
                        }
                    }
                }

//=========  Если стоит лимитка Sell/Buy и цена пересекла низ/верх 2 пика - закрыть лимитку
                if (posGuidSell != Guid.Empty &&
                    Trade.GetPosition(posGuidSell).State == PositionState.Pending &&
                    Bars[Bars.Range.To - 1].Low < zzts2)
                {
                    var res = Trade.CancelPendingPosition(posGuidSell);
                    if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
                if (posGuidBuy != Guid.Empty &&
                    Trade.GetPosition(posGuidBuy).State == PositionState.Pending &&
                    Bars[Bars.Range.To - 1].High > zztb2)
                {
                    var res = Trade.CancelPendingPosition(posGuidBuy);
                    if (res.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
            }
        }
예제 #20
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();

            //if(posGuidBuy!=Guid.Empty && posGuidBuy)
            //=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }

            //=== Закрытие всех ордеров если пятница 16:00 (19:00 Kiev) ===========================================================================
            if (Bars[Bars.Range.To - 1].Time.DayOfWeek == DayOfWeek.Friday && Bars[Bars.Range.To - 1].Time.Hour == 16)
            {
                Torg = false;
                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.Active)
                {
                    var res = Trade.CloseMarketPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }
            if (Bars[Bars.Range.To - 1].Time.DayOfWeek == DayOfWeek.Monday && Bars[Bars.Range.To - 1].Time.Hour == 6)
            {
                Torg = true;
            }

//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;

                if (zz3 < zz2 && zz2 > zz1)
                {                 // 1 - ВВЕРХУ
                    zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu6 = zzu5; zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("ВВЕРХ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);

// Патерн 1-2-3  zzu1-пик вверху
//
                    if (zzu3 > zzu1 && zzu5 > zzu3 && zzu4 > zzu2)
                    {
                        var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Red; vr.Time = Bars[zzd3].Time; vr.Width = 4;

                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Blue;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd4].Time, Bars[zzd4].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd3].Time, Bars[zzd3].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd2].Time, Bars[zzd2].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd1].Time, Bars[zzd1].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[Bars.Range.To].Time, Bars[Bars.Range.To].Low));

                        if (Torg && posGuidBuy == Guid.Empty)
                        {
                            var result2 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1, Stops.InPips(200, 150), null, null);
//var result1 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1,Instrument.Ask, -1,Stops.InPrice(Bars[zzd1].High,null), null, null);
                            if (result2.IsSuccessful)
                            {
                                posGuidBuy = result2.Position.Id;                                          //Stops.InPips(200,100) Stops.InPrice(Bars[zzd1].High,Bars[Bars.Range.To-1].Low-0.001)
                            }
                        }
                    }
                }

                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu6 = zzu5; zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("НИЗ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);

//			if (posGuidSell!=Guid.Empty && Trade.GetPosition(posGuidSell).State==PositionState.Active)
//			{var res = Trade.CloseMarketPosition(posGuidSell); if (res.IsSuccessful) posGuidSell = Guid.Empty;}

// Патерн 1-2-3  zzu1-пик ВНИЗУ
//
                    if (zzu2 > zzu4 && zzu1 > zzu3 && zzu3 > zzu5)
                    {
                        var vr           = Tools.Create <VerticalLine>(); vr.Color = Color.Blue; vr.Time = Bars[zzd3].Time; vr.Width = 4;
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Blue;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd4].Time, Bars[zzd4].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd3].Time, Bars[zzd3].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd2].Time, Bars[zzd2].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd1].Time, Bars[zzd1].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[Bars.Range.To].Time, Bars[Bars.Range.To].Low));

                        if (Torg && posGuidSell == Guid.Empty)
                        {
                            var result1 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1, Stops.InPips(200, 150), null, null);
//var result2 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1,Instrument.Bid, -1, Stops.InPrice(Bars[zzd1].Low,null), null, null);
                            if (result1.IsSuccessful)
                            {
                                posGuidSell = result1.Position.Id;                                         //Stops.InPips(200,100)  Stops.InPrice(Bars[zzd1].Low,Bars[Bars.Range.To-1].High+0.001),
                            }
                        }
                        var toolPolyLine1 = Tools.Create <PolyLine>();
                        toolPolyLine1.Color = Color.Black;
                        toolPolyLine1.Width = 4;
                        //toolPolyLine.AddPoint(new ChartPoint(Bars[zzd6].Time, Bars[zzd6].Low));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[zzd5].Time, Bars[zzd5].Low));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[zzd4].Time, Bars[zzd4].High));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[zzd3].Time, Bars[zzd3].Low));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[zzd2].Time, Bars[zzd2].High));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[zzd1].Time, Bars[zzd1].Low));
                        toolPolyLine1.AddPoint(new ChartPoint(Bars[Bars.Range.To].Time, Bars[Bars.Range.To].High));
                    }
                }
            }
        }
예제 #21
0
        protected override void NewBar()
        {
            //=== КОРЕКЦИЯ ===========================================================================================================
            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
            //Print("|{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}| - {13}", _wprInd.MainIndicatorSeries[Bars.Range.To-1],_wprInd.MainIndicatorSeries[Bars.Range.To-2],_wprInd.MainIndicatorSeries[Bars.Range.To-3],_wprInd.MainIndicatorSeries[Bars.Range.To-4],_wprInd.MainIndicatorSeries[Bars.Range.To-5],_wprInd.MainIndicatorSeries[Bars.Range.To-6],_wprInd.MainIndicatorSeries[Bars.Range.To-7],_wprInd.MainIndicatorSeries[Bars.Range.To-8],_wprInd.MainIndicatorSeries[Bars.Range.To-9],_wprInd.MainIndicatorSeries[Bars.Range.To-10],_wprInd.MainIndicatorSeries[Bars.Range.To-11],_wprInd.MainIndicatorSeries[Bars.Range.To-12],_wprInd.MainIndicatorSeries[Bars.Range.To-13], Bars[Bars.Range.To-1].Time);
            //Print("ZigZag : {0} - {1} -  {2}", _wprInd.MainIndicatorSeries[Bars.Range.To-2],Bars[Bars.Range.To-2].Time,Bars.Range.To-2);
            _wprInd.ReInit();
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 2] > 0)
            {             // Всі точки перегину зиззага
                zz3  = zz2;        zz2 = zz1;    zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 2];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 2;
                Print("{0} {1} {2} -- {3}", zz3, zz2, zz1, Bars[Bars.Range.To - 2].Time);

                /*
                 * var toolVerticalLine=Tools.Create<VerticalLine>();
                 * toolVerticalLine.Time = Bars[Bars.Range.To-2].Time;
                 *      toolVerticalLine.Color=Color.Yellow;
                 */

                if (Bars[zzd2].Low > Bars[zzi1].Low && Bars[zzd2].High < Bars[zzd1].High && Bars[zzi1].High < Bars[zzd1].High)
                {
                    var toolVerticalLine = Tools.Create <VerticalLine>();
                    toolVerticalLine.Time  = Bars[zzd1].Time;
                    toolVerticalLine.Color = Color.Red;
                    if (posGuidSell == Guid.Empty)
                    {
                        var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1, Bars[zzd1].High - Instrument.Spread - kor, 0, Stops.InPips(SL, TP), null, null, null);
                        if (result1.IsSuccessful)
                        {
                            posGuidSell = result1.Position.Id;
                        }
                    }
                    if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                    {
                        var res = Trade.CancelPendingPosition(posGuidSell);
                        if (res.IsSuccessful)
                        {
                            posGuidSell = Guid.Empty;
                            var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1, Bars[zzd1].High - Instrument.Spread - kor, 0, Stops.InPips(SL, TP), null, null, null);
                            if (result1.IsSuccessful)
                            {
                                posGuidSell = result1.Position.Id;
                            }
                        }
                    }
                }

                if (Bars[zzd2].High <Bars[zzi1].High && Bars[zzd2].Low> Bars[zzd1].Low && Bars[zzi1].Low > Bars[zzd1].Low)
                {
                    var toolVerticalLine = Tools.Create <VerticalLine>();
                    toolVerticalLine.Time  = Bars[zzd2].Time;
                    toolVerticalLine.Color = Color.Blue;
                    if (posGuidBuy == Guid.Empty)
                    {
                        var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, Bars[zzd1].Low + Instrument.Spread + kor, 0, Stops.InPips(SL, TP), null, null, null);
                        if (result.IsSuccessful)
                        {
                            posGuidBuy = result.Position.Id;
                        }
                    }
                    if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending)
                    {
                        var res = Trade.CancelPendingPosition(posGuidBuy);
                        if (res.IsSuccessful)
                        {
                            posGuidBuy = Guid.Empty;
                            var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, Bars[zzd1].Low + Instrument.Spread + kor, 0, Stops.InPips(SL, TP), null, null, null);
                            if (result1.IsSuccessful)
                            {
                                posGuidBuy = result1.Position.Id;
                            }
                        }
                    }
                }

//if(Bars[zzd1].Close>_wprInd.MainIndicatorSeries[zzd1] && zz3>zz2 && zz2<zz1 && up)  {
                if (zz3 > zz2 && zz2 < zz1 && up)
                {
                    up = false; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2; zzU = _wprInd.MainIndicatorSeries[zzd1];

/*				    var toolVerticalLine=Tools.Create<VerticalLine>();
 *                              toolVerticalLine.Time = Bars[zzi2].Time;
 *                                      toolVerticalLine.Color=Color.Red;
 */
//Print("zzU={0} Bars[zzd1]={1} -- {2} -- {3}",zzU,Bars[zzd1].Close,Bars[zzd1].Time,Bars[zzd1].Close<zzU);
                }

//if(Bars[zzd1].Close<_wprInd.MainIndicatorSeries[zzd1] && zz3<zz2 && zz2>zz1 && !up) {
                if (zz3 < zz2 && zz2 > zz1 && !up)
                {
                    up = true;  zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2; zzD = _wprInd.MainIndicatorSeries[zzd1];

/*					var toolVerticalLine=Tools.Create<VerticalLine>();
 *                              toolVerticalLine.Time = Bars[zzi2].Time;
 *                                      toolVerticalLine.Color=Color.Blue;
 */
//Print("zzD={0} Bars[zzd1]={1} -- {2} -- {3}",zzD,Bars[zzd1].Close,Bars[zzd1].Time,Bars[zzd1].Close>zzD);
                }
            }
            //Print("|{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}| - {13}", _wprInd.MainIndicatorSeries[Bars.Range.To-1],_wprInd.MainIndicatorSeries[Bars.Range.To-2],_wprInd.MainIndicatorSeries[Bars.Range.To-3],_wprInd.MainIndicatorSeries[Bars.Range.To-4],_wprInd.MainIndicatorSeries[Bars.Range.To-5],_wprInd.MainIndicatorSeries[Bars.Range.To-6],_wprInd.MainIndicatorSeries[Bars.Range.To-7],_wprInd.MainIndicatorSeries[Bars.Range.To-8],_wprInd.MainIndicatorSeries[Bars.Range.To-9],_wprInd.MainIndicatorSeries[Bars.Range.To-10],_wprInd.MainIndicatorSeries[Bars.Range.To-11],_wprInd.MainIndicatorSeries[Bars.Range.To-12],_wprInd.MainIndicatorSeries[Bars.Range.To-13], Bars[Bars.Range.To-1].Time);
        }
예제 #22
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();
            DTime = Bars[Bars.Range.To - 1].Time;
            ci    = Bars.Range.To - 1;
            if (DTime.Hour < 7)
            {
                torgD = true; torgU = true; torg = true; StartTR = false;
            }

            if (DTime.Hour >= 6 && DTime.Hour < 8)
            {
                Print("ДО     - {0}  Up1={1} torgU={2} torgD={3} torg={4}", DTime, Up1, torgU, torgD, torg);
            }
//=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }


//====== BUY  UPDATE STOP  при появлении фрактала =======================================================================================================
            // if(posGuidBuy!=Guid.Empty  && _frInd.BottomSeries[Bars.Range.To-5]>0) StartTR=true;
//===SELL UPDATE STOP   при появлении фрактала ===========================================================================================================
            // if(posGuidSell!=Guid.Empty && _frInd.TopSeries[Bars.Range.To-5]>0) StartTR=true;
            if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).Pips > 30)
            {
                StartTR = true;
            }
            if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).Pips > 30)
            {
                StartTR = true;
            }
            if (StartTR)
            {
                TrailActiveOrders();
            }
//=== События ===================================================================================================================

            //=====  ZigZag  ======================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0 && DTime.Hour < 7)
            {
                zz3  = zz2; zz2 = zz1; zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzt2 = zzt1; zzt1 = Bars[Bars.Range.To - 1].Time;
                if (zz3 < zz2 && zz2 > zz1)
                {
                    Up1 = true; Upt = zzt2;
                }
                if (zz3 > zz2 && zz2 < zz1)
                {
                    Up1 = false; Upt = zzt2;
                }
            }

            // Рисуем вертикальную линию в 7:00
            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 = 3;
            }

//====================================================================================================================================
            if (DTime.Hour >= 7)
            {
                if (posGuidBuy == Guid.Empty && Up1 && torg)
                {
                    torg = false;
                    Print("Buy - Upt={0}", Upt);
                    var vl2      = Tools.Create <VerticalLine>(); vl2.Time = Upt; vl2.Color = Color.Red;
                    var result10 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1,
                                                            Stops.InPips(200, null), null, null);
                    if (result10.IsSuccessful)
                    {
                        posGuidBuy = result10.Position.Id;
                    }
                }

                if (posGuidSell == Guid.Empty && !Up1 && torg)
                {
                    torg = false;
                    Print("SELL - Upt={0}", Upt);
                    var vl2      = Tools.Create <VerticalLine>(); vl2.Time = Upt; vl2.Color = Color.Blue;
                    var result20 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1,
                                                            Stops.InPips(200, null), null, null);
                    if (result20.IsSuccessful)
                    {
                        posGuidSell = result20.Position.Id;
                    }
                }
            }
        }
예제 #23
0
        protected override void NewBar()
        {
            _wprInd.ReInit();



            if (first)
            {
                first = false;
                Print("First1");
                dt1     = dt1.AddHours(-3);
                iFT     = TimeToIndex(dt1, Timeframe);
                MAX     = Bars[iFT].High;
                MIN     = Bars[iFT].Low;
                MaxTime = dt1;
                MinTime = dt1;
                vl.Time = dt1;
                //Print("First - RTime={0} Max={1} Min={2} iFT={3}",RTime,MAX,MIN,iFT);
            }
            else
            {
                //Print("NOT First !!!!!  - RTime={0} Max={1} Min={2} iFT={3}",RTime,MAX,MIN,iFT);
                if (Bars[Bars.Range.To - 1].High > MAX)
                {
                    MAX = Bars[Bars.Range.To - 1].High; MaxTime = Bars[Bars.Range.To - 1].Time;
                }
                if (Bars[Bars.Range.To - 1].Low < MIN)
                {
                    MIN = Bars[Bars.Range.To - 1].Low; MinTime = Bars[Bars.Range.To - 1].Time;
                }
            }

            if (tu)
            {
                zmax = MAX;
                //Print("tu=true  - RTime={0} Max={1} Min={2} iFT={3}",RTime,MAX,MIN,iFT);
                RTime = MaxTime;
                nkz4  = zmax - ((NKZ - 5 - (NKZ * kf)) * Instrument.Point);
                nkz2  = zmax - (((NKZ * 2) - (NKZ * 2 * kf)) * Instrument.Point);
                nkz4v = zmax - ((NKZ - 5) * Instrument.Point);
                nkz2v = zmax - ((NKZ * 2) * Instrument.Point);
                nkz4  = Math.Round(nkz4, Instrument.PriceScale);
                nkz2  = Math.Round(nkz2, Instrument.PriceScale);
                nkz4v = Math.Round(nkz4v, Instrument.PriceScale);
                nkz2v = Math.Round(nkz2v, Instrument.PriceScale);
            }

            if (td)
            {
                zmin = MIN;
                //Print("td=true  - RTime={0} Max={1} Min={2} iFT={3}",RTime,MAX,MIN,iFT);
                RTime = MinTime;
                nkz4  = zmin + ((NKZ - 5 - (NKZ * kf)) * Instrument.Point);
                nkz2  = zmin + (((NKZ * 2) - (NKZ * 2 * kf)) * Instrument.Point);
                nkz4v = zmin + ((NKZ - 5) * Instrument.Point);
                nkz2v = zmin + (((NKZ * 2)) * Instrument.Point);
                nkz4  = Math.Round(nkz4, Instrument.PriceScale);
                nkz2  = Math.Round(nkz2, Instrument.PriceScale);
                nkz4v = Math.Round(nkz4v, Instrument.PriceScale);
                nkz2v = Math.Round(nkz2v, Instrument.PriceScale);
            }

            //Print("Rtime={0} nkz4={1} nkz4v={2} tu={3} td={4} k={5} zmax={6} zmin={7}",RTime,nkz4,nkz4v,tu,td,k,zmax,zmin);

            toolRectangle.Point1 = new ChartPoint(RTime, nkz4);
            toolRectangle.Point2 = new ChartPoint(Bars[Bars.Range.To - 1].Time.AddHours(4).AddHours(12), nkz4v);

            toolRectangle1.Point1 = new ChartPoint(RTime, nkz2);
            toolRectangle1.Point2 = new ChartPoint(Bars[Bars.Range.To - 1].Time.AddHours(4), nkz2v);
            //vl.Time=RTime;


//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                Print("{0} zz1={1} zz2={2} zz3={3}", Bars[Bars.Range.To - 1].Time, zz1, zz2, zz3);
                zz3 = zz2;      zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zi3 = zi2;      zi2 = zi1;   zi1 = Bars.Range.To - 1;

                if (zz3 < zz2 && zz2 > zz1)
                {                 // ВВЕРХУ
                    zzd7 = zzd6; zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zz2;
                    zzi7 = zzi6; zzi6 = zzi5; zzi5 = zzi4; zzi4 = zzi3; zzi3 = zzi2; zzi2 = zzi1; zzi1 = zi2;
                    //var vl1 = Tools.Create<VerticalLine>(); vl1.Time=Bars[zzi1].Time; vl1.Color=Color.Red;
                    //if( zzd4>zzd6 && zzd4>zzd2 && zzd3>zzd1  && (zzd3-zzd2)*0.5+zzd2<zzd1  ) // ВВЕРХУ  && (zzd3-zzd2)*0.5+zzd2<zzd1 && nkz4<zzd5 && td
                    if (zzd3 < zzd5 && zzd3 < zzd1 && zzd4 < zzd6 && nkz4 > zzd4 && tu)
                    {
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Aqua;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi6].Time, zzd6));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi5].Time, zzd5));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi4].Time, zzd4));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi3].Time, zzd3));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi2].Time, zzd2));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi1].Time, zzd1));
                        var vl1 = Tools.Create <VerticalLine>(); vl1.Time = Bars[zzi4].Time; vl1.Color = Color.Red;
                    }
                }

                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    zzd7 = zzd6; zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zz2;
                    zzi7 = zzi6; zzi6 = zzi5; zzi5 = zzi4; zzi4 = zzi3; zzi3 = zzi2; zzi2 = zzi1; zzi1 = zi2;
//var vl1 = Tools.Create<VerticalLine>(); vl1.Time=Bars[zzi1].Time; vl1.Color=Color.Blue;
                    //if( zzd4<zzd6 && zzd4<zzd2 && zzd3<zzd1   && (zzd2-zzd3)*0.5+zzd3>zzd1 ) //  ВНИЗУ  && (zzd2-zzd3)*0.5+zzd3>zzd1 && nkz4>zzd5 && tu
                    if (zzd3 > zzd5 && zzd3 > zzd1 && zzd4 > zzd6 && nkz4 < zzd4 && td)
                    {
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.White;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi6].Time, zzd6));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi5].Time, zzd5));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi4].Time, zzd4));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi3].Time, zzd3));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi2].Time, zzd2));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi1].Time, zzd1));
                        var vl1 = Tools.Create <VerticalLine>(); vl1.Time = Bars[zzi4].Time; vl1.Color = Color.Blue;
                    }
                }
            }
        }
예제 #24
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();
//=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }

//=== Закрытие всех ордеров если пятница 16:00 (19:00 Kiev) ===========================================================================
            if (Bars[Bars.Range.To - 1].Time.DayOfWeek == DayOfWeek.Friday && Bars[Bars.Range.To - 1].Time.Hour == 16)
            {
                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.Active)
                {
                    var res = Trade.CloseMarketPosition(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 (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                {
                    var res = Trade.CancelPendingPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }
//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;

                if (zz3 < zz2 && zz2 > zz1)
                {                 // ВВЕРХУ
                    zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("ВВЕРХ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
                    if (zzu1 > zzu2 && zzu3 > zzu2 && zzu1 > zzu3 && zzu2 > zzu4 && zzu3 > zzu4)          // ВВЕРХУ
                    {
                        var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Red; vr.Time = Bars[zzd1].Time;
                        if (posGuidSell == Guid.Empty)
                        {
                            var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1, zzu1 + Instrument.Spread - 0.0002, 0, Stops.InPips(200, 100), null, null, null);
                            if (result1.IsSuccessful)
                            {
                                posGuidSell = result1.Position.Id; zzts2 = zzu2;
                            }
                        }
                    }
                }

                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("НИЗ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
                    if (zzu4 > zzu2 && zzu3 > zzu1 && zzu2 > zzu3 && zzu4 > zzu3)            //  ВНИЗУ
                    {
                        var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Blue; vr.Time = Bars[zzd1].Time;
                        if (posGuidBuy == Guid.Empty)
                        {
                            var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, zzu1 - Instrument.Spread + 0.0002, 0, Stops.InPips(200, 100), null, null, null);
                            if (result.IsSuccessful)
                            {
                                posGuidBuy = result.Position.Id; zztb2 = zzu2;
                            }
                        }
                    }
                }

                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending && Bars[Bars.Range.To - 1].Low < zzts2)
                {
                    var res = Trade.CancelPendingPosition(posGuidSell);
                    if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending && Bars[Bars.Range.To - 1].High > zztb2)
                {
                    var res = Trade.CancelPendingPosition(posGuidBuy);
                    if (res.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
            }
        }
예제 #25
0
//===============================================================================================================================
        protected void Patern123()
        {
            _wprInd.ReInit();
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzt3 = zzt2;      zzt2 = zzt1;  zzt1 = Bars.Range.To - 1;
//====== ВВЕРХУ ПИК =====================================================================================================================
                if (zz3 < zz2 && zz2 > zz1)
                {                 // ВВЕРХУ на BUY - tu
                    zzi6 = zzi5; zzi5 = zzi4; zzi4 = zzi3; zzi3 = zzi2; zzi2 = zzi1; zzi1 = zzt2;
                    zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zz2;
                    if (zzd5 < zzd1 && zzd3 < zzd5 && zzd3 < zzd1 && nu)              // ВВЕРХУ
                    {
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Red;
                        toolPolyLine.Width = 4;

                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi6].Time, zzd6));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi5].Time, zzd5));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi4].Time, zzd4));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi3].Time, zzd3));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi2].Time, zzd2));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi1].Time, zzd1));

                        if (posGuidBuy == Guid.Empty)
                        {
                            frDown0 = frDown;
                            var result107 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1,
                                                                     Stops.InPips(SL1, null), null, mgB);
                            if (result107.IsSuccessful)
                            {
                                posGuidBuy = result107.Position.Id;
                            }
                        }
                    }
                }
//==== ВНИЗУ ПИК ======================================================================================================================
                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    zzi6 = zzi5; zzi5 = zzi4; zzi4 = zzi3; zzi3 = zzi2; zzi2 = zzi1; zzi1 = zzt2;
                    zzd6 = zzd5; zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zz2;
                    if (zzd3 > zzd5 && zzd3 > zzd1 && zzd5 > zzd1 && nd)                   //  ВНИЗУ
                    {
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Blue;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi6].Time, zzd6));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi5].Time, zzd5));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi4].Time, zzd4));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi3].Time, zzd3));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi2].Time, zzd2));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzi1].Time, zzd1));
                        if (posGuidSell == Guid.Empty)
                        {
                            frUp0 = frUp;
                            var result207 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1,
                                                                     Stops.InPips(SL1, null), null, mgS);
                            if (result207.IsSuccessful)
                            {
                                posGuidSell = result207.Position.Id;
                            }
                        }
                    }
                }
            }
        }
예제 #26
0
      protected override void NewBar()
      {
          _wprInd3.ReInit();
          if (_ftoInd.Ma2Series[Bars.Range.To - 1] > 0)
          {
              isF = true;
          }
          else
          {
              isF = false;
          }
          if (_ftoInd.Ma1Series[Bars.Range.To - 1] < _ftoInd.Ma2Series[Bars.Range.To - 1] && _ftoInd.Ma1Series[Bars.Range.To - 2] > _ftoInd.Ma2Series[Bars.Range.To - 2])
          {
              isFU = true;
          }
          else
          {
              isFU = false;
          }
          if (_ftoInd.Ma1Series[Bars.Range.To - 1] > _ftoInd.Ma2Series[Bars.Range.To - 1] && _ftoInd.Ma1Series[Bars.Range.To - 2] < _ftoInd.Ma2Series[Bars.Range.To - 2])
          {
              isFD = true;
          }
          else
          {
              isFD = false;
          }
          if (C1 > L1 && !PrD)
          {
              PrD = true;                      // Пересечение PrD=ВНИЗ или PrU=ВВЕРХ
          }
          if (C1 < H1 && !PrU)
          {
              PrU = true;
          }

          O1    = Bars[Bars.Range.To - 1].Open;
          C1    = Bars[Bars.Range.To - 1].Close;
          DTime = Bars[Bars.Range.To - 1].Time;

          if (DTime.Hour == 00 && DTime.Minute == 00)
          {
              PrD = true; PrU = true;
              var highestIndex = Series.Highest(Bars.Range.To, 288, PriceMode.High);
              var highestPrice = Bars[highestIndex].High;
              H1 = highestPrice;
              var lowestIndex = Series.Lowest(Bars.Range.To, 288, PriceMode.Low);
              var lowestPrice = Bars[lowestIndex].Low;
              L1          = lowestPrice;
              Line1.Price = H1;
              Line1.Text  = string.Format("{0}", Math.Round((H1 - L1) * 100000, 0));
              Line2.Price = L1;
          }

          if (C1 > H1 && DTime.Minute == 00 && PrU)
          {
              PrU = false;
              var toolVerticalLine = Tools.Create <VerticalLine>();
              toolVerticalLine.Time  = Bars[Bars.Range.To - 1].Time;
              toolVerticalLine.Color = Color.Red;
              var result3 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1, Stops.InPips(200, 600), null, null);
              if (result3.IsSuccessful)
              {
                  posGuidBuy = result3.Position.Id;
              }
          }

          if (C1 < L1 && DTime.Minute == 00 && PrD)
          {
              PrD = false;
              var toolVerticalLine = Tools.Create <VerticalLine>();
              toolVerticalLine.Time  = Bars[Bars.Range.To - 1].Time;
              toolVerticalLine.Color = Color.Blue;
              var result2 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1, Stops.InPips(200, 600), null, null);
              if (result2.IsSuccessful)
              {
                  posGuidSell = result2.Position.Id;
              }
          }

          if (isFU && posGuidBuy != Guid.Empty)
          {
              var res1 = Trade.CloseMarketPosition(posGuidBuy); if (res1.IsSuccessful)
              {
                  posGuidBuy = Guid.Empty;
              }
          }
          if (isFD && posGuidSell != Guid.Empty)
          {
              var res2 = Trade.CloseMarketPosition(posGuidSell); if (res2.IsSuccessful)
              {
                  posGuidSell = Guid.Empty;
              }
          }
      }
예제 #27
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();
//=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }

//=== Закрытие всех ордеров если пятница 16:00 (19:00 Kiev) ===========================================================================
            if (Bars[Bars.Range.To - 1].Time.DayOfWeek == DayOfWeek.Friday && Bars[Bars.Range.To - 1].Time.Hour == 16)
            {
                zzu5 = 0; zzu4 = 0; zzu3 = 0; zzu2 = 0; zzu1 = 0; zzd5 = 0; zzd4 = 0; zzd3 = 0; zzd2 = 0; zzd1 = 0;
                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.Active)
                {
                    var res = Trade.CloseMarketPosition(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 (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                {
                    var res = Trade.CancelPendingPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }
//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                if (zzd5 != 0 && zzd4 != 0 && zzd3 != 0 && zzd2 != 0 && zzd1 != 0)
                {
                    torg = true;
                }
                else
                {
                    torg = false;
                }
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;
//====== ВВЕРХУ ПИК =====================================================================================================================
                if (zz3 < zz2 && zz2 > zz1)
                {                 // ВВЕРХУ
                    zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("ВВЕРХ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
                    vy.Time = Bars[Bars.Range.To - 111111].Time;
                    sv      = 0;
                    for (int i = zzd1; i > zzd2; i--)
                    {
                        sv = sv + Bars[i].TickCount;
                    }
                    av5 = av4; av4 = av3; av3 = av2; av2 = av1; av1 = Math.Round(sv / (zzd1 - zzd2), 0);

                    var toolText1 = Tools.Create <Text>();
                    toolText1.Point    = new ChartPoint(Bars[zzd1 - 1].Time, Bars[zzd1].High + 0.001);
                    toolText1.FontSize = 10;
                    toolText1.Caption  = string.Format("{0}", av1);

                    if (zzu1 > zzu2 &&
                        zzu3 > zzu2 &&
                        zzu3 > zzu1 &&
                        zzu3 > zzu4 &&
                        zzu4 > zzu1
                        )                         // ВВЕРХУ
                    {
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Red;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd5].Time, Bars[zzd5].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd4].Time, Bars[zzd4].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd3].Time, Bars[zzd3].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd2].Time, Bars[zzd2].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd1].Time, Bars[zzd1].High));

                        if (av1 > av3 && av2 > av4)
                        {
                            if (torg && posGuidSell == Guid.Empty)
                            {
                                var result2 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1, Stops.InPips(SL, TP), null, null);
                                if (result2.IsSuccessful)
                                {
                                    posGuidSell = result2.Position.Id;
                                }
                            }
                        }
                        else
                        {
                            if (torg && posGuidBuy == Guid.Empty)
                            {
                                var result1 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1, Stops.InPips(SL, TP), null, null);
                                if (result1.IsSuccessful)
                                {
                                    posGuidBuy = result1.Position.Id;
                                }
                            }
                        }
                    }
                }
//==== ВНИЗУ ПИК ======================================================================================================================
                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu5 = zzu4; zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("НИЗ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
                    vy.Time = Bars[Bars.Range.To - 1].Time;

                    sv = 0;
                    for (int i = zzd1; i > zzd2; i--)
                    {
                        sv = sv + Bars[i].TickCount;
                    }
                    av5 = av4; av4 = av3; av3 = av2; av2 = av1; av1 = Math.Round(sv / (zzd1 - zzd2), 0);

                    var toolText2 = Tools.Create <Text>();
                    toolText2.Point    = new ChartPoint(Bars[zzd1 - 1].Time, Bars[zzd1 - 1].Low);
                    toolText2.FontSize = 10;
                    toolText2.Caption  = string.Format("{0}", av1);

                    if (zzu1 > zzu3 &&
                        zzu2 > zzu1 &&
                        zzu2 > zzu3 &&
                        zzu4 > zzu3 &&
                        zzu2 > zzu4 &&
                        zzu1 > zzu4
                        )                  //  ВНИЗУ
                    {
                        var toolPolyLine = Tools.Create <PolyLine>();
                        toolPolyLine.Color = Color.Blue;
                        toolPolyLine.Width = 4;
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd5].Time, Bars[zzd5].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd4].Time, Bars[zzd4].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd3].Time, Bars[zzd3].Low));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd2].Time, Bars[zzd2].High));
                        toolPolyLine.AddPoint(new ChartPoint(Bars[zzd1].Time, Bars[zzd1].Low));

                        if (av1 > av3 && av2 > av4)
                        {
                            if (torg && posGuidBuy == Guid.Empty)
                            {
                                var result3 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1, Stops.InPips(SL, TP), null, null);
                                if (result3.IsSuccessful)
                                {
                                    posGuidBuy = result3.Position.Id;
                                }
                            }
                        }
                        else
                        {
                            if (torg && posGuidSell == Guid.Empty)
                            {
                                var result4 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1, Stops.InPips(SL, TP), null, null);
                                if (result4.IsSuccessful)
                                {
                                    posGuidSell = result4.Position.Id;
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #28
0
//===============================================================================================================================
        protected override void NewBar()
        {
 			_wprInd3.ReInit();
			 _wprInd50.ReInit();
			stML=_stoInd.MainLine[Bars.Range.To-1];
			//Print("{0} - {1}",Bars[Bars.Range.To-1].Time,stML);
//=== КОРЕКЦИЯ ===========================================================================================================							 
			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;  
			
//=== Закрытие всех ордеров если пятница 16:00 (19:00 Kiev) ===========================================================================
			
          if ( Bars[Bars.Range.To-1].Time.DayOfWeek==DayOfWeek.Friday && Bars[Bars.Range.To-1].Time.Hour==16 ) 
		  { z50_3=0;z50_2=0;z50_1=0; torg=false;
		    zzu5=0;zzu4=0;zzu3=0;zzu2=0;zzu1=0; 
			zzd5=0;zzd4=0;zzd3=0;zzd2=0;zzd1=0;
			  if (posGuidBuy!=Guid.Empty) 
			{var res = Trade.CloseMarketPosition(posGuidBuy); if (res.IsSuccessful) posGuidBuy = Guid.Empty; }
			if (posGuidSell!=Guid.Empty) 
			{var res = Trade.CloseMarketPosition(posGuidSell); if (res.IsSuccessful) posGuidSell = Guid.Empty;}	
		  } 
		  if ( Bars[Bars.Range.To-1].Time.DayOfWeek==DayOfWeek.Monday && Bars[Bars.Range.To-1].Time.Hour==01 )  torg=true;
		
//======================================================================================================================================
		  if( _wprInd50.MainIndicatorSeries[Bars.Range.To-1]>0) 
			{ vb.Time=Bars[Bars.Range.To-1].Time;
				z50_3=z50_2; z50_2=z50_1;
			   z50_1 =_wprInd50.MainIndicatorSeries[Bars.Range.To-1];
				if (z50_3<z50_2 && z50_1<z50_2) { torgD=true; 
					var	vb1 = Tools.Create<VerticalLine>();
							vb1.Color=Color.Violet;
				vb1.Width=3;
				vb1.Time=Bars[Bars.Range.To-1].Time;}
				if (z50_3>z50_2 && z50_1>z50_2) { torgU=true;
				
				var	vb1 = Tools.Create<VerticalLine>();
							vb1.Color=Color.Purple;
				vb1.Width=3;
				vb1.Time=Bars[Bars.Range.To-1].Time;}
				
			}
//======================================================================================================================================
			if (posGuidBuy!=Guid.Empty && z50_1<z50_2) 
			{var res = Trade.CloseMarketPosition(posGuidBuy); if (res.IsSuccessful) posGuidBuy = Guid.Empty;}
			if (posGuidSell!=Guid.Empty && z50_1>z50_2) 
			{var res = Trade.CloseMarketPosition(posGuidSell); if (res.IsSuccessful) posGuidSell = Guid.Empty;}				
//======================================================================================================================================
/*			if (posGuidBuy!=Guid.Empty && Trade.GetPosition(posGuidBuy).Pips>40) 
			{var res = Trade.UpdateMarketPosition(posGuidBuy,Trade.GetPosition(posGuidBuy).OpenPrice, null, null); if (res.IsSuccessful) posGuidBuy = Guid.Empty;}
			if (posGuidSell!=Guid.Empty && Trade.GetPosition(posGuidBuy).Pips>40) 
			{var res = Trade.UpdateMarketPosition(posGuidSell,Trade.GetPosition(posGuidBuy).OpenPrice, null, null); if (res.IsSuccessful) posGuidSell = Guid.Empty;}			
*/
//======================================================================================================================================
			if( _wprInd3.MainIndicatorSeries[Bars.Range.To-1]>0) 
			{    if(zzd5!=0 && zzd4!=0 && zzd3!=0 && zzd2!=0 && zzd1!=0) torg=true; else torg=false;
				 zz3 =zz2;	 zz2 =zz1;   zz1 =_wprInd3.MainIndicatorSeries[Bars.Range.To-1];
				 zzi3=zzi2;	 zzi2=zzi1;  zzi1= Bars.Range.To-1;
//====== ВВЕРХУ ПИК =====================================================================================================================
				if(zz3<zz2 && zz2>zz1)  
				{ // ВВЕРХУ
					zzd5=zzd4; zzd4=zzd3; zzd3=zzd2; zzd2=zzd1; zzd1=zzi2; 
					zzu5=zzu4; zzu4=zzu3; zzu3=zzu2; zzu2=zzu1; zzu1=zz2;
			    	vy.Time=Bars[Bars.Range.To-111111].Time;
					
			if (posGuidBuy!=Guid.Empty && zzb>zzu1) 
			{var res = Trade.CloseMarketPosition(posGuidBuy); if (res.IsSuccessful) posGuidBuy = Guid.Empty;}

					

					 // ВВЕРХУ
							
							if(stML<20.0 && torgD && torg && posGuidSell==Guid.Empty){ torgD=false;
								var result2 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1,Instrument.Ask, -1,Stops.InPips(SL,TP), null, null);
								if (result2.IsSuccessful)  { posGuidSell=result2.Position.Id; zzs=zzu1; }
						       } 
						
				}				
//==== ВНИЗУ ПИК ======================================================================================================================				
				if(zz3>zz2 && zz2<zz1)  
				{ // ВНИЗУ
					zzd5=zzd4; zzd4=zzd3; zzd3=zzd2; zzd2=zzd1; zzd1=zzi2;
					zzu5=zzu4; zzu4=zzu3; zzu3=zzu2; zzu2=zzu1; zzu1=zz2; 
					vy.Time=Bars[Bars.Range.To-1].Time;

			if (posGuidSell!=Guid.Empty && zzs<zzu1) 
			{var res = Trade.CloseMarketPosition(posGuidSell); if (res.IsSuccessful) posGuidSell = Guid.Empty;}
			
					//  ВНИЗУ
						   
							if(stML>80.0 && torgU && torg && posGuidBuy==Guid.Empty){ torgU=false;
								Print("{0}",Bars[)
예제 #29
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _wprInd.ReInit();


//=== КОРЕКЦИЯ ===========================================================================================================
            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;
            }

// Значение счетчика прохода фишера через 0  FU - вверх  FD - вниз
//		    if ( _ftoInd.FisherSeries[Bars.Range.To-2]<0  &&  _ftoInd.FisherSeries[Bars.Range.To-1]>0)  isFU=true;  else isFU=false;
//			if ( _ftoInd.FisherSeries[Bars.Range.To-2]>0  &&  _ftoInd.FisherSeries[Bars.Range.To-1]<0)   isFD=true;  else isFD=false;

//========  isFM2U isFM2D - красная линия пересекла линию фишера
            // Sell stop <0
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] < _ftoInd.Ma2Series[Bars.Range.To - 2] && _ftoInd.FisherSeries[Bars.Range.To - 1] > _ftoInd.Ma2Series[Bars.Range.To - 1])
            {
                isFU = true;
            }
            else
            {
                isFU = false;
            }
            //  Buy stop >0
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] > _ftoInd.Ma2Series[Bars.Range.To - 2] && _ftoInd.FisherSeries[Bars.Range.To - 1] < _ftoInd.Ma2Series[Bars.Range.To - 1])
            {
                isFD = true;
            }
            else
            {
                isFD = false;
            }

//=== Закрытие всех ордеров если пятница 16:00 (19:00 Kiev) ===========================================================================
            if (Bars[Bars.Range.To - 1].Time.DayOfWeek == DayOfWeek.Friday && Bars[Bars.Range.To - 1].Time.Hour == 16)
            {
                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.Active)
                {
                    var res = Trade.CloseMarketPosition(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 (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                {
                    var res = Trade.CancelPendingPosition(posGuidSell); if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }
//=== Если фишер пересек линию - закрыть все ордера  =================================================================================
            if (isFD)
            {
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Active)
                {
                    var res1 = Trade.CloseMarketPosition(posGuidBuy); if (res1.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending)
                {
                    var res2 = Trade.CancelPendingPosition(posGuidBuy); if (res2.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
            }
            if (isFU)
            {
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Active)
                {
                    var res3 = Trade.CloseMarketPosition(posGuidSell); if (res3.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending)
                {
                    var res4 = Trade.CancelPendingPosition(posGuidSell); if (res4.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
            }
//======================================================================================================================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3  = zz2;       zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                zzi3 = zzi2;      zzi2 = zzi1;  zzi1 = Bars.Range.To - 1;

                if (zz3 < zz2 && zz2 > zz1)
                {                 // ВВЕРХУ
                    zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("ВВЕРХ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
                    if (zzu1 > zzu2 && zzu3 > zzu2 && zzu1 > zzu3 && zzu2 > zzu4 && zzu3 > zzu4)          // ВВЕРХУ
                    {
                        var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Red; vr.Time = Bars[zzd1].Time;
                        if (posGuidSell == Guid.Empty)
                        {
                            var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1, zzu1 + Instrument.Spread - 0.0002, 0, Stops.InPips(200, 100), null, null, null);
                            // var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1,  zzu1+Instrument.Spread-0.0002, 0, Stops.InPips(200,null), null, null, null);
                            if (result1.IsSuccessful)
                            {
                                posGuidSell = result1.Position.Id; zzts2 = zzu2;
                            }
                        }
                    }
                }

                if (zz3 > zz2 && zz2 < zz1)
                {                 // ВНИЗУ
                    zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zzi2;
                    zzu4 = zzu3; zzu3 = zzu2; zzu2 = zzu1; zzu1 = zz2;
                    Print("НИЗ {0} 1={1} 2={2} 3={3} 4={4}", Bars[zzd1].Time, zzu1, zzu2, zzu3, zzu4);
                    if (zzu4 > zzu2 && zzu3 > zzu1 && zzu2 > zzu3 && zzu4 > zzu3)            //  ВНИЗУ
                    {
                        var vr = Tools.Create <VerticalLine>(); vr.Color = Color.Blue; vr.Time = Bars[zzd1].Time;
                        if (posGuidBuy == Guid.Empty)
                        {
                            var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, zzu1 - Instrument.Spread + 0.0002, 0, Stops.InPips(200, 100), null, null, null);
                            // var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1, zzu1-Instrument.Spread+0.0002, 0, Stops.InPips(200,null), null, null, null);
                            if (result.IsSuccessful)
                            {
                                posGuidBuy = result.Position.Id; zztb2 = zzu2;
                            }
                        }
                    }
                }

                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Pending && Bars[Bars.Range.To - 1].Low < zzts2)
                {
                    var res = Trade.CancelPendingPosition(posGuidSell);
                    if (res.IsSuccessful)
                    {
                        posGuidSell = Guid.Empty;
                    }
                }
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Pending && Bars[Bars.Range.To - 1].High > zztb2)
                {
                    var res = Trade.CancelPendingPosition(posGuidBuy);
                    if (res.IsSuccessful)
                    {
                        posGuidBuy = Guid.Empty;
                    }
                }
            }
        }
예제 #30
0
        protected override void Init()
        {       //dt1=Bars[Bars.Range.To-1].Time;
            k = 0;
            _wprInd.ReInit();
            dt1 = dt1.AddHours(-3);
            iFT = TimeToIndex(dt1, Timeframe);

            //Print("Init - {0} - {1} - {2} - k={3}",dt1,Bars[Bars.Range.To-1].Time,Bars[iFT].Time,k);

            //toolPolyLine = Tools.Create<PolyLine>(); toolPolyLine.Color=Color.Aqua;
            toolRectangle  = Tools.Create <Rectangle>(); toolRectangle.BorderColor = Color.Aqua; toolRectangle.Color = Color.DarkSeaGreen;
            toolRectangle1 = Tools.Create <Rectangle>(); toolRectangle1.BorderColor = Color.Aqua; toolRectangle1.Color = Color.DarkSeaGreen;
            //toolRectangle2 = Tools.Create<Rectangle>(); toolRectangle1.BorderColor=Color.Aqua; toolRectangle1.Color=Color.DarkSeaGreen;

            _frInd           = GetIndicator <Fractals>(Instrument.Id, Timeframe);
            first            = true;
            _wprInd          = GetIndicator <ZigZag>(Instrument.Id, Timeframe);
            _wprInd.ExtDepth = 5;
            // 15/05/2018
            if (Instrument.Name == "EURUSD")
            {
                NKZ = 462;
            }
            if (Instrument.Name == "GBPUSD")
            {
                NKZ = 792;
            }
            if (Instrument.Name == "AUDUSD")
            {
                NKZ = 343;
            }
            if (Instrument.Name == "NZDUSD")
            {
                NKZ = 357;
            }
            if (Instrument.Name == "USDJPY")
            {
                NKZ = 527;
            }
            if (Instrument.Name == "USDCAD")
            {
                NKZ = 491;
            }
            if (Instrument.Name == "USDCHF")
            {
                NKZ = 608;
            }
            if (Instrument.Name == "AUDJPY")
            {
                NKZ = 550;
            }
            if (Instrument.Name == "AUDNZD")
            {
                NKZ = 412;
            }
            if (Instrument.Name == "CHFJPY")
            {
                NKZ = 1430;
            }
            if (Instrument.Name == "EURAUD")
            {
                NKZ = 682;
            }
            if (Instrument.Name == "AUDCAD")
            {
                NKZ = 357;
            }
            if (Instrument.Name == "EURCAD")
            {
                NKZ = 762;
            }
            if (Instrument.Name == "EURCHF")
            {
                NKZ = 539;
            }
            if (Instrument.Name == "EURGBP")
            {
                NKZ = 484;
            }
            if (Instrument.Name == "EURJPY")
            {
                NKZ = 715;
            }
            if (Instrument.Name == "GBPCHF")
            {
                NKZ = 924;
            }
            if (Instrument.Name == "GBPJPY")
            {
                NKZ = 1045;
            }
        }