Example #1
0
        public override void Stop(StopMode mode)
        {
            Historique.AjouterAction(new ActionStop(this, mode));

            _lockMove.WaitOne();

            if (mode == StopMode.Smooth)
            {
                Position nouvelleDestination = new Position(Position.Angle, new RealPoint(_currentPosition.Coordinates.X, _currentPosition.Coordinates.Y));

                if (IsInLineMove)
                {
                    if (_sensMove == SensAR.Avant)
                    {
                        nouvelleDestination.Move(GetCurrentLineBreakDistance());
                    }
                    else
                    {
                        nouvelleDestination.Move(-GetCurrentLineBreakDistance());
                    }
                }

                _destination = nouvelleDestination;
            }
            else if (mode == StopMode.Abrupt)
            {
                _currentSpeed = 0;
                _destination  = Position;
            }
            _lockMove.Release();
        }
Example #2
0
        public Stop SetStop(double level, StopType type = StopType.Fixed, StopMode mode = StopMode.Absolute)
        {
            var stop = new Stop(this.strategy, this.Position, level, type, mode);

            this.strategy.AddStop(stop);
            return(stop);
        }
Example #3
0
        /// <summary>
        /// Уведомляет серверный обработчик о завершении работы и закрывает подключение.
        /// </summary>
        protected async Task DisconnectFromHandler(Connection connection, StopMode stopMode)
        {
            bool       useExclusiveAccess = false;
            Connection usingConnection    = connection;

            if (stopMode == StopMode.Hard)
            {
                usingConnection    = mainConnection;
                useExclusiveAccess = true;
            }

            if (connection.IsConnected)
            {
                CommunicationObject comObj = new CommunicationObject(usingConnection, useExclusiveAccess);

                try
                {
                    comObj.SetData(NetSharpProtocol.Commands.STOP_HANDLER, new HandlerStopData(connection.HandlerID, stopMode));
                    await comObj.SendAsync().ConfigureAwait(false);
                }
                finally
                {
                    comObj.Dispose();
                    connection.Close();
                }
            }
        }
Example #4
0
        public Task Stop(StopMode mode = StopMode.GracefulShutdown, StopOptions options = StopOptions.StopChildren)
        {
            State = ExecutionState.Stopping;

            State = ExecutionState.Stopped;
            return(Task.CompletedTask);
        }
Example #5
0
        internal async Task StopService(StopMode stopMode)
        {
            if (cleanup)
            {
                return;
            }

            if (stopMode == StopMode.Soft)
            {
                ctSource.Cancel(true);

                try
                {
                    if (workTask != null)
                    {
                        await workTask.ConfigureAwait(false);
                    }
                }
                finally
                {
                    Cleanup();
                }
            }
            else
            {
                HardStop = true;

                connection.Close();

                Cleanup();
            }
        }
Example #6
0
        public ATSStop SetStop(Position position, double level, StopType type, StopMode mode)
        {
            ATSStop aTSStop = new ATSStop(position, level, type, mode);

            base.Strategy.AddStop(aTSStop);
            return(aTSStop);
        }
Example #7
0
		public virtual Stop AddStop(double level, StopType type, StopMode mode)
		{
			if (!this.Strategy.IsInstrumentActive(this.Position.Instrument))
				return null;
			else
				return new Stop(this.Strategy, this.Position, level, type, mode);
		}
Example #8
0
        public ATSStop SetStop(Position position, double level, StopType type, StopMode mode)
        {
            ATSStop atsStop = new ATSStop(position, level, type, mode);

            this.Strategy.nPMi9oJHY7(atsStop);
            return(atsStop);
        }
 public virtual Stop AddStop(double level, StopType type, StopMode mode)
 {
     if (!base.Strategy.IsInstrumentActive(base.Position.Instrument))
     {
         return(null);
     }
     return(new Stop(base.Strategy, base.Position, level, type, mode));
 }
Example #10
0
        public override void SetMotorStop(MotorID motor, StopMode mode)
        {
            base.SetMotorStop(motor, mode);

            Frame trame = UdpFrameFactory.MoteurStop(_boardMotor[motor], motor, mode);

            Connections.UDPBoardConnection[_boardMotor[motor]].SendMessage(trame);
        }
Example #11
0
        static public Frame MoteurStop(Board board, MotorID moteur, StopMode mode)
        {
            byte[] tab = new byte[4];
            tab[0] = (byte)board;
            tab[1] = (byte)UdpFrameFunction.MoteurStop;
            tab[2] = (byte)moteur;
            tab[3] = (byte)mode;

            return(new Frame(tab));
        }
Example #12
0
        static public Frame Stop(StopMode mode, Robot robot)
        {
            byte[] tab = new byte[3];
            tab[0] = (byte)robot.AsservBoard;
            tab[1] = (byte)UdpFrameFunction.Stop;
            tab[2] = (byte)mode;

            Frame retour = new Frame(tab);

            return(retour);
        }
Example #13
0
 public virtual Stop AddStop(double level, StopType type, StopMode mode)
 {
     if (!this.Strategy.IsInstrumentActive(this.Position.Instrument))
     {
         return(null);
     }
     else
     {
         return(new Stop(this.Strategy, this.Position, level, type, mode));
     }
 }
 public QBStop(Strategy strategy, Position position,
               PositionSide side, double qty,
               double level, StopType type, StopMode mode)
     : base(strategy, position, level, type, mode)
 {
     if (qty > 0)
     {
         this.qty = qty;
     }
     this.side = side;
 }
Example #15
0
        public override void Stop(StopMode mode = StopMode.Smooth)
        {
            AsserEnable = (mode != StopMode.Freely);

            IsInLineMove = false;

            Frame frame = UdpFrameFactory.Stop(mode, this);

            _asserConnection.SendMessage(frame);

            Historique.AjouterAction(new ActionStop(this, mode));
        }
Example #16
0
        /// <summary>
        /// Forces the Logging thread to stop completely.
        /// At a maximum, it will take checkPeriod to stop.
        /// </summary>
        /// <returns><c>true</c>, If Logging thread stopped within timeout, <c>false</c> otherwise.</returns>
        /// <param name="timeout">Time to wait for Logging thread to stop. -1 forever.</param>
        public static bool ForceStop(int timeout)
        {
            _stopMode = StopMode.ForceStop;

            if (_waitStopSemaphore.Wait (timeout))
            {
                _waitStopSemaphore.Release ();
                return true;
            }

            return false;
        }
Example #17
0
 internal Stop(Position position, double level, StopType type, StopMode mode)
 {
     this.position = position;
     FreeQuant.Trading.StopType stopType = EnumConverter.Convert(type);
     FreeQuant.Trading.StopMode stopMode = EnumConverter.Convert(mode);
     this.stop = new ATSStop(position.position, level, stopType, stopMode);
     ((StopBase)this.stop).TrailOnHighLow = true;
     ((StopBase)this.stop).TraceOnBarOpen = true;
     ((StopBase)this.stop).TraceOnBar     = true;
     ((StopBase)this.stop).TraceOnQuote   = true;
     ((StopBase)this.stop).TraceOnTrade   = true;
 }
Example #18
0
 internal Stop(Position position, double level, StopType type, StopMode mode)
 {
     this.position = position;
     SmartQuant.Trading.StopType type2 = EnumConverter.Convert(type);
     SmartQuant.Trading.StopMode mode2 = EnumConverter.Convert(mode);
     this.stop = new ATSStop(position.position, level, type2, mode2);
     this.stop.TrailOnHighLow = true;
     this.stop.TraceOnBarOpen = true;
     this.stop.TraceOnBar     = true;
     this.stop.TraceOnQuote   = true;
     this.stop.TraceOnTrade   = true;
 }
        internal void StopHandler(Guid handlerID, StopMode stopMode)
        {
            ConnectingHandler handler;

            if (handlers.TryGetValue(handlerID, out handler))
            {
                incompleteTasksHandlers.Add(handler.StopService(stopMode));
            }
            else
            {
                Logger.Write(Source.Server, $"Ошибка остановки обработчика: обработчик с ID {handlerID} не найден.");
            }
        }
Example #20
0
        // Запрет добавления элементов
        // и ожидание завершения обработки содержимого очереди.
        public async Task DrainAsync()
        {
            lock (this)
            {
                if (_stopMode == StopMode.None)
                {
                    _stopMode = StopMode.Drain;
                }
                _tcs.TrySetResult(null);
            }

            await _task;
        }
        internal static SmartQuant.Trading.StopMode Convert(StopMode stopMode)
        {
            switch (stopMode)
            {
            case StopMode.Absolute:
                return(SmartQuant.Trading.StopMode.Absolute);

            case StopMode.Percent:
                return(SmartQuant.Trading.StopMode.Percent);

            default:
                throw new NotImplementedException("Stop mode is not supported : " + stopMode);
            }
        }
        /// <summary>
        /// 根据入场后的最高与最低价,跟踪止损
        /// </summary>
        /// <param name="currentPrice"></param>
        /// <param name="level"></param>
        /// <param name="mode"></param>
        /// <returns>止损了返止损前持仓,可用于后面的反手</returns>
        public virtual double TrailingStop(double currentPrice, double level, StopMode mode, string text)
        {
            //lock(this)
            {
                double qty = GetCurrentQty();
                double stop;
                if (qty > double.Epsilon)
                {
                    if (StopMode.Percent == mode)
                    {
                        stop = HighestAfterEntry * (1.0 - level);
                    }
                    else
                    {
                        stop = HighestAfterEntry - level;
                    }
                    if (currentPrice < stop)
                    {
                        TargetPosition     = 0;
                        TextParameter.Text = string.Format("跟踪止损 - 最高{0},止损{1}>当前{2}|{3}",
                                                           HighestAfterEntry, stop, currentPrice,
                                                           text);
                        return(qty);
                    }
                }
                else if (qty < -double.Epsilon)
                {
                    if (StopMode.Percent == mode)
                    {
                        stop = LowestAfterEntry * (1.0 + level);
                    }
                    else
                    {
                        stop = LowestAfterEntry + level;
                    }

                    if (currentPrice > stop)
                    {
                        TargetPosition     = 0;
                        TextParameter.Text = string.Format("跟踪止损 - 最低{0},止损{1}<当前{2}|{3}",
                                                           HighestAfterEntry, stop, currentPrice,
                                                           text);
                        return(qty);
                    }
                }

                return(0);
            }
        }
        public virtual double TakeProfit(double currentPrice, double level, StopMode mode, string text)
        {
            //lock(this)
            {
                double qty = GetCurrentQty();
                double stop;
                if (qty > double.Epsilon)
                {
                    if (StopMode.Percent == mode)
                    {
                        stop = GetLongAvgPrice() * (1.0 + level);
                    }
                    else
                    {
                        stop = GetLongAvgPrice() + level;
                    }
                    if (currentPrice > stop)
                    {
                        TargetPosition     = 0;
                        TextParameter.Text = string.Format("固定止赢 - 多头均价{0},止赢{1}<当前{2}|{3}",
                                                           GetLongAvgPrice(), stop, currentPrice,
                                                           text);
                        return(qty);
                    }
                }
                else if (qty < -double.Epsilon)
                {
                    if (StopMode.Percent == mode)
                    {
                        stop = GetShortAvgPrice() * (1.0 - level);
                    }
                    else
                    {
                        stop = GetShortAvgPrice() - level;
                    }

                    if (currentPrice < stop)
                    {
                        TargetPosition     = 0;
                        TextParameter.Text = string.Format("固定止赢 - 空头均价{0},止赢{1}>当前{2}|{3}",
                                                           GetShortAvgPrice(), stop, currentPrice,
                                                           text);
                        return(qty);
                    }
                }
                return(0);
            }
        }
Example #24
0
    public PortfolioStop(StrategyBase strategy, DateTime time, bool stopStrategy)
			:base(){
      this.dUqRtBdT71 = StopType.Trailing;
      this.Wa9RdDJEOa = StopMode.Percent;
      this.rfci6isjj5 = StopFillMode.Stop;
      this.sKmRoRmeN5 = strategy;
      this.ElNRan0isi = strategy.Portfolio;
      this.RUQiAxBBaC = stopStrategy;
      this.dUqRtBdT71 = StopType.Time;
      this.XoERmcoQ62 = Clock.Now;
      this.xTNRf1TvWo = time;
      this.FuNRz16ilo = this.ElNRan0isi.GetValue();
      if (!(this.xTNRf1TvWo > this.XoERmcoQ62))
        return;
      Clock.AddReminder(new ReminderEventHandler(this.AaPRYK2epA), this.xTNRf1TvWo, (object) null);
    }
Example #25
0
        protected async Task DoStop(StopMode stopMode = StopMode.GracefulShutdown, StopOptions options = StopOptions.StopChildren)
        {
            DesiredExecutionState = ExecutionStateEx.Stopped;

            switch (State)
            {
            case ExecutionStateEx.Unspecified:
            case ExecutionStateEx.Uninitialized:
            case ExecutionStateEx.Faulted:
            case ExecutionStateEx.Stopped:
            //case ExecutionStateEx.Finished:
            case ExecutionStateEx.Disposed:
                return;

            case ExecutionStateEx.Initializing:
            case ExecutionStateEx.Ready:
            case ExecutionStateEx.Starting:
            case ExecutionStateEx.Started:
            case ExecutionStateEx.Pausing:
            case ExecutionStateEx.Paused:
            case ExecutionStateEx.Unpausing:
                break;

            case ExecutionStateEx.Stopping:
                break;

            default:
                throw new Exception();
            }

            SetState(ExecutionStateEx.Stopping);

            OnStopping();

            foreach (var child in Children.OfType <IStoppableEx>())
            {
                await child.Stop(stopMode, options).ConfigureAwait(false);
            }
            foreach (var child in Children.OfType <IStoppable>())
            {
                await child.Stop().ConfigureAwait(false);
            }

            SetState(ExecutionStateEx.Stopped);

            OnStopped();
        }
Example #26
0
        /// <summary>
        /// 从入场均价开始算起,固定点位止损
        /// </summary>
        /// <param name="currentPrice"></param>
        /// <param name="level"></param>
        /// <param name="mode"></param>
        /// <returns>止损了返止损前持仓,可用于后面的反手</returns>
        public virtual double FixedStop(double currentPrice, double level, StopMode mode, string text)
        {
            double qty = GetCurrentQty();
            double stop;

            if (qty > 0)
            {
                if (StopMode.Percent == mode)
                {
                    stop = GetLongAvgPrice() * (1.0 - level);
                }
                else
                {
                    stop = GetLongAvgPrice() - level;
                }
                if (currentPrice < stop)
                {
                    TargetPosition     = 0;
                    TextParameter.Text = string.Format("固定止损 - 多头均价{0},止损{1}>当前{2}|{3}",
                                                       GetLongAvgPrice(), stop, currentPrice,
                                                       text);
                    return(qty);
                }
            }
            else
            {
                if (StopMode.Percent == mode)
                {
                    stop = GetShortAvgPrice() * (1.0 + level);
                }
                else
                {
                    stop = GetShortAvgPrice() + level;
                }

                if (currentPrice > stop)
                {
                    TargetPosition     = 0;
                    TextParameter.Text = string.Format("固定止损 - 空头均价{0},止损{1}<当前{2}|{3}",
                                                       GetShortAvgPrice(), stop, currentPrice,
                                                       text);
                    return(qty);
                }
            }
            return(0);
        }
Example #27
0
 public Stop(Strategy strategy, Position position, double level, StopType type, StopMode mode)
 {
     this.strategy = strategy;
     this.position = position;
     this.instrument = position.instrument;
     this.qty = position.qty;
     this.side = position.Side;
     this.level = level;
     this.type = type;
     this.mode = mode;
     this.currPrice = this.GetInstrumentPrice();
     this.trailPrice = this.currPrice;
     this.stopPrice = this.GetStopPrice();
     this.creationTime = strategy.framework.Clock.DateTime;
     this.completionTime = DateTime.MinValue;
     this.Connect();
 }
Example #28
0
 public Stop(Strategy strategy, Position position, double level, StopType type, StopMode mode)
 {
     this.strategy       = strategy;
     this.position       = position;
     this.instrument     = position.instrument;
     this.qty            = position.qty;
     this.side           = position.Side;
     this.level          = level;
     this.type           = type;
     this.mode           = mode;
     this.currPrice      = this.GetInstrumentPrice();
     this.trailPrice     = this.currPrice;
     this.stopPrice      = this.GetStopPrice();
     this.creationTime   = strategy.framework.Clock.DateTime;
     this.completionTime = DateTime.MinValue;
     this.Connect();
 }
Example #29
0
        // Запрет добавления элементов,
        // и прерывание цикла обработки очереди
        // после завершения текущих вызовов ProcessItem и OnSuspend.
        public void Break()
        {
            lock (this)
            {
                _stopMode = StopMode.Break;
                _tcs.TrySetResult(null);
            }

            try
            {
                Task.WhenAll(_task).Wait();
            }
            catch (AggregateException e)
            {
                e.Handle(x => throw x);
            }
        }
Example #30
0
 private Stop(Strategy strategy, Position position, DateTime time, double level = 0, StopType type = StopType.Trailing, StopMode mode = StopMode.Percent)
 {
     this.strategy       = strategy;
     this.position       = position;
     this.instrument     = position.Instrument;
     this.qty            = position.Qty;
     this.side           = position.Side;
     this.type           = type;
     this.mode           = mode;
     this.creationTime   = strategy.framework.Clock.DateTime;
     this.completionTime = time;
     this.stopPrice      = GetInstrumentPrice();
     if (this.completionTime > this.creationTime)
     {
         strategy.framework.Clock.AddReminder(new Reminder(this.method_9, this.completionTime, null));
     }
 }
Example #31
0
 public PortfolioStop(StrategyBase strategy, double level, StopType type, StopMode mode, bool stopStrategy)
 {
     this.strategy       = strategy;
     this.portfolio      = strategy.Portfolio;
     this.level          = level;
     this.type           = type;
     this.mode           = mode;
     this.stopStrategy   = stopStrategy;
     this.currValue      = this.portfolio.GetValue();
     this.trailValue     = this.currValue;
     this.stopValue      = this.GetStopValue();
     this.creationTime   = Clock.Now;
     this.completionTime = DateTime.MinValue;
     this.Connect();
     this.fillValue  = this.currValue;
     this.trailValue = this.currValue;
     this.CheckStop();
 }
Example #32
0
        public void Stop(StopMode stopMode)
        {
            if (!isActive)
            {
                Debug.LogWarning("Called Stop on a non-active cutscene", gameObject);
                return;
            }

            isActive = false;
            isPaused = false;

            if (stopMode == StopMode.Skip)
            {
                Sample(playingDirection == PlayingDirection.Forwards ? playTimeMax : playTimeMin);
            }

            if (stopMode == StopMode.Rewind)
            {
                Sample(playingDirection == PlayingDirection.Forwards ? playTimeMin : playTimeMax);
            }

            if (stopMode == StopMode.Hold)
            {
                Sample();
            }

            if (stopMode == StopMode.SkipRewindNoUndo)
            {
                Sample(playingDirection == PlayingDirection.Forwards ? playTimeMax : playTimeMin);
                RewindNoUndo();
            }

            SendGlobalMessage("OnCutsceneStopped", this);
            if (OnCutsceneStopped != null)
            {
                OnCutsceneStopped(this);
            }

            if (OnStop != null)
            {
                OnStop();
                OnStop = null;
            }
        }
Example #33
0
        public void Stop(StopMode stopMode)
        {
            if (!isActive)
            {
                return;
            }

            isActive = false;
            isPaused = false;

            if (stopMode == StopMode.Skip)
            {
                Sample(playTimeMax);
            }

            if (stopMode == StopMode.Rewind)
            {
                Sample(playTimeMin);
            }

            if (stopMode == StopMode.Hold)
            {
                Sample();
            }

            if (stopMode == StopMode.SkipRewindNoUndo)
            {
                Sample(playTimeMax);
                RewindNoUndo();
            }

            SendGlobalMessage("OnCutsceneStopped", this);
            if (OnCutsceneStopped != null)
            {
                OnCutsceneStopped(this);
            }

            if (OnStop != null)
            {
                OnStop();
                OnStop = null;
            }
        }
Example #34
0
		public ATSStop(Position position, double level, StopType type, StopMode mode)	: base()
		{
			this.fPosition = position;
			this.fInstrument = position.Instrument;
			this.fQty = position.Qty;
			this.fSide = position.Side;
			this.fLevel = level;
			this.fType = type;
			this.fMode = mode;
			this.fCurrPrice = this.fInstrument.Price();
			this.fTrailPrice = this.fCurrPrice;
			this.fStopPrice = this.lkZijZtYnj();
			this.fCreationTime = Clock.Now;
			this.fCompletionTime = DateTime.MinValue;
			this.series = new DoubleSeries();
			if (this.fType == StopType.Trailing)
				this.series.Add(this.fCreationTime, this.lkZijZtYnj());
			this.Connect();
		}
Example #35
0
 public StopBase() : base()
 {
     this.fType           = StopType.Trailing;
     this.fMode           = StopMode.Percent;
     this.fTraceOnQuote   = true;
     this.fTraceOnTrade   = true;
     this.fTraceOnBar     = true;
     this.fTraceOnBarOpen = true;
     this.fTrailOnOpen    = true;
     this.fFilterBarSize  = -1L;
     this.fFilterBarType  = BarType.Time;
     this.fFillMode       = StopFillMode.Stop;
     this.textEnabled     = true;
     this.toolTipEnabled  = true;
     this.toolTipFormat   = "";
     this.activeColor     = Color.Purple;
     this.executedColor   = Color.RoyalBlue;
     this.canceledColor   = Color.Gray;
 }
Example #36
0
File: Stop.cs Project: heber/FreeOQ
    public Stop(StrategyBase strategy, Position position, double level, StopType type, StopMode mode)
			:base()
		{
      this.Udd6EeE9v6 = strategy;
      this.fPosition = position;
      this.fInstrument = position.Instrument;
      this.fQty = position.Qty;
      this.fSide = position.Side;
      this.fLevel = level;
      this.fType = type;
      this.fMode = mode;
      this.fCurrPrice = this.fInstrument.Price();
      this.fTrailPrice = this.fCurrPrice;
      this.fStopPrice = this.SlN6PMZ5Ct();
      this.fCreationTime = Clock.Now;
      this.fCompletionTime = DateTime.MinValue;
      this.Udd6EeE9v6.AddStop((StopBase) this);
      this.t276DXCuDr();
    }
Example #37
0
    public PortfolioStop(StrategyBase strategy, double level, StopType type, StopMode mode, bool stopStrategy)
			:base(){
      this.dUqRtBdT71 = StopType.Trailing;
      this.Wa9RdDJEOa = StopMode.Percent;
      this.rfci6isjj5 = StopFillMode.Stop;
      this.sKmRoRmeN5 = strategy;
      this.ElNRan0isi = strategy.Portfolio;
      this.QqtReC8Evy = level;
      this.dUqRtBdT71 = type;
      this.Wa9RdDJEOa = mode;
      this.RUQiAxBBaC = stopStrategy;
      this.oURRNWOggg = this.ElNRan0isi.GetValue();
      this.uLLipPWdua = this.oURRNWOggg;
      this.FuNRz16ilo = this.aIZRlrvLwJ();
      this.XoERmcoQ62 = Clock.Now;
      this.xTNRf1TvWo = DateTime.MinValue;
      this.i7uRq8Sj1g();
      this.agAikbNDtv = this.oURRNWOggg;
      this.uLLipPWdua = this.oURRNWOggg;
      this.QJSRn03JW5();
    }
Example #38
0
		internal static SmartQuant.Trading.StopMode Convert(StopMode stopMode)
		{
			switch (stopMode)
			{
			case StopMode.Absolute:
				return SmartQuant.Trading.StopMode.Absolute;
			case StopMode.Percent:
				return SmartQuant.Trading.StopMode.Percent;
			default:
				throw new NotImplementedException("Stop mode is not supported : " + stopMode);
			}
		}
Example #39
0
File: Stop.cs Project: heber/FreeOQ
    public Stop(StrategyBase strategy, double level, StopType type, StopMode mode)
			:  this(strategy, (Position) null, level, type, mode) {
    }
Example #40
0
        public override void Stop(StopMode mode = StopMode.Smooth)
        {
            Trame trame = TrameFactory.Stop(mode, this);
            DeplacementLigne = false;

            Connexion.SendMessage(trame);

            Historique.AjouterAction(new ActionStop(this, mode));
        }
        /// <summary>
        /// 根据入场后的最高与最低价,跟踪止损
        /// </summary>
        /// <param name="currentPrice"></param>
        /// <param name="level"></param>
        /// <param name="mode"></param>
        /// <returns>止损了返止损前持仓,可用于后面的反手</returns>
        public virtual double TrailingStop(double currentPrice, double level, StopMode mode,string text)
        {
            //lock(this)
            {
                double qty = GetCurrentQty();
                double stop;
                if (qty > double.Epsilon)
                {
                    if (StopMode.Percent == mode)
                    {
                        stop = HighestAfterEntry * (1.0 - level);
                    }
                    else
                    {
                        stop = HighestAfterEntry - level;
                    }
                    if (currentPrice < stop)
                    {
                        TargetPosition = 0;
                        TextParameter.Text = string.Format("跟踪止损 - 最高{0},止损{1}>当前{2}|{3}",
                            HighestAfterEntry, stop, currentPrice,
                            text);
                        return qty;
                    }
                }
                else if (qty < -double.Epsilon)
                {
                    if (StopMode.Percent == mode)
                    {
                        stop = LowestAfterEntry * (1.0 + level);
                    }
                    else
                    {
                        stop = LowestAfterEntry + level;
                    }

                    if (currentPrice > stop)
                    {
                        TargetPosition = 0;
                        TextParameter.Text = string.Format("跟踪止损 - 最低{0},止损{1}<当前{2}|{3}",
                            HighestAfterEntry, stop, currentPrice,
                            text);
                        return qty;
                    }
                }

                return 0;
            }
        }
Example #42
0
 public Stop(Strategy strategy, Position position, double level, StopType type, StopMode mode)
     :this(strategy, position, DateTime.MinValue, level, type, mode)
 {
 }
Example #43
0
 private Stop(Strategy strategy, Position position, DateTime time, double level = 0, StopType type = StopType.Trailing, StopMode mode = StopMode.Percent)
 {
     this.strategy = strategy;
     this.position = position;
     this.instrument = position.Instrument;
     this.qty = position.Qty;
     this.side = position.Side;
     this.type = type;
     this.mode = mode;
     this.creationTime = strategy.framework.Clock.DateTime;
     this.completionTime = time;
     this.stopPrice = GetInstrumentPrice();
     if (this.completionTime > this.creationTime)
         strategy.framework.Clock.AddReminder(new Reminder(this.method_9, this.completionTime, null));
 }
        /// <summary>
        /// 从入场均价开始算起,固定点位止损
        /// </summary>
        /// <param name="currentPrice"></param>
        /// <param name="level"></param>
        /// <param name="mode"></param>
        /// <returns>止损了返止损前持仓,可用于后面的反手</returns>
        public virtual double FixedStop(double currentPrice, double level, StopMode mode, string text)
        {
            double qty = GetCurrentQty();
            double stop;
            if (qty > 0)
            {
                if (StopMode.Percent == mode)
                {
                    stop = GetLongAvgPrice() * (1.0 - level);
                }
                else
                {
                    stop = GetLongAvgPrice() - level;
                }
                if (currentPrice < stop)
                {
                    TargetPosition = 0;
                    TextParameter.Text = string.Format("固定止损 - 多头均价{0},止损{1}>当前{2}|{3}",
                        GetLongAvgPrice(), stop, currentPrice,
                        text);
                    return qty;
                }
            }
            else
            {
                if (StopMode.Percent == mode)
                {
                    stop = GetShortAvgPrice() * (1.0 + level);
                }
                else
                {
                    stop = GetShortAvgPrice() + level;
                }

                if (currentPrice > stop)
                {
                    TargetPosition = 0;
                    TextParameter.Text = string.Format("固定止损 - 空头均价{0},止损{1}<当前{2}|{3}",
                        GetShortAvgPrice(), stop, currentPrice,
                        text);
                    return qty;
                }
            }
            return 0;
        }
Example #45
0
File: Stop.cs Project: heber/FreeOQ
		internal Stop(Position position, double level, StopType type, StopMode mode)
		{
			this.position = position;
			FreeQuant.Trading.StopType stopType = EnumConverter.Convert(type);
			FreeQuant.Trading.StopMode stopMode = EnumConverter.Convert(mode);
			this.stop = new ATSStop(position.position, level, stopType, stopMode);
			((StopBase)this.stop).TrailOnHighLow = true;
			((StopBase)this.stop).TraceOnBarOpen = true;
			((StopBase)this.stop).TraceOnBar = true;
			((StopBase)this.stop).TraceOnQuote = true;
			((StopBase)this.stop).TraceOnTrade = true;
		}
Example #46
0
		public ATSStop SetStop(Position position, double level, StopType type, StopMode mode)
		{
			ATSStop atsStop = new ATSStop(position, level, type, mode);
			this.Strategy.nPMi9oJHY7(atsStop);
			return atsStop;
		}
        /// <summary>
        /// 根据入场后的最高与最低价,跟踪止损
        /// </summary>
        /// <param name="currentPrice">当前价格</param>
        /// <param name="level">止损水平:为绝对值或百分比</param>
        /// <param name="mode">止损类型:绝对值,Percent百分比</param>
        /// <returns>止损了返回止损前持仓,可用于后面的反手</returns>
        public virtual double TrailingStop(double currentPrice, double level, StopMode mode,string text)
        {
            //lock(this)
            {
                double qty = GetCurrentQty();//获取当前持仓
                double stop;//止损价
                //当前持仓 > 0 时
                if (qty > double.Epsilon)
                {
                    //止损类型为百分比时
                    if (StopMode.Percent == mode)
                    {
                        //止损价=入场后最高价*(1.0-止损百分比)
                        stop = HighestAfterEntry * (1.0 - level);
                    }
                    else//止损类型为绝对值
                    {
                        //止损价=入场后最高价 - 止损绝对值
                        stop = HighestAfterEntry - level;
                    }
                    //当前价格 < 止损价 时清仓
                    if (currentPrice < stop)
                    {
                        TargetPosition = 0;//目标仓位=0,表示清仓
                        TextParameter.Text = string.Format("跟踪止损 - 最高{0},止损{1}>当前{2}|{3}",
                            HighestAfterEntry, stop, currentPrice,
                            text);
                        return qty;//返回止损仓位,可用于后面的反手
                    }
                }
                    //当前持仓 < 0 时
                else if (qty < -double.Epsilon)
                {
                    //止损类型为百分比时
                    if (StopMode.Percent == mode)
                    {
                        stop = LowestAfterEntry * (1.0 + level);
                    }
                    else//止损类型为绝对值
                    {
                        stop = LowestAfterEntry + level;
                    }

                    if (currentPrice > stop)
                    {
                        TargetPosition = 0;
                        TextParameter.Text = string.Format("跟踪止损 - 最低{0},止损{1}<当前{2}|{3}",
                            HighestAfterEntry, stop, currentPrice,
                            text);
                        return qty;
                    }
                }

                return 0;
            }
        }
        public virtual double TakeProfit(double currentPrice, double level, StopMode mode, string text)
        {
            //lock(this)
            {
                double qty = GetCurrentQty();
                double stop;
                if (qty > double.Epsilon)
                {
                    if (StopMode.Percent == mode)
                    {
                        stop = GetLongAvgPrice() * (1.0 + level);
                    }
                    else
                    {
                        stop = GetLongAvgPrice() + level;
                    }
                    if (currentPrice > stop)
                    {
                        TargetPosition = 0;
                        TextParameter.Text = string.Format("固定止赢 - 多头均价{0},止赢{1}<当前{2}|{3}",
                            GetLongAvgPrice(), stop, currentPrice,
                            text);
                        return qty;
                    }
                }
                else if (qty < -double.Epsilon)
                {
                    if (StopMode.Percent == mode)
                    {
                        stop = GetShortAvgPrice() * (1.0 - level);
                    }
                    else
                    {
                        stop = GetShortAvgPrice() - level;
                    }

                    if (currentPrice < stop)
                    {
                        TargetPosition = 0;
                        TextParameter.Text = string.Format("固定止赢 - 空头均价{0},止赢{1}>当前{2}|{3}",
                            GetShortAvgPrice(), stop, currentPrice,
                            text);
                        return qty;
                    }
                }
                return 0;
            }
        }
Example #49
0
        public static Trame Stop(StopMode mode, Robot robot)
        {
            byte[] tab = new byte[3];
            tab[0] = (byte)robot.Carte;
            tab[1] = (byte)FonctionMove.Stop;
            tab[2] = (byte)mode;

            Trame retour = new Trame(tab);
            return retour;
        }
Example #50
0
 public Stop(Strategy strategy, Position position, double level, StopType type, StopMode mode)
 {
     this.type = StopType.Trailing;
     this.mode = StopMode.Percent;
     this.traceOnQuote = true;
     this.traceOnTrade = true;
     this.traceOnBar = true;
     this.traceOnBarOpen = true;
     this.trailOnOpen = true;
     this.filterBarSize = -1L;
     this.filterBarType = BarType.Time;
     this.fillMode = StopFillMode.Stop;
     this.strategy = strategy;
     this.position = position;
     this.instrument = position.Instrument;
     this.qty = position.Qty;
     this.side = position.Side;
     this.level = level;
     this.type = type;
     this.mode = mode;
     this.currPrice = GetInstrumentPrice();
     this.trailPrice = this.currPrice;
     this.stopPrice = GetStopPrice();
     this.creationTime = strategy.Framework.Clock.DateTime;
     this.completionTime = DateTime.MinValue;
     this.method_0();
 }
Example #51
0
		public Stop SetStop(double level, StopType type, StopMode mode)
		{
			return this.SetStop(this.Position, level, type, mode);
		}
Example #52
0
		public Stop SetStop(Position position, double level, StopType type, StopMode mode)
		{
			Stop stop = new Stop(position, level, type, mode);
			Map.OQ_SQ_Stop[stop] = stop.stop;
			Map.SQ_OQ_Stop[stop.stop] = stop;
			Map.AddStop(stop.stop, this.strategyName);
			stop.TraceOnBar = this.stopTraceOnBar;
			stop.TraceOnTrade = this.stopTraceOnTrade;
			stop.TraceOnQuote = this.stopTraceOnQuote;
			return stop;
		}
Example #53
0
 public ActionStop(Robot r, StopMode m)
 {
     robot = r;
     mode = m;
 }
        /// <summary>
        /// 从入场均价开始算起,固定点位止损
        /// </summary>
        /// <param name="currentPrice">当前价</param>
        /// <param name="level">止损水平</param>
        /// <param name="mode">止损类型</param>
        /// <returns>止损了返止损前持仓,可用于后面的反手</returns>
        public virtual double FixedStop(double currentPrice, double level, StopMode mode, string text)
        {
            //lock(this)
            {
                double qty = GetCurrentQty();//获取当前仓位
                double stop;//止损价
                //仓位>0时
                if (qty > double.Epsilon)
                {
                    //止损类型为百分比时
                    if (StopMode.Percent == mode)
                    {
                        stop = GetLongAvgPrice() * (1.0 - level);
                    }
                    else//止损类型为绝对值时
                    {
                        stop = GetLongAvgPrice() - level;
                    }
                    if (currentPrice < stop)
                    {
                        TargetPosition = 0;//清仓
                        TextParameter.Text = string.Format("固定止损 - 多头均价{0},止损{1}>当前{2}|{3}",
                            GetLongAvgPrice(), stop, currentPrice,
                            text);
                        return qty;
                    }
                }
                    //仓位<0时
                else if (qty < -double.Epsilon)
                {
                    if (StopMode.Percent == mode)
                    {
                        stop = GetShortAvgPrice() * (1.0 + level);
                    }
                    else
                    {
                        stop = GetShortAvgPrice() + level;
                    }

                    if (currentPrice > stop)
                    {
                        TargetPosition = 0;
                        TextParameter.Text = string.Format("固定止损 - 空头均价{0},止损{1}<当前{2}|{3}",
                            GetShortAvgPrice(), stop, currentPrice,
                            text);
                        return qty;
                    }
                }
                return 0;
            }
        }
Example #55
0
		internal Stop(Position position, double level, StopType type, StopMode mode)
		{
			this.position = position;
			SmartQuant.Trading.StopType type2 = EnumConverter.Convert(type);
			SmartQuant.Trading.StopMode mode2 = EnumConverter.Convert(mode);
			this.stop = new ATSStop(position.position, level, type2, mode2);
			this.stop.TrailOnHighLow = true;
			this.stop.TraceOnBarOpen = true;
			this.stop.TraceOnBar = true;
			this.stop.TraceOnQuote = true;
			this.stop.TraceOnTrade = true;
		}
Example #56
0
        public override void Stop(StopMode mode)
        {
            Historique.AjouterAction(new ActionStop(this, mode));
            SemDeplacement.WaitOne();

            if (mode == StopMode.Smooth)
            {
                Position nouvelleDestination = new Calculs.Position(new Angle(Position.Angle.AngleDegres), new PointReel(position.Coordonnees.X, position.Coordonnees.Y));

                if (DeplacementLigne)
                {
                    if (SensDep == SensAR.Avant)
                        nouvelleDestination.Avancer(DistanceFreinageActuelle);
                    else
                        nouvelleDestination.Avancer(-DistanceFreinageActuelle);
                }

                Destination = nouvelleDestination;
            }
            else if (mode == StopMode.Abrupt)
            {
                VitesseActuelle = 0;
                Destination = Position;
            }
            SemDeplacement.Release();
        }
Example #57
0
        /// <summary>
        /// Sets up the Logger instance. 
        /// </summary>
        /// <param name="checkPeriod">How often the Logger thread should check the queue.</param>
        /// <param name="sinks">Sinks to install into the logger</param>
        public static void Setup(int checkPeriod, params ILoggerSink[] sinks)
        {
            _sinks = sinks;
            _stopMode = StopMode.CanRun;
            _checkPeriod = checkPeriod;

            Debug = new LoggerWriter ("D", EnqueueMessage);
            Warning = new LoggerWriter ("W", EnqueueMessage);
            Error = new LoggerWriter ("E", EnqueueMessage);

            _waitStopSemaphore = new SemaphoreSlim (0, 1);
            _messageQueue = new ConcurrentQueue<LoggerMessage> ();
            new Thread (new ThreadStart (MessageCatcher)).Start ();
        }
Example #58
0
		public StopBase() : base()
		{
			this.fType = StopType.Trailing;
			this.fMode = StopMode.Percent;
			this.fTraceOnQuote = true;
			this.fTraceOnTrade = true;
			this.fTraceOnBar = true;
			this.fTraceOnBarOpen = true;
			this.fTrailOnOpen = true;
			this.fFilterBarSize = -1L;
			this.fFilterBarType = BarType.Time;
			this.fFillMode = StopFillMode.Stop;
			this.textEnabled = true;
			this.toolTipEnabled = true;
			this.toolTipFormat = "";
			this.activeColor = Color.Purple;
			this.executedColor = Color.RoyalBlue;
			this.canceledColor = Color.Gray;
		}
Example #59
0
 public abstract void Stop(StopMode mode = StopMode.Smooth);
 public Stop SetStop(double level, StopType type = StopType.Fixed, StopMode mode = StopMode.Absolute)
 {
     var stop = new Stop(this.strategy, this.Position, level, type, mode);
     this.strategy.AddStop(stop);
     return stop;
 }