示例#1
0
        public KeyValuePair <Double, Double> getHighLowPairInRange(String symbol, TIMEFRAME timeframe, DateTime from, DateTime to)
        {
            double low = Double.MaxValue;
            double high = 0;
            double ilow, ihigh;

            for (int i = 0; ; i++)
            {
                DateTime itime = iTime(symbol, (int)timeframe, i);
                if (itime < from)
                {
                    // break out once past from
                    break;
                }
                if (itime < to || itime == to)
                {
                    ilow  = iLow(symbol, (int)timeframe, i);
                    ihigh = iHigh(symbol, (int)timeframe, i);
                    if (ilow < low)
                    {
                        low = ilow;
                    }
                    if (ihigh > high)
                    {
                        high = ihigh;
                    }
                }
            }
            return(new KeyValuePair <double, double>(high, low));
        }
示例#2
0
        public double iCandleBodyLow(String symbol, TIMEFRAME timeframe, int shift)
        {
            double open  = iOpen(symbol, (int)timeframe, shift);
            double close = iClose(symbol, (int)timeframe, shift);

            return(open <= close? open : close);
        }
示例#3
0
 public BaseStrategy(Int64 ix) : base(ix)
 {
     this.symbolList = new List <string>();
     this.symbolList.Add(Symbol());
     this.timeframe      = TIMEFRAME.PERIOD_CURRENT;
     strategyMetaDataMap = new Dictionary <string, StrategyMetaData>();
     logHashMap          = new Dictionary <String, String>();
 }
示例#4
0
 public BaseStrategy(Int64 ix) : base(ix)
 {
     this.symbolList = new List<string>();
     this.symbolList.Add(Symbol());
     this.timeframe = TIMEFRAME.PERIOD_CURRENT;
     strategyMetaDataMap = new Dictionary<string, StrategyMetaData>();
     logHashMap = new Dictionary<String, String>();
 }
示例#5
0
 public override double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal)
 {
     if (signal.getSignal() < 0)
     {
         return(strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_BID) + strategy.iATR(symbol, (int)timeframe, atrPeriods, atrShift));
     }
     else
     {
         return(strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_ASK) - strategy.iATR(symbol, (int)timeframe, atrPeriods, atrShift));
     }
 }
示例#6
0
 public override double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal)
 {
     if (signal.getSignal() < 0)
     {
         return strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_BID) + strategy.iATR(symbol, (int)timeframe, atrPeriods, atrShift);
     }
     else
     {
         return strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_ASK) - strategy.iATR(symbol, (int)timeframe, atrPeriods, atrShift);
     }
 }
示例#7
0
 public BaseStrategy(int ix,
                     TIMEFRAME timeframe,
                     String symbol,
                     bool evalOncePerCandle = true,
                     bool closeOnOpposingSignal = true) : base(ix)
 {
     this.symbolList = new List<string>();
     this.symbolList.Add(symbol);
     this.timeframe = timeframe;
     this.evalOncePerCandle = evalOncePerCandle;
     this.closeOnOpposingSignal = closeOnOpposingSignal;
 }
示例#8
0
 public BaseStrategy(int ix,
                     TIMEFRAME timeframe,
                     String symbol,
                     bool evalOncePerCandle     = true,
                     bool closeOnOpposingSignal = true) : base(ix)
 {
     this.symbolList = new List <string>();
     this.symbolList.Add(symbol);
     this.timeframe             = timeframe;
     this.evalOncePerCandle     = evalOncePerCandle;
     this.closeOnOpposingSignal = closeOnOpposingSignal;
 }
        public override double getLevel(String symbol, TIMEFRAME timeframe, int signal)
        {
            double range = strategy.iHigh(symbol, (int)timeframe, 1) - strategy.iLow(symbol, (int)timeframe, 1);

            if (signal == (int)SignalResult.SELLMARKET)
            {
                return strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_BID) - pips* strategy.pipToPoint(symbol);
            }
            else
            {
                    return strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_ASK) + pips* strategy.pipToPoint(symbol);
            }
        }
示例#10
0
        public override double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal)
        {
            double range = strategy.iHigh(symbol, (int)timeframe, 1) - strategy.iLow(symbol, (int)timeframe, 1);

            if (signal.getSignal() == (int)SignalResult.SELLMARKET)
            {
                return(strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_BID) - pips * strategy.pipToPoint(symbol));
            }
            else
            {
                return(strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_ASK) + pips * strategy.pipToPoint(symbol));
            }
        }
示例#11
0
 public BaseStrategy(int ix,
                     TIMEFRAME timeframe,
                     List<String> symbolList,
                     bool evalOncePerCandle = true,
                     bool closeOnOpposingSignal = true) : base(ix)
 {
     this.timeframe = timeframe;
     this.symbolList = symbolList;
     this.evalOncePerCandle = evalOncePerCandle;
     this.closeOnOpposingSignal = closeOnOpposingSignal;
     if (symbolList.Count == 0)
     {
         throw new Exception("SymbolList should not be empty in Strategy constructor");
     }
 }
示例#12
0
        public override bool filter(String symbol, TIMEFRAME timeframe)
        {
            DateTime currentMarketTime = DateUtil.FromUnixTime((long)strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_TIME));

            foreach (NewsReport newsReport in newsReports)
            {
                if (symbol.Contains(newsReport.getCurrency()) &&
                    currentMarketTime > newsReport.getNoEntryPrior() &&
                    currentMarketTime < newsReport.getNoEntryPost())
                {
                    return(false);
                }
            }
            return(true);
        }
示例#13
0
 public BaseStrategy(int ix,
                     TIMEFRAME timeframe,
                     List <String> symbolList,
                     bool evalOncePerCandle     = true,
                     bool closeOnOpposingSignal = true) : base(ix)
 {
     this.timeframe             = timeframe;
     this.symbolList            = symbolList;
     this.evalOncePerCandle     = evalOncePerCandle;
     this.closeOnOpposingSignal = closeOnOpposingSignal;
     if (symbolList.Count == 0)
     {
         throw new Exception("SymbolList should not be empty in Strategy constructor");
     }
 }
示例#14
0
        public override bool filter(String symbol, TIMEFRAME timeframe)
        {
            DateTime currentMarketTime = DateUtil.FromUnixTime((long)strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_TIME));

            foreach (NewsReport newsReport in newsReports)
            {
                if (symbol.Contains(newsReport.getCurrency())
                    && currentMarketTime > newsReport.getCloseOutPrior()
                    && currentMarketTime < newsReport.getDateTime())
                {
                    return true;
                }
            }
            return false;
        }
示例#15
0
        public override bool filter(String symbol, TIMEFRAME timeframe)
        {
            DateTime currentMarketTime = DateUtil.FromUnixTime((long) strategy.MarketInfo(symbol, (int) MARKET_INFO.MODE_TIME));
            DateTime startTrading = DateUtil.getDateFromCurrentAnd24HRTime(currentMarketTime, timeStart);
            DateTime stopTrading = DateUtil.getDateFromCurrentAnd24HRTime(currentMarketTime, timeStop);

            // Trade Window
            if (currentMarketTime >= startTrading && currentMarketTime <= stopTrading)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
示例#16
0
        public override bool filter(String symbol, TIMEFRAME timeframe)
        {
            DateTime currentMarketTime = DateUtil.FromUnixTime((long)strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_TIME));
            DateTime startTrading      = DateUtil.getDateFromCurrentAnd24HRTime(currentMarketTime, timeStart);
            DateTime stopTrading       = DateUtil.getDateFromCurrentAnd24HRTime(currentMarketTime, timeStop);

            // Trade Window
            if (currentMarketTime >= startTrading && currentMarketTime <= stopTrading)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#17
0
        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]);
        }
示例#18
0
        public override SignalResult evaluate(string symbol, TIMEFRAME timeframe)
        {
            double maFast1 = strategy.iMA(symbol, (int) timeframe, maPeriodFast, maShift, (int)methodFast, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE, 1);
            double maSlow1 = strategy.iMA(symbol, (int)timeframe, maPeriodSlow, maShift, (int)methodSlow, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE, 1);
            double maFast2 = strategy.iMA(symbol, (int)timeframe, maPeriodFast, maShift, (int)methodFast, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE, 2);
            double maSlow2 = strategy.iMA(symbol, (int)timeframe, maPeriodSlow, maShift, (int)methodSlow, (int)ENUM_APPLIED_PRICE.PRICE_CLOSE, 2);

            if (maFast1 < maSlow1 && maFast2 > maSlow2)
            {
                return SignalResult.newSELLMARKET();
            }
            else if (maFast1 > maSlow1 && maFast2 < maSlow2)
            {
                return SignalResult.newBUYMARKET();
            }
            else
            {
                return SignalResult.newNEUTRAL();
            }
        }
示例#19
0
 protected BaseStrategy(long ix,
                        TIMEFRAME timeframe        = TIMEFRAME.PERIOD_CURRENT,
                        List <String> symbolList   = null,
                        bool evalOncePerCandle     = true,
                        bool closeOnOpposingSignal = true) : base(ix)
 {
     if (symbolList == null || symbolList.Count == 0)
     {
         this.symbolList = new List <string>();
         this.symbolList.Add(Symbol());
     }
     else
     {
         this.symbolList = symbolList;
     }
     this.timeframe             = timeframe;
     this.evalOncePerCandle     = evalOncePerCandle;
     this.closeOnOpposingSignal = closeOnOpposingSignal;
     strategyMetaDataMap        = new Dictionary <string, StrategyMetaData>();
     logHashMap = new Dictionary <String, String>();
 }
示例#20
0
 public override double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal)
 {
     if (signal.getSignal() == SignalResult.SELLMARKET)
     {
         double current_high = strategy.iHigh(symbol, (int)timeframe, 0);
         for (int i = 1; strategy.iHigh(symbol, (int)timeframe, i) > current_high; i++)
         {
             current_high = strategy.iHigh(symbol, (int)timeframe, i);
         }
         return current_high + pipTolerance * strategy.pipToPoint(symbol);
     }
     else
     {
         double current_low = strategy.iLow(symbol, (int)timeframe, 0);
         for (int i = 1; strategy.iLow(symbol, (int)timeframe, i) < current_low; i++)
         {
             current_low = strategy.iLow(symbol, (int)timeframe, i);
         }
         return current_low - pipTolerance * strategy.pipToPoint(symbol);
     }
 }
示例#21
0
 public override double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal)
 {
     if (signal.getSignal() == SignalResult.SELLMARKET)
     {
         double current_high = strategy.iHigh(symbol, (int)timeframe, 0);
         for (int i = 1; strategy.iHigh(symbol, (int)timeframe, i) > current_high; i++)
         {
             current_high = strategy.iHigh(symbol, (int)timeframe, i);
         }
         return(current_high + pipTolerance * strategy.pipToPoint(symbol));
     }
     else
     {
         double current_low = strategy.iLow(symbol, (int)timeframe, 0);
         for (int i = 1; strategy.iLow(symbol, (int)timeframe, i) < current_low; i++)
         {
             current_low = strategy.iLow(symbol, (int)timeframe, i);
         }
         return(current_low - pipTolerance * strategy.pipToPoint(symbol));
     }
 }
示例#22
0
        public override SignalResult evaluate(string symbol, TIMEFRAME timeframe)
        {
            double maFast1 = strategy.iMA(symbol, (int)timeframe, maPeriodFast, maShift, (int)methodFast, (int)APPLIED_PRICE.PRICE_CLOSE, 1);
            double maFast2 = strategy.iMA(symbol, (int)timeframe, maPeriodFast, maShift, (int)methodFast, (int)APPLIED_PRICE.PRICE_CLOSE, 2);
            double maSlow1 = strategy.iMA(symbol, (int)timeframe, maPeriodSlow, maShift, (int)methodSlow, (int)APPLIED_PRICE.PRICE_CLOSE, 1);
            double maSlow2 = strategy.iMA(symbol, (int)timeframe, maPeriodSlow, maShift, (int)methodSlow, (int)APPLIED_PRICE.PRICE_CLOSE, 2);

            if (maFast1 < maSlow1 && maFast2 > maSlow2)
            {
                //strategy.LOG.Info("Signal Short: " + strategy.iTime(symbol, (int)timeframe, 0));
                return SignalResult.newSELLMARKET();
            }
            else if (maFast1 > maSlow1 && maFast2 < maSlow2)
            {
                //strategy.LOG.Info("Signal Long: " + strategy.iTime(symbol, (int)timeframe, 0));
                return SignalResult.newBUYMARKET();
            }
            else
            {
                //strategy.LOG.Info("Signal Neutral: " + strategy.iTime(symbol, (int)timeframe, 0));
                return SignalResult.newNEUTRAL();
            }
        }
示例#23
0
        public override SignalResult evaluate(string symbol, TIMEFRAME timeframe)
        {
            double maFast1 = strategy.iMA(symbol, (int)timeframe, maPeriodFast, maShift, (int)methodFast, (int)APPLIED_PRICE.PRICE_CLOSE, 1);
            double maFast2 = strategy.iMA(symbol, (int)timeframe, maPeriodFast, maShift, (int)methodFast, (int)APPLIED_PRICE.PRICE_CLOSE, 2);
            double maSlow1 = strategy.iMA(symbol, (int)timeframe, maPeriodSlow, maShift, (int)methodSlow, (int)APPLIED_PRICE.PRICE_CLOSE, 1);
            double maSlow2 = strategy.iMA(symbol, (int)timeframe, maPeriodSlow, maShift, (int)methodSlow, (int)APPLIED_PRICE.PRICE_CLOSE, 2);

            if (maFast1 < maSlow1 && maFast2 > maSlow2)
            {
                //strategy.LOG.Info("Signal Short: " + strategy.iTime(symbol, (int)timeframe, 0));
                return(SignalResult.newSELLMARKET());
            }
            else if (maFast1 > maSlow1 && maFast2 < maSlow2)
            {
                //strategy.LOG.Info("Signal Long: " + strategy.iTime(symbol, (int)timeframe, 0));
                return(SignalResult.newBUYMARKET());
            }
            else
            {
                //strategy.LOG.Info("Signal Neutral: " + strategy.iTime(symbol, (int)timeframe, 0));
                return(SignalResult.newNEUTRAL());
            }
        }
示例#24
0
        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;
            }
        }
        /// <summary>
        /// Get raw stock historical price from Yahoo Finance
        /// </summary>
        /// <param name="symbol">Stock ticker symbol</param>
        /// <param name="start">Starting datetime</param>
        /// <param name="end">Ending datetime</param>
        /// <returns>Raw history price string</returns>

        public static string GetRaw(string symbol, DateTime start, DateTime end, TIMEFRAME timeFrame)
        {
            string csvData = null;

            try
            {
                int pos = symbol.IndexOf("BTC", 2);
                if (pos <= 0)
                {
                    pos = symbol.IndexOf("LTC", 2);
                }
                if (pos <= 0)
                {
                    pos = symbol.IndexOf("ETH", 2);
                }
                if (pos <= 0)
                {
                    pos = symbol.IndexOf("BNB", 2);
                }
                if (pos <= 0)
                {
                    pos = symbol.IndexOf("TUSD", 2);
                }
                if (pos <= 0)
                {
                    pos = symbol.IndexOf("USDT", 2);
                }
                if (pos <= 0)
                {
                    pos = symbol.IndexOf("USD", 2);
                }
                if (pos <= 0)
                {
                    throw new Exception("ERROR: Pair not found " + symbol);
                }

                string fsym = symbol.Substring(0, pos);
                string tsym = symbol.Substring(pos, symbol.Length - fsym.Length);
                MainSymbol = tsym;

                string toTs      = ((int)DateTimeToUnixTimestamp(end)).ToString();
                string aggregate = "1";
                string action    = "histominute";
                if (timeFrame == TIMEFRAME.MIN1 || timeFrame == TIMEFRAME.MIN15 || timeFrame == TIMEFRAME.MIN30)
                {
                    action    = "histominute";
                    aggregate = timeFrame.ToString();
                }
                else if (timeFrame == TIMEFRAME.MIN60 || timeFrame == TIMEFRAME.MIN240)
                {
                    action    = "histohour";
                    aggregate = "1";
                    if (timeFrame == TIMEFRAME.MIN240)
                    {
                        aggregate = "4";
                    }
                }
                else if (timeFrame == TIMEFRAME.MIN1440 || timeFrame != TIMEFRAME.MIN10080 || timeFrame != TIMEFRAME.MIN21600)
                {
                    action    = "histoday";
                    aggregate = "1";
                    if (timeFrame == TIMEFRAME.MIN10080)
                    {
                        aggregate = "7";
                    }
                    if (timeFrame == TIMEFRAME.MIN21600)
                    {
                        aggregate = "30";
                    }
                }

                //string url = "https://min-api.cryptocompare.com/data/" + action + "?fsym=" + fsym + "&tsym=" + tsym + "&limit=" + limit + "&aggregate=" + aggregate + "&e=CCCAGG&toTs=" + toTs;
                string url = string.Format(CryptoCompURL, action, fsym, tsym, limit, aggregate, exchange.ToString(), toTs);
                //else
                //url = "https://min-api.cryptocompare.com/data/" + action + "?fsym=" + fsym + "&tsym=" + tsym + "&limit=" + limit + "&aggregate=" + aggregate + "&e=CCCAGG&toTs=" + toTs;
                //url = string.Format(BinanceURL,  fsym+tsym, toTs);



                using (WebClient wc = new WebClient())
                {
                    csvData = wc.DownloadString(url);
                }
            }
            catch (WebException webEx)
            {
                throw;
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }

            return(csvData);
        }
 public override void manage(String symbol, TIMEFRAME timeframe)
 {
     // Do nothing
 }
示例#27
0
 // Method called onTick to manage the Take Profit Level
 public abstract void manage(String symbol, TIMEFRAME timeframe);
示例#28
0
 /// <summary>
 /// Function: ChartSetSymbolPeriod
 /// Description: Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion. The command is added to chart message queue and executed only after all previous commands have been processed.
 /// URL: http://docs.mql4.com/chart_operations/chartsetsymbolperiod.html
 /// </summary>
 /// <param name="chart_id">[in] Chart ID. 0 means the current chart.</param>
 /// <param name="symbol">[in] Chart symbol. value means the current chart symbol (Expert Advisor is attached to)</param>
 /// <param name="period">[in] Chart period (timeframe). Can be one of the values. 0 means the current chart period.</param>
 public bool ChartSetSymbolPeriod(long chart_id, string symbol, TIMEFRAME period)
 {
     List<Object> parameters = new List<Object>();
     parameters.Add(chart_id);
     parameters.Add(symbol);
     parameters.Add(period.ToString());
     int id = getCommandManager().ExecCommand(MQLCommand.ChartSetSymbolPeriod_1, parameters); // MQLCommand ENUM = 89
     while (getCommandManager().IsCommandRunning(id))
     {
         //Thread.Sleep(1);
     }
     getCommandManager().throwExceptionIfErrorResponse(id);
     return (bool)getCommandManager().GetCommandResult(id);
 }
示例#29
0
 public override  double getLevel(String symbol, TIMEFRAME timeframe, int signal)
 {
     return 0;
 }
示例#30
0
 public abstract SignalResult evaluate(String symbol, TIMEFRAME timeframe);
示例#31
0
 public abstract bool filter(String symbol, TIMEFRAME timeframe);
示例#32
0
        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;
            }
        }
示例#33
0
 public override void onNewCandle(string symbol, TIMEFRAME timeframe)
 {
 }
示例#34
0
 /// <summary>
 /// Function: ChartOpen
 /// Description: Opens a new chart with the specified symbol and period. The command is added to chart message queue and executed only after all previous commands have been processed.
 /// URL: http://mm.l/mql4/docs.mql4.com/chart_operations/chartopen.html
 /// </summary>
 /// <param name="symbol">[in] Chart symbol. means the symbol of the current chart (the Expert Advisor is attached to).</param>
 /// <param name="period">[in] Chart period (timeframe). Can be one of the values. 0 means the current chart period.</param>
 public long ChartOpen(string symbol, TIMEFRAME period)
 {
     List<Object> parameters = new List<Object>();
     parameters.Add(symbol);
     parameters.Add(period.ToString());
     MQLCommandManager.getInstance().ExecCommand(MQLCommand.ChartOpen_1, parameters); // MQLCommand ENUM = 70
     while (MQLCommandManager.getInstance().IsCommandRunning()) Thread.Sleep(1);
     return (long) MQLCommandManager.getInstance().GetCommandResult();
 }
示例#35
0
 public abstract void onNewCandle(String symbol, TIMEFRAME timeframe);
        /// <summary>
        /// Get stock historical price from Yahoo Finance
        /// </summary>
        /// <param name="symbol">Stock ticker symbol</param>
        /// <param name="start">Starting datetime</param>
        /// <param name="end">Ending datetime</param>
        /// <returns>List of history price</returns>
        public static int Get(string symbol, DateTime start, DateTime end, TIMEFRAME TimeFrame)
        {
            List <string> HistoryPrices    = new List <string>();
            DateTime      RawDataStartDate = DateTime.UtcNow;

            try
            {
                while (RawDataStartDate > start)
                {
                    end = RawDataStartDate;
                    string jsonData = GetRaw(symbol, start, end, TimeFrame);
                    if (jsonData != null && jsonData != "[]")
                    {
                        dynamic obj      = JsonConvert.DeserializeObject(jsonData);
                        var     DataArr  = ((IEnumerable <dynamic>)obj["Data"]);
                        var     lastElem = DataArr.ElementAt(DataArr.Count() - 2);

                        if (lastElem["open"].ToString() == "0" || lastElem["open"].ToString() == "null" ||
                            string.IsNullOrEmpty(lastElem["open"].ToString()))
                        {
                            break;
                        }

                        foreach (var x in DataArr.Reverse())
                        {
                            DateTime UnixTs = UnixTimestampToDateTime(System.Convert.ToDouble(x["time"].ToString()));
                            if (RawDataStartDate == UnixTs)
                            {
                                RawDataStartDate = DateTime.MinValue;
                                //break;
                            }

                            if (x == DataArr.ElementAt(0))
                            {
                                RawDataStartDate = UnixTs;
                            }

                            if (x["open"].ToString() != "0" && x["open"].ToString() != "null" && !string.IsNullOrEmpty(x["open"].ToString()))
                            {
                                string time =
                                    UnixTimestampToDateTime(System.Convert.ToDouble(x["time"].ToString()))
                                    .ToString("yyyy-MM-dd HH:mm");
                                string data = string.Format("{0},{1},{2},{3},{4},{5},{6}", time,
                                                            System.Convert.ToDouble(x["open"]).ToString("0.0000000000"),
                                                            System.Convert.ToDouble(x["high"]).ToString("0.0000000000"),
                                                            System.Convert.ToDouble(x["low"]).ToString("0.0000000000"),
                                                            System.Convert.ToDouble(x["close"]).ToString("0.0000000000"),
                                                            System.Convert.ToDouble(x["close"]).ToString("0.0000000000"),
                                                            //System.Convert.ToDouble(x["volumeto"]).ToString("0.0000000000"));
                                                            exchange == EXCHANGES.Binance? System.Convert.ToDouble(x["volumefrom"]).ToString("0.0000000000"):System.Convert.ToDouble(x["volumeto"]).ToString("0.0000000000"));

                                HistoryPrices.Add(data);
                            }
                        }
                    }

                    if (Maxlimit.ToString() != limit)
                    {
                        break;
                    }
                }


                if (HistoryPrices.Count > 0)
                {
                    //HistoryPrices.Reverse();

                    string csv = "date,open,high,low,close,adjclose,volume\n" + String.Join("\n", HistoryPrices);
                    System.IO.File.WriteAllText(@"history\history.csv", csv);
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }

            return(HistoryPrices.Count - 1);
        }
示例#37
0
 // Method to return the stop loss level
 public abstract double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal);
示例#38
0
 public abstract void onNewCandle(String symbol, TIMEFRAME timeframe);
示例#39
0
 public override void onNewCandle(string symbol, TIMEFRAME timeframe)
 {
     throw new NotImplementedException();
 }
示例#40
0
        public override void onNewCandle(string symbol, TIMEFRAME timeframe)
        {

        }
示例#41
0
 /// <summary>
 /// Function: ChartSetSymbolPeriod
 /// Description: Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion. The command is added to chart message queue and executed only after all previous commands have been processed.
 /// URL: http://mm.l/mql4/docs.mql4.com/chart_operations/chartsetsymbolperiod.html
 /// </summary>
 /// <param name="chart_id">[in] Chart ID. 0 means the current chart.</param>
 /// <param name="symbol">[in] Chart symbol. value means the current chart symbol (Expert Advisor is attached to)</param>
 /// <param name="period">[in] Chart period (timeframe). Can be one of the values. 0 means the current chart period.</param>
 public bool ChartSetSymbolPeriod(long chart_id, string symbol, TIMEFRAME period)
 {
     List<Object> parameters = new List<Object>();
     parameters.Add(chart_id);
     parameters.Add(symbol);
     parameters.Add(period.ToString());
     MQLCommandManager.getInstance().ExecCommand(MQLCommand.ChartSetSymbolPeriod_1, parameters);
         // MQLCommand ENUM = 89
     while (MQLCommandManager.getInstance().IsCommandRunning()) Thread.Sleep(1);
     return (bool) MQLCommandManager.getInstance().GetCommandResult();
 }
示例#42
0
 /// <summary>
 /// Function: Bars
 /// Description: Returns the number of bars count in the history for a specified symbol and period. There are 2 variants of functions calls.
 /// URL: http://docs.mql4.com/series/barsfunction.html
 /// </summary>
 /// <param name="symbol_name">[in] Symbol name.</param>
 /// <param name="timeframe">[in] Period.</param>
 /// <param name="start_time">[in] Bar time corresponding to the first element.</param>
 /// <param name="stop_time">[in] Bar time corresponding to the last element.</param>
 public int Bars(string symbol_name, TIMEFRAME timeframe, DateTime start_time, DateTime stop_time)
 {
     List<Object> parameters = new List<Object>();
     parameters.Add(symbol_name);
     parameters.Add(timeframe.ToString());
     parameters.Add(start_time);
     parameters.Add(stop_time);
     int id = getCommandManager().ExecCommand(MQLCommand.Bars_2, parameters); // MQLCommand ENUM = 56
     while (getCommandManager().IsCommandRunning(id))
     {
         //Thread.Sleep(1);
     }
     getCommandManager().throwExceptionIfErrorResponse(id);
     return (int)getCommandManager().GetCommandResult(id);
 }
示例#43
0
 public abstract bool filter(String symbol, TIMEFRAME timeframe);
示例#44
0
 // Method to return the Take Profit Level
 public abstract double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal);
示例#45
0
 public KeyValuePair<Double, Double> getHighLowPairInRange(String symbol, TIMEFRAME timeframe, DateTime from, DateTime to)
 {
     double low = Double.MaxValue;
     double high = 0;
     double ilow, ihigh;
     for(int i = 0; ; i++)
     {
         DateTime itime = iTime(symbol, (int)timeframe, i);
         if(itime < from)
         {
             // break out once past from
             break;
         }
         if(itime < to || itime == to)
         {
             ilow = iLow(symbol, (int)timeframe, i);
             ihigh = iHigh(symbol, (int)timeframe, i);
             if(ilow<low)
             {
                 low = ilow;
             }
             if(ihigh > high)
             {
                 high = ihigh;
             }
         }
     }
     return new KeyValuePair<double, double>(high, low);
 }
示例#46
0
 // Method called onTick to manage the Take Profit Level
 public abstract void manage(String symbol, TIMEFRAME timeframe);
示例#47
0
 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];
 }
示例#48
0
 /// <summary>
 /// Function: Bars
 /// Description: Returns the number of bars count in the history for a specified symbol and period. There are 2 variants of functions calls.
 /// URL: http://mm.l/mql4/docs.mql4.com/series/barsfunction.html
 /// </summary>
 /// <param name="symbol_name">[in] Symbol name.</param>
 /// <param name="timeframe">[in] Period.</param>
 /// <param name="start_time">[in] Bar time corresponding to the first element.</param>
 /// <param name="stop_time">[in] Bar time corresponding to the last element.</param>
 public int Bars(string symbol_name, TIMEFRAME timeframe, DateTime start_time, DateTime stop_time)
 {
     List<Object> parameters = new List<Object>();
     parameters.Add(symbol_name);
     parameters.Add(timeframe.ToString());
     parameters.Add(start_time);
     parameters.Add(stop_time);
     MQLCommandManager.getInstance().ExecCommand(MQLCommand.Bars_2, parameters); // MQLCommand ENUM = 56
     while (MQLCommandManager.getInstance().IsCommandRunning()) Thread.Sleep(1);
     return (int) MQLCommandManager.getInstance().GetCommandResult();
 }
示例#49
0
 public override void onNewCandle(string symbol, TIMEFRAME timeframe)
 {
     throw new NotImplementedException();
 }
示例#50
0
 public override void manage(String symbol, TIMEFRAME timeframe)
 {
     // Do nothing
 }
示例#51
0
 public override double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal)
 {
     return(0);
 }
示例#52
0
 public abstract SignalResult evaluate(String symbol, TIMEFRAME timeframe);
示例#53
0
 public double iCandleBodyLow(String symbol, TIMEFRAME timeframe, int shift)
 {
     double open = iOpen(symbol, (int)timeframe, shift);
     double close = iClose(symbol, (int)timeframe, shift);
     return open <= close? open : close;
 }