Download MetaTrader 5

MQL5 Indicator unittesting

To add comments, please log in or register
aseidel
106
aseidel  

Hello,

i need an advice how i can unit test code which uses an Indicator. My problem is, i can not figure out how i can feed an indicator with artifical data.

Perhaps somebody can give me an hint


Thanks, Alex






phi nuts
2184
phi nuts  
aseidel:

Hello,

i need an advice how i can unit test code which uses an Indicator. My problem is, i can not figure out how i can feed an indicator with artifical data.

Perhaps somebody can give me an hint 

Thanks, Alex

I don't understand what you meant by "unit test code which uses an indicator". Perhaps, you should explain and give example.

Feeding artificial data can be done if we using original calculation. not some mql5 function. For example, for Moving Average, instead using iMA, we could you original Moving Average calculation like we found in MetaEditor, or we can also use IncMAOnArray like the one in code base.

aseidel
106
aseidel  
phi.nuts:

I don't understand what you meant by "unit test code which uses an indicator". Perhaps, you should explain and give example.

Feeding artificial data can be done if we using original calculation. not some mql5 function. For example, for Moving Average, instead using iMA, we could you original Moving Average calculation like we found in MetaEditor, or we can also use IncMAOnArray like the one in code base.

I usually write Unit Tests to assure my classes do exactly what i want. These Unit-Test works with some well defined input values and compare the results with expected values. If my class under tests uses an indicator i have an problem. I cant predict the result of the indicator, because he uses real-time date and no artificial test data to provoke certain conditions.

So the simple question is, how can I feed the indicator with my own rates. Or how other people handle this problem (Call onCalculate by the testclass, write a mock class or something else)

At the moment I think, the best way is to implement a mock (dummy) class for the indicator and use a provider to inject this dependency in my class under test. But i actually don't want reimplement an complete indicator just to be able to test classes which uses this indicator, as your links guess.

Thanks,

Alex


 

phi nuts
2184
phi nuts  
aseidel:

I usually write Unit Tests to assure my classes do exactly what i want. These Unit-Test works with some well defined input values and compare the results with expected values. If my class under tests uses an indicator i have an problem. I cant predict the result of the indicator, because he uses real-time date and no artificial test data to provoke certain conditions.

So the simple question is, how can I feed the indicator with my own rates. Or how other people handle this problem (Call onCalculate by the testclass, write a mock class or something else)

At the moment I think, the best way is to implement a mock (dummy) class for the indicator and use a provider to inject this dependency in my class under test. But i actually don't want reimplement an complete indicator just to be able to test classes which uses this indicator, as your links guess.

Thanks,

Alex

Now you're talking :).

I ... never try that.  I think you're the first person in this forum who asked that question. Hopefully there are other forumer who can solve this.

Sorry. 

 

chuck_cug
5
chuck_cug  
any progress? where should u put your unittest in? a script or at the begining of the ea start function?and how can u feed the data?
Uwe Goetzke
1487
Uwe Goetzke  

I build unit test for a class which can be tested with a script  and than use that class in the indicator.

If you introduce a method to feed your class with prices you can use that method also for 'articial' data.

To add comments, please log in or register