Beispiel #1
0
        public Alert ExitAlertCreate(Bar exitBar, Position position, double stopOrLimitPrice, string signalName,
                                     Direction direction, MarketLimitStop exitMarketLimitStop)
        {
            this.checkThrowEntryBarIsValid(exitBar);
            this.checkThrowPositionToCloseIsValid(position);

            double          priceScriptOrStreaming = stopOrLimitPrice;
            OrderSpreadSide orderSpreadSide        = OrderSpreadSide.Unknown;

            if (exitMarketLimitStop == MarketLimitStop.Market)
            {
                priceScriptOrStreaming = this.getStreamingPriceForMarketOrder(exitMarketLimitStop, direction, out orderSpreadSide);
            }

            PositionLongShort longShortFromDirection = MarketConverter.LongShortFromDirection(direction);
            double            exitPriceScript        = exitBar.ParentBars.SymbolInfo.RoundAlertPriceToPriceLevel(
                priceScriptOrStreaming, true, longShortFromDirection, exitMarketLimitStop);

            Alert alert = new Alert(exitBar, position.Shares, exitPriceScript, signalName,
                                    direction, exitMarketLimitStop, orderSpreadSide,
                                    //this.executor.Script,
                                    this.executor.Strategy);

            alert.AbsorbFromExecutor(executor);
            alert.PositionAffected = position;
            // moved to CallbackAlertFilled - we can exit by TP or SL - and position has no clue which Alert was filled!!!
            //position.ExitCopyFromAlert(alert);
            alert.PositionAffected.ExitAlertAttach(alert);

            return(alert);
        }
Beispiel #2
0
        public Alert EntryAlertCreate(Bar entryBar, double stopOrLimitPrice, string entrySignalName,
                                      Direction direction, MarketLimitStop entryMarketLimitStop)
        {
            this.checkThrowEntryBarIsValid(entryBar);

            double          priceScriptOrStreaming = stopOrLimitPrice;
            OrderSpreadSide orderSpreadSide        = OrderSpreadSide.Unknown;

            if (entryMarketLimitStop == MarketLimitStop.Market)
            {
                priceScriptOrStreaming = this.getStreamingPriceForMarketOrder(entryMarketLimitStop, direction, out orderSpreadSide);
            }

            PositionLongShort longShortFromDirection = MarketConverter.LongShortFromDirection(direction);
            // ALREADY_ALIGNED_AFTER GetAlignedBidOrAskForTidalOrCrossMarketFromStreaming
            double entryPriceScript = entryBar.ParentBars.SymbolInfo.RoundAlertPriceToPriceLevel(
                priceScriptOrStreaming, true, longShortFromDirection, entryMarketLimitStop);

            double shares = this.executor.PositionSizeCalculate(entryBar, entryPriceScript);

            Alert alert = new Alert(entryBar, shares, entryPriceScript, entrySignalName,
                                    direction, entryMarketLimitStop, orderSpreadSide,
                                    //this.executor.Script,
                                    this.executor.Strategy);

            alert.AbsorbFromExecutor(executor);

            return(alert);
        }