public void if_timeframe_is_null_isValid_returns_false()
        {
            Asset asset = new Asset(1, "x");
            AssetTimeframe atf = new AssetTimeframe(asset, null);

            Assert.IsFalse(atf.isValid());
        }
        public void if_asset_is_null_isValid_returns_false()
        {
            Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M30);
            AssetTimeframe atf = new AssetTimeframe(null, timeframe);

            Assert.IsFalse(atf.isValid());
        }
Exemple #3
0
 public static Mock<IAnalyzer> generateMockAnalyzer(AssetTimeframe atf, AnalysisType type, DateTime? firstRequiredDate)
 {
     Mock<IAnalyzer> mock = new Mock<IAnalyzer>();
     mock.Setup(q => q.getFirstRequiredDate()).Returns(firstRequiredDate);
     mock.Setup(q => q.getAssetTimeframe()).Returns(atf);
     mock.Setup(q => q.getAnalysisType()).Returns(type);
     return mock;
 }
Exemple #4
0
        public void runFull(IAnalyzer analyzer, DataItem item, AssetTimeframe atf)
        {
            this.atf = atf;
            if (item == null) return;
            if (item.Quotation == null) return;

            runLeftSide(analyzer, item, atf);
        }
        public void function_returns_proper_symbol()
        {
            Asset asset = new Asset(1, "ABC") { ShortName = "ABC" };
            Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M30);
            AssetTimeframe atf = new AssetTimeframe(asset, timeframe);

            Assert.AreEqual("ABC_M30", atf.Symbol());
        }
        public void if_both_asset_and_timeframe_are_set_isValid_returns_true()
        {
            Asset asset = new Asset(1, "x");
            Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M30);
            AssetTimeframe atf = new AssetTimeframe(asset, timeframe);

            Assert.IsTrue(atf.isValid());
        }
Exemple #7
0
        public Dictionary<AnalysisType, IAnalyzer> getAnalyzers(AssetTimeframe atf, IEnumerable<AnalysisType> types)
        {
            var dict = new Dictionary<AnalysisType, IAnalyzer>();
            foreach (var type in types)
            {
                IAnalyzer analyzer = getAnalyzer(type, atf);
                dict.Add(type, analyzer);
            }

            return dict;
        }
Exemple #8
0
 public IAnalyzer getAnalyzer(AnalysisType type, AssetTimeframe atf)
 {
     switch (type)
     {
         case AnalysisType.Price: return new PriceAnalyzer(atf);
         case AnalysisType.MACD: return new MacdAnalyzer(atf);
         case AnalysisType.ADX: return new AdxAnalyzer(atf);
         case AnalysisType.Candlestick: return new CandlestickAnalyzer(atf);
         case AnalysisType.Trendline: return new TrendlineAnalyzer(atf);
         case AnalysisType.Unknown: return null;
         default: return null;
     }
 }
 public IProcessService GetProcessService(AssetTimeframe atf)
 {
     string symbol = atf.Symbol();
     IProcessService service = null;
     try
     {
         services.TryGetValue(symbol, out service);
         return service;
     }
     catch (Exception) {
         service = new ProcessService(atf);
         return service;
     }
 }
Exemple #10
0
        public void runRightSide(IAnalyzer analyzer, DataItem item, AssetTimeframe atf)
        {
            this.atf = atf;
            if (item == null) return;
            if (item.Quotation == null) return;

            //Calculate new values for peaks and troughs and apply them to the current item price.
            //If any of this is changed, this price will have flag [IsChange] set to @true.
            //This is the only thing that can be changed for items being only updated.
            CheckForExtremum(item, ExtremumType.PeakByClose, false);
            CheckForExtremum(item, ExtremumType.PeakByHigh, false);
            CheckForExtremum(item, ExtremumType.TroughByClose, false);
            CheckForExtremum(item, ExtremumType.TroughByLow, false);
            CheckPriceGap(item);
        }
Exemple #11
0
 public void runRightSide(IAnalyzer analyzer, int index, AssetTimeframe atf)
 {
     DataItem item = analyzer.getDataItem(index);
     runRightSide(analyzer, item, atf);
 }
Exemple #12
0
 public DateTime? getLastCalculationDate(AssetTimeframe atf, AnalysisType analysisType)
 {
     if (LastAnalyzed > 2) return Data[LastAnalyzed - 2].Date;
     return null;
 }
Exemple #13
0
        private void runLeftSide(IAnalyzer analyzer, DataItem item, AssetTimeframe atf)
        {
            //Check if quotation is missing (but only in the middle of not-missing quotations,
            //because missing quotations at the end of array was excluded one line above).
            //If it is copy data from the previous quotation.
            if (!item.Quotation.IsComplete())
            {
                var previousQuotation = (item.Index > 0 ? analyzer.getDataItem(item.Index - 1).Quotation : null);
                if (previousQuotation != null)
                {
                    item.Quotation.CompleteMissing(previousQuotation);
                    //_dataService.UpdateQuotation(item.Quotation, Symbol);
                }

            }

            //Ensure that [Price] object is appended to this [DataItem].
            item.Price = new Price();
            item.Price.Date = item.Date;
            if (item.Index > 0) item.Price.CloseDelta = CalculateDeltaClosePrice(item.Quotation.Close, item.Index);
            item.Price.Direction2D = CalculateDirection2D(item.Index);
            item.Price.Direction3D = CalculateDirection3D(item.Index);

            //Calculate new values for peaks and troughs and apply them to the current item price.
            //If any of this is changed, this price will have flag [IsChange] set to @true.
            //This is the only thing that can be changed for items being only updated.
            CheckForExtremum(item, ExtremumType.PeakByClose, true);
            CheckForExtremum(item, ExtremumType.PeakByHigh, true);
            CheckForExtremum(item, ExtremumType.TroughByClose, true);
            CheckForExtremum(item, ExtremumType.TroughByLow, true);
            CheckPriceGap(item);
        }
Exemple #14
0
 public void runFull(IAnalyzer analyzer, int index, AssetTimeframe atf)
 {
 }
Exemple #15
0
 public void runRightSide(IAnalyzer analyzer, int index, AssetTimeframe atf)
 {
 }
Exemple #16
0
 public ProcessService(Asset asset, Timeframe timeframe)
 {
     this.assetTimeframe = new AssetTimeframe(asset, timeframe);
 }
Exemple #17
0
 public Analyzer(AssetTimeframe atf, IQuotationService quotationService)
 {
     this.quotationService = quotationService;
     initialize(atf);
 }
Exemple #18
0
 public ProcessService(AssetTimeframe atf)
 {
     this.assetTimeframe = atf;
 }
 public void if_atf_is_not_valid_function_throws_exception()
 {
     Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M30);
     AssetTimeframe atf = new AssetTimeframe(null, timeframe);
     string symbol = atf.Symbol();
 }
Exemple #20
0
 public DateTime? getLastCalculationDate(AssetTimeframe atf, AnalysisType analysisType)
 {
     return service.GetAnalysisLastCalculation(atf.Symbol(), analysisType.toString());
 }
 private Mock<IQuotationService> mockedQuotationService(AssetTimeframe atf, DateTime lastAnalysisDate, AnalysisType type)
 {
     Mock<IQuotationService> obj = new Mock<IQuotationService>();
     obj.Setup(mqs => mqs.getLastCalculationDate(atf, type)).Returns(lastAnalysisDate);
     return obj;
 }
Exemple #22
0
        public bool Start(AssetTimeframe atf, AnalysisType[] types)
        {
            this.Symbol = atf.Symbol();
            this.types = types;

            try
            {
                Data = _dataService.GetFxQuotations(this.Symbol, true).ToArray();
                Data.AppendIndexNumbers();

                Debug.WriteLine(string.Format("+;SimulationService.Start - Data loaded (Items: {0})", Data.Length));

                if (types.Contains(AnalysisType.Price)){
                    _priceAnalyzer = new PriceAnalyzer(atf);
                    ((Analyzer)_priceAnalyzer).injectQuotationService(quotationService);
                }

                if (types.Contains(AnalysisType.Trendline))
                {
                    _trendAnalyzer = new TrendlineAnalyzer(atf);
                    ((Analyzer)_trendAnalyzer).injectQuotationService(quotationService);
                }

                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
Exemple #23
0
 public CandlestickAnalyzer(AssetTimeframe atf)
     : base(atf)
 {
 }
Exemple #24
0
 /* CONSTRUCTORS */
 public PriceAnalyzer(AssetTimeframe atf)
     : base(atf)
 {
 }
Exemple #25
0
 public CandlestickAnalyzer(IAnalysisDataService dataService, AssetTimeframe atf)
     : base(atf)
 {
     this._dataService = dataService;
 }
Exemple #26
0
 public AdxAnalyzer(AssetTimeframe atf)
     : base(atf)
 {
     initialize_specific();
 }
Exemple #27
0
 public void runFull(IAnalyzer analyzer, DataItem item, AssetTimeframe atf)
 {
 }
Exemple #28
0
 public AdxAnalyzer(IAnalysisDataService dataService, AssetTimeframe atf)
     : base(atf)
 {
     initialize_specific();
     this._dataService = dataService;
 }
Exemple #29
0
 public void runRightSide(IAnalyzer analyzer, DataItem item, AssetTimeframe atf)
 {
 }
Exemple #30
0
        public AssetTimeframe GetAssetTimeframe(Timeframe timeframe)
        {
            var assetTimeframe = AssetTimeframes.SingleOrDefault(a => a.timeframe == timeframe);
            if (assetTimeframe == null)
            {
                assetTimeframe = new AssetTimeframe(this, timeframe);
                AssetTimeframes = AssetTimeframes.Concat(new[] { assetTimeframe });
            }

            return assetTimeframe;
        }