Example #1
0
        protected override void OnTick()
        {
            int last = MarketSeries.Close.Count - 1;

            if (!(MarketSeries.Open[last] == MarketSeries.High[last] && MarketSeries.Open[last] == MarketSeries.Low[last]))
            {
                return;                                                                                                        // проверка на начало бара
            }
            // Закрытие позиции
            if (IsOpenPos)
            {
                if ((pos.TradeType == TradeType.Buy && MarketSeries.Close[last - 1] < bb.Main[last - 1]) || (pos.TradeType == TradeType.Sell && MarketSeries.Close[last - 1] > bb.Main[last - 1]))
                {
                    Trade.Close(pos);
                }
            }
            // открытие пщзиций
            if (!IsOpenPos)
            {
                // открытие длинной позиции
                if (MarketSeries.Close[last - 2] < bb.Top[last - 1] && MarketSeries.Close[last - 1] > bb.Top[last - 1] && sma.Result[last - 1] > sma.Result[last - 4])
                {
                    Trade.CreateBuyMarketOrder(Symbol, vol);
                    IsOpenPos = true;
                }
                // открытие короткой позиции
                if (MarketSeries.Close[last - 2] > bb.Bottom[last - 1] && MarketSeries.Close[last - 1] < bb.Bottom[last - 1] && sma.Result[last - 1] < sma.Result[last - 4])
                {
                    Trade.CreateSellMarketOrder(Symbol, vol);
                    IsOpenPos = true;
                }
            }
        }
Example #2
0
        protected override void OnTick()
        {
            int last = MarketSeries.Close.Count - 1;

            if (!(MarketSeries.Open[last] == MarketSeries.High[last] && MarketSeries.Open[last] == MarketSeries.Low[last]))
            {
                return;
            }
            double per = percertron();

            if (!IsPosOpen)
            {
                if (per > 0)
                {
                    Trade.CreateBuyMarketOrder(Symbol, Volume); IsPosOpen = true;
                }
                if (per < 0)
                {
                    Trade.CreateSellMarketOrder(Symbol, Volume); IsPosOpen = true;
                }
            }
            else
            {
                if (pos.TradeType == TradeType.Buy && per < 0)
                {
                    Trade.Close(pos);
                    Trade.CreateSellMarketOrder(Symbol, Volume);
                    return;
                }
                else
                {
                    if (Symbol.Ask > sl + StopLoss * 2 * Symbol.PointSize)
                    {
                        Trade.ModifyPosition(pos, Symbol.Ask - StopLoss * Symbol.PointSize, 0);
                    }
                }
                if (pos.TradeType == TradeType.Sell && per > 0)
                {
                    Trade.Close(pos);
                    Trade.CreateBuyMarketOrder(Symbol, Volume);
                }
                else
                {
                    if (Symbol.Bid < sl - StopLoss * 2 * Symbol.PointSize)
                    {
                        Trade.ModifyPosition(pos, Symbol.Bid + StopLoss * Symbol.PointSize, 0);
                    }
                }
            }
        }
Example #3
0
        private void ControlSeries()
        {
            int _pipstep, NewVolume, Rem;
            int BarCount = 25;
            int Del      = MaxOrders - 1;

            if (PipStep == 0)
            {
                _pipstep = GetDynamicPipstep(BarCount, Del);
            }
            else
            {
                _pipstep = PipStep;
                //_pipstep = (PipStep * PipStart * (Account.Positions.Count) / PipMulti);
            }



            if (Account.Positions.Count < MaxOrders)
            {
                switch (GetPositionsSide())
                {
                case 0:
                    if (Symbol.Ask < FindLastPrice(TradeType.Buy) - _pipstep * Symbol.PointSize)
                    {
                        NewVolume = Math.DivRem((int)(FirstLot + FirstLot * Account.Positions.Count), LotStep, out Rem) * LotStep;
                        if (!(NewVolume < LotStep) && GetStdIlanSignal() == 1)
                        {
                            Trade.CreateBuyMarketOrder(Symbol, NewVolume);
                            TotalBuy += NewVolume;
                        }
                    }
                    break;

                case 1:
                    if (Symbol.Bid > FindLastPrice(TradeType.Sell) + _pipstep * Symbol.PointSize)
                    {
                        NewVolume = Math.DivRem((int)(FirstLot + FirstLot * Account.Positions.Count), LotStep, out Rem) * LotStep;
                        if (!(NewVolume < LotStep) && GetStdIlanSignal() == 0)
                        {
                            Trade.CreateSellMarketOrder(Symbol, NewVolume);
                            TotalBuy += NewVolume;
                        }
                    }
                    break;
                }
            }
        }
Example #4
0
        private void SendFirstOrder(int OrderVolume)
        {
            int Signal = GetStdIlanSignal();

            if (!(Signal < 0))
            {
                switch (Signal)
                {
                case 0:
                    Trade.CreateBuyMarketOrder(Symbol, OrderVolume);
                    break;

                case 1:
                    Trade.CreateSellMarketOrder(Symbol, OrderVolume);
                    break;
                }
            }
        }
Example #5
0
        protected override void OnTick()
        {
            foreach (var position in Positions)
            {
                long     elapsedTicks = Server.Time.Ticks - position.EntryTime.Ticks;
                TimeSpan elapsedSpan  = new TimeSpan(elapsedTicks);

                if (elapsedSpan.TotalSeconds > 60 * MaxTimeOpen)
                {
                    ClosePosition(position);
                }
            }

            int last = MarketSeries.Close.Count - 1;

            if (!(MarketSeries.Open[last] == MarketSeries.High[last] && MarketSeries.Open[last] == MarketSeries.Low[last]))
            {
                return;
            }
            if (dt.Date != Server.Time.Date)
            {
                StartBalanse = Account.Balance;
                dt           = Server.Time;
            }

            double bp = (StartBalanse - Account.Balance) / (StartBalanse / 100);

            if (bp > 0 && bp >= MaxDropDown && MaxDropDown != 0)
            {
                return;
            }

            if (bp < 0 && Math.Abs(bp) >= MaxProfit && MaxProfit != 0)
            {
                return;
            }

            if (BarCount < 1)
            {
                Print("Few bars for trend analysis. BarCount must be greater than or equal to 1");
                return;
            }
            if (PosOpen < MaxOrders)
            {
                if (OpenIndex == 0 || last - OpenIndex > BarCount)
                {
                    if (IsBuy(last))
                    {
                        Trade.CreateBuyMarketOrder(Symbol, Volume);
                        PosOpen++;
                        OpenIndex = last;
                    }
                    if (IsSell(last))
                    {
                        Trade.CreateSellMarketOrder(Symbol, Volume);
                        PosOpen++;
                        OpenIndex = last;
                    }
                }
            }
        }
Example #6
0
 private void Buy()
 {
     Trade.CreateBuyMarketOrder(Symbol, Volume);
 }
Example #7
0
        protected override void OnTick()
        {
            int    bars = MarketSeries.Close.Count - 1;
            double cl1  = MarketSeries.Close[bars - 1];
            double cl2  = MarketSeries.Close[bars - 2];

            double MA1  = MA.Result[MA.Result.Count - 2];
            double MA2  = MA.Result[MA.Result.Count - 3];
            double WPR1 = WPR.Result[WPR.Result.Count - 2];
            double St11 = St1.PercentK[St1.PercentK.Count - 2];
            double St21 = St1.PercentD[St1.PercentD.Count - 2];
            double St12 = St2.PercentD[St2.PercentD.Count - 2];

            double Bid   = Symbol.Bid;
            double Ask   = Symbol.Ask;
            double Point = Symbol.PointSize;

            if (Trade.IsExecuting)
            {
                return;
            }

            if (WPR1 > -50 && cl1 > MA1 && cl2 <= MA2 && St11 > St21 && St12 > 20 && a == 0)
            {
                Trade.CreateBuyMarketOrder(Symbol, Vol);
                Print("Trade BUY was successfully open");
                a = 1;
            }

            if (WPR1 < -50 && cl1 < MA1 && cl2 >= MA2 && St11 < St21 && St12 < 80 && a == 0)
            {
                Trade.CreateSellMarketOrder(Symbol, Vol);
                Print("Trade SELL was successfully open");
                a = 1;
            }

            foreach (var position in Account.Positions)
            {
                if (position.SymbolCode == Symbol.Code)
                {
                    if (position.TradeType == TradeType.Buy)
                    {
                        if (Bid - position.EntryPrice >= Tral_Start * Point)
                        {
                            if (Bid - Tral_Stop * Point >= position.StopLoss)
                            {
                                Trade.ModifyPosition(position, Bid - Tral_Stop * Point, position.TakeProfit);
                            }
                        }
                    }

                    if (position.TradeType == TradeType.Sell)
                    {
                        if (position.EntryPrice - Ask >= Tral_Start * Point)
                        {
                            if (Ask + Tral_Stop * Point <= position.StopLoss)
                            {
                                Trade.ModifyPosition(position, Ask + Tral_Stop * Point, position.TakeProfit);
                            }
                        }
                    }
                }
            }
        }