public StrategyMetaData getStrategyMetaDataMap(String symbol, TIMEFRAME timeframe) { int tf = (int)timeframe; if (tf == 0) { tf = (int)Period(); } string key = symbol + "_" + tf; if (!strategyMetaDataMap.ContainsKey(key)) { strategyMetaDataMap[key] = new StrategyMetaData(); } return(strategyMetaDataMap[key]); }
private bool checkCandle(String symbol, TIMEFRAME timeframe) { try { bool newCandle = false; StrategyMetaData strategyMetaData = getStrategyMetaDataMap(symbol, timeframe); LocalDate localDate = getMarketLocalDate(symbol); // new day detected if (!localDate.Equals(strategyMetaData.getCurrentLocalDate())) { strategyMetaData.setCurrentLocalDate(localDate); // Get todays high/low: /* * todaysHigh = iHigh(symbol, (int)TIMEFRAME.PERIOD_D1, 0); * todaysLow = iLow(symbol, (int)TIMEFRAME.PERIOD_D1, 0); * * strategyMetaData.setSignalStartDateTime(DateUtil.addDateAndTime(strategyMetaData.getCurrentLocalDate(), signalStartTime)); * * if (signalStopTime.Equals(LocalTime.Midnight)) * { * // If stop time midnight, set signal stop to following day * strategyMetaData.setSignalStopDateTime(DateUtil.addDateAndTime(strategyMetaData.getCurrentLocalDate().PlusDays(1), signalStopTime)); * } * else * { * strategyMetaData.setSignalStopDateTime(DateUtil.addDateAndTime(strategyMetaData.getCurrentLocalDate(), signalStopTime)); * } */ LOG.Info("New Day Detected: " + strategyMetaData.getCurrentLocalDate()); //LOG.Debug("Market Time: " + getMarketTime(symbol)); //LOG.Debug("Market DateTime: " + getMarketDateTime(symbol)); //LOG.Debug("Local Date: " + localDate); //LOG.Debug("Signal Start: " + strategyMetaData.getSignalStartDateTime()); //LOG.Debug("Signal Stop: " + strategyMetaData.getSignalStopDateTime()); // Get yesterdays high/low: //yesterdaysHigh = iHigh(symbol, (int)TIMEFRAME.PERIOD_D1, 1); //yesterdaysLow = iLow(symbol, (int)TIMEFRAME.PERIOD_D1, 1); onNewDate(symbol, timeframe); } // new candle detected DateTime newCurrentCandle = LocalDateTime.FromDateTime(iTime(symbol, (int)timeframe, 0)).ToDateTimeUnspecified(); if (!newCurrentCandle.Equals(strategyMetaData.getCurrentCandleDateTime())) { strategyMetaData.setCurrentCandleDateTime(newCurrentCandle); // Get distance to first candle of the day int i = 0; DateTime epoch = new DateTime(0); for (DateTime itime = epoch; itime == epoch || (itime != epoch && itime > strategyMetaData.getCurrentLocalDate().AtMidnight().ToDateTimeUnspecified()); i++) { itime = iTime(symbol, (int)timeframe, i); } strategyMetaData.setCandleDistanceToDayStart(i); //LOG.Debug("New Candle Detected: " + newCurrentCandle + " : distance from day start: " + strategyMetaData.getCandleDistanceToDayStart()); newCandle = true; onNewCandle(symbol, timeframe); } if (evalOncePerCandle && !newCandle) { return(false); } return(true); } catch (Exception e) { LOG.Error(e); throw; } }