Beispiel #1
0
        private void cacluateRanges()
        {
            if (!rangesCalculated)
            {
                MarketDataElement preData = getPreTradeDayMData();
                log.Info("[cacluateRanges]: preData=" + preData.ToString());
                lastClose        = preData.close;
                lastHigh         = preData.high;
                lastLow          = preData.low;
                sellCheck        = lastHigh + f1 * (lastClose - lastLow);
                buyCheck         = lastLow - f1 * (lastHigh - lastClose);
                revSell          = ((1 + f2) / 2) * (lastHigh + lastClose) - f2 * lastLow;
                revBuy           = ((1 + f2) / 2) * (lastLow + lastClose) - f2 * lastHigh;
                trendSell        = buyCheck - f3 * (sellCheck - buyCheck);
                trendBuy         = sellCheck + f3 * (sellCheck - buyCheck);
                sellCheck        = Math.Floor(sellCheck);
                buyCheck         = Math.Floor(buyCheck);
                revSell          = Math.Floor(revSell);
                revBuy           = Math.Floor(revBuy);
                trendSell        = Math.Floor(trendSell);
                trendBuy         = Math.Floor(trendBuy);
                rangesCalculated = true;

                /*
                 * double anchor = 22290;
                 * trendBuy = anchor + 25;
                 * sellCheck = anchor + 15;
                 * revSell = anchor + 5;
                 *
                 * revBuy = anchor - 5;
                 * buyCheck = anchor - 15;
                 * trendSell = anchor - 25;
                 */
                log.Info("-----------------------------------------------");
                log.Info("[cacluateRanges]: trendBuy=" + trendBuy.ToString());
                log.Info("[cacluateRanges]: sellCheck=" + sellCheck.ToString());
                log.Info("[cacluateRanges]: revSell=" + revSell.ToString());
                log.Info("-----------------------------------------------");
                log.Info("[cacluateRanges]: revBuy=" + revBuy.ToString());
                log.Info("[cacluateRanges]: buyCheck=" + buyCheck.ToString());
                log.Info("[cacluateRanges]: trendSell=" + trendSell.ToString());
                log.Info("-----------------------------------------------");
            }
        }
Beispiel #2
0
        protected void dayEndCloseTrade(Series <DateTime, MarketDataElement> series)
        {
            if (dayClosed)
            {
                return;
            }

            MarketDataElement lastItem   = (MarketDataElement)series.GetAt(series.KeyCount - 1);
            DateTime          current    = lastItem.time;
            String            strCurrent = String.Format("{0:yyyyMMdd}", current);
            DateTime          dayEnd     = new DateTime(current.Year, current.Month, current.Day, 16, 13, 0);

            if (current < dayEnd)
            {
                return;
            }
            dayClosed = true;
            double tickClose = calculateMid();

            if (tickClose.Equals(double.NaN))
            {
                return;
            }

            stgHelper.cancelPendingTrades();

            if (execution.isPositionSignalBothEmpty())
            {
                return;
            }
            double enterPrice = lastExecutePrice;

            if (execution.CurrentMarketPosition > 0)
            {
                String reason = "[Strategy] : Dayend Exit Sell Generated !!! | MarketDataElement=" + lastItem.ToString();
                log.Info("[Strategy] : Cut Loss SELL Exit Generated !!!");
                log.Info(reason);
                if (sentOrder)
                {
                    stgHelper.placeMarketTrade(AppConstant.SELL_SIGNAL, "Day Exit Rule", tickClose, reason, 1, 1);
                    clearCache();
                }
            }

            if (execution.CurrentMarketPosition < 0)
            {
                String reason = "[Strategy] : Dayend Exit BUY Generated !!! | MarketDataElement=" + lastItem.ToString();
                log.Info("[Strategy] : Cut Loss BUY Exit Generated !!!");
                log.Info(reason);
                if (sentOrder)
                {
                    stgHelper.placeMarketTrade(AppConstant.BUY_SIGNAL, "Day Exit Rule", tickClose, reason, 1, 1);
                    clearCache();
                }
            }
        }