Example #1
0
        private void CheckStop(ViewData data, StockQuote quote /*, decimal dividends*/)
        {
            bool    showAlert = false;
            Decimal stopPrice = data.fixedStop;

            if (data.fixedStop != 0 && data.fixedStop >= quote.close)
            {
                showAlert = true;
            }

            if (data.stopPercent != 0)
            {
                if (data.useTrailing)
                {
                    Decimal highestClose = data.highestClose;
                    if (quote.highest > data.highestClose)
                    {
                        highestClose = quote.highest;
                    }

                    Decimal referencePrice = highestClose;
                    //if (data.useDividends)
                    //    referencePrice -= dividends;
                    if (data.useOptions)
                    {
                        referencePrice -= data.options;
                    }
                    Decimal subtractedPercentage = referencePrice * data.stopPercent / 100;
                    stopPrice = referencePrice - subtractedPercentage;
                    if (quote.close <= stopPrice)
                    {
                        showAlert = true;
                    }
                }
                else
                {
                    Decimal referencePrice = data.buyPrice;
                    //if (data.useDividends)
                    //    referencePrice -= data.dividends;
                    if (data.useOptions)
                    {
                        referencePrice -= data.options;
                    }
                    Decimal subtractedPercentage = referencePrice * data.stopPercent / 100;
                    stopPrice = referencePrice - subtractedPercentage;
                    if (quote.close <= stopPrice)
                    {
                        showAlert = true;
                    }
                }
            }

            if (showAlert)
            {
                StopAlert alert = new StopAlert {
                    symbol = data.symbol, close = quote.close, stop = stopPrice
                };
                stopAlerts.Add(alert);
            }
        }
Example #2
0
 public virtual void OnStopTriggered(EventArgs e)
 {
     //触发结束事件
     StopAlert?.Invoke(this, e);
 }