Exemple #1
0
        protected override void NewBar()
        {
            _ichInd.ReInit();
            // Event occurs on every new bar
            // Print("ChinkouSpan={0} KijunSen={1} _ichInd.KijunSenSeries={2} SecurityExceptionOccurred={3}",_ichInd.ChinkouSpan,_ichInd.KijunSen,_ichInd.KijunSenSeries,_ichInd.SecurityExceptionOccurred);
            // Print("SenkouSpan={0} SenkouSpanASeries={1} SenkouSpanBSeries={2} TankanSen={3}",_ichInd.SenkouSpan,_ichInd.SenkouSpanASeries,_ichInd.SenkouSpanBSeries,_ichInd.TankanSen);
            // Print("TankanSenSeries={0} -- {1}",_ichInd.TankanSenSeries,Bars[Bars.Range.To-1]);
            //Print("{0} {1} {2} -- {3}",_ichInd.TankanSenSeries[Bars.Range.To-1],_ichInd.SenkouSpanASeries[Bars.Range.To-1],_ichInd.SenkouSpanBSeries[Bars.Range.To-1],Bars[Bars.Range.To-1].Time);
            tank1 = _ichInd.TankanSenSeries[Bars.Range.To - 1];
            senA1 = _ichInd.SenkouSpanASeries[Bars.Range.To - 1];
            senB1 = _ichInd.SenkouSpanBSeries[Bars.Range.To - 1];
            kij1  = _ichInd.KijunSenSeries[Bars.Range.To - 1];


            tank2 = _ichInd.TankanSenSeries[Bars.Range.To - 2];
            senA2 = _ichInd.SenkouSpanASeries[Bars.Range.To - 2];
            senB2 = _ichInd.SenkouSpanBSeries[Bars.Range.To - 2];
            kij2  = _ichInd.KijunSenSeries[Bars.Range.To - 2];

            if (tank1 >= kij1 && kij2 >= tank2)
            {
                var toolVerticalLine = Tools.Create <VerticalLine>();
                toolVerticalLine.Time  = Bars[Bars.Range.To - 1].Time;
                toolVerticalLine.Color = Color.Red;
            }
            if (tank1 <= kij1 && kij2 <= tank2)
            {
                var toolVerticalLine = Tools.Create <VerticalLine>();
                toolVerticalLine.Time  = Bars[Bars.Range.To - 1].Time;
                toolVerticalLine.Color = Color.Blue;
            }
        }
Exemple #2
0
//===============================================================================================================================
        protected override void NewBar()
        {
            _ichInd.ReInit();
            tank1 = _ichInd.TankanSenSeries[Bars.Range.To - 1];
            senA1 = _ichInd.SenkouSpanASeries[Bars.Range.To - 1];
            senB1 = _ichInd.SenkouSpanBSeries[Bars.Range.To - 1];
            kij1  = _ichInd.KijunSenSeries[Bars.Range.To - 1];

            tank2 = _ichInd.TankanSenSeries[Bars.Range.To - 2];
            kij2  = _ichInd.KijunSenSeries[Bars.Range.To - 2];
//=== КОРЕКЦИЯ ===========================================================================================================
            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) {FU=Bars.Range.To; isFU=true;} else isFU=false;
 *                      if ( _ftoInd.FisherSeries[Bars.Range.To-2]>0  &&  _ftoInd.FisherSeries[Bars.Range.To-1]<0) {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 (tank1 > kij1 && kij2 >= tank2)
            {
                isFU = true;
            }
            else
            {
                isFU = false;
            }
            if (tank1 < kij1 && kij2 <= tank2)
            {
                isFD = true;
            }
            else
            {
                isFD = false;
            }
            // Цена ВЫШЕ/НИЖЕ Senkou Span B
            if (Bars[Bars.Range.To - 1].Close > senB1)
            {
                isFMU = true;
            }
            else
            {
                isFMU = false;
            }
            if (Bars[Bars.Range.To - 1].Close < senB1)
            {
                isFMD = true;
            }
            else
            {
                isFMD = false;
            }



            // Если красная пересекла линию - закрыть все активные ордера

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

//======================================================================================================================================
            //Print("{0} - {1} - {2}>{3} - {4}",Bars[Bars.Range.To-1].Time,_barM15[_barM15.Range.To-1].Time,Fs,Fs1,F15U);


            Print("{0} - {1} {2} {3} - {4} {5} {6}", Bars[Bars.Range.To - 1].Time, isFU, isFMU, FDU, isFD, isFMD, FDD);
            if (isFU && isFMU && F1U)
            {
                var vline = Tools.Create <VerticalLine>();
                vline.Color = Color.Red;
                vline.Time  = Bars[Bars.Range.To - 1].Time;
                vline.Width = 4;
                if (posGuidSell == Guid.Empty)
                {
                    var result2 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 2.0, Instrument.Bid, -1, Stops.InPips(200, null), null, null);
                    if (result2.IsSuccessful)
                    {
                        posGuidSell = result2.Position.Id;
                    }
                }
            }


            if (isFD && isFMD && F1D)
            {
                var vline = Tools.Create <VerticalLine>();
                vline.Color = Color.Blue;
                vline.Time  = Bars[Bars.Range.To - 1].Time;
                vline.Width = 4;
                if (posGuidBuy == Guid.Empty)
                {
                    var result3 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 2.0, Instrument.Bid, -1, Stops.InPips(200, null), null, null);
                    if (result3.IsSuccessful)
                    {
                        posGuidBuy = result3.Position.Id;
                    }
                }
            }


//===============================================================================================================================
        }