Testing with Fake MarketSeries Data
Testing with Fake MarketSeries Data
03 Feb 2015, 20:43
I am trying to set up unit tests for indicators that I am developing. How can I use fake MarketSeries data in the Calculate method.
Below is an example of code where I would like to test with the fake MarketSeries data.
public class _SwingStrength : Indicator { ... public override void Calculate(int newBarFormingIndex) { ... double potentialSwingBarHigh = CalculateBarValue(newBarFormingIndex, "High", false, false); ... } private double CalculateBarValue(int barIndex, string highOrLow, bool useHeikenAshiBars, bool useOpenClose) { double returnError = -1; if (useHeikenAshiBars) {...} else if (useOpenClose) {...} else { if (highOrLow == "High") return MarketSeries.High[barIndex]; else if (highOrLow == "Low") return MarketSeries.Low[barIndex]; else return returnError; } return returnError; } }
Any help you can give me is greatly appreciated!
Greg
Replies
AlexanderRC
04 Feb 2015, 22:23
You even try to not inherit from Indicator and reimplement the feauters you require from it as stubs
And do conditional compilation whether you are running as an externally invoked unit test or inside cAlgo compilation engine. But cAlgo compilation engine ignores symbols defined in Visual Studio properties. You may have to #define you conditional compilation manually or at the unit test project which would not depend on cAlgo API directly and could be run independently.
See /forum/calgo-support/3827 for more info.
@AlexanderRC
gregschr
04 Feb 2015, 04:45
I think I figured this out. By introducing a seam between my indicator and the Indicator class I can now override the MarketSeries getter and setter (and any other properties or methods) in my unit tests. When the indicator is running normally in cAlgo, the MarketSeries data from the Indicator class is returned as usual.
@gregschr