Example #1
0
 private void ClosePrev()
 {
     foreach (Position position in Account.Positions.Where(position => position.Label == Label && position.SymbolCode == Symbol.Code))
     {
         Trade.Close(position);
     }
 }
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;                                                                                                        // проверка на начало бара
            }
            // Закрытие позиции
            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 #3
0
        protected override void OnBar()
        {
            if (Trade.IsExecuting)
            {
                return;
            }

            if (rsi.Result.LastValue < 25 && _position == null)
            {
                OpenPosition(TradeType.Buy);
            }

            if (rsi.Result.LastValue > 75 && _position == null)
            {
                OpenPosition(TradeType.Sell);
            }
            if (_position != null)
            {
                if (_position.TradeType == TradeType.Buy && rsi.Result.LastValue > 55)
                {
                    Trade.Close(_position);
                }

                if (_position.TradeType == TradeType.Sell && rsi.Result.LastValue < 45)
                {
                    Trade.Close(_position);
                }
            }
        }
Example #4
0
 /// <summary>
 /// Close Position
 /// </summary>
 /// <param name="pos"></param>
 private void ClosePosition(Position pos)
 {
     if (pos == null)
     {
         return;
     }
     Trade.Close(pos);
 }
//=====================================================================================================
// functions
//=====================================================================================================
        private void ClosePosition()
        {
            if (position != null)
            {
                Trade.Close(position);
                position = null;
            }
        }
Example #6
0
 private void ClosePosition()
 {
     if (_position == null)
     {
         return;
     }
     Trade.Close(_position);
     _position = null;
 }
Example #7
0
 private void CheckBalance()
 {
     if (Account.Equity <= _startingBalance * BalancePercent)
     {
         // if you only want to close the positions of this robot change to:
         // foreach (var pos in Account.Positions).Where(position1 => position1.Label == LabelName)
         foreach (var pos in Account.Positions)
         {
             Trade.Close(pos);
         }
         Stop();
     }
 }
Example #8
0
 private void ClosePositions()
 {
     foreach (var position in Account.Positions)
     {
         if (position.Label == DragonID)
         {
             if (position.GrossProfit < 0)
             {
                 Trade.Close(position);
                 Message(2, "Closing position " + position.Id + " for $" + position.GrossProfit + " loss");
             }
         }
     }
 }
Example #9
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 #10
0
        private void OpenPosition(TradeType type)
        {
            if (_position != null)
            {
                Trade.Close(_position);
            }

            Volume = GetVolume;
            Print(Volume);
            Request request = new MarketOrderRequest(type, Volume)
            {
                Label          = "CCI 20",
                StopLossPips   = StopLoss > 0 ? StopLoss : (int?)null,
                TakeProfitPips = TakeProfit > 0 ? TakeProfit : (int?)null,
            };

            Trade.Send(request);
        }