Discussion of article "Enhancing the StrategyTester to Optimize Indicators Solely on the Example of Flat and Trend Markets"

To add comments, please log in or register
MetaQuotes Software Corp.
Moderator
208140
MetaQuotes Software Corp.  

New article Enhancing the StrategyTester to Optimize Indicators Solely on the Example of Flat and Trend Markets has been published:

To detect whether a market is flat or not is essential for many strategies. Using the wellknown ADX we demonstrate how we can use the Strategy Tester not only to optimize this indicator for our specific purpose but we as well can decide whether this indicator will meet our needs and we will get to know the average range of the flat and the trend markets which might be quite important to determine stops and targets of the markets.

The Idea

We build a pseudo-EA that does not trade! It has only three important functions. OnTick(), where we check the indicator and determine the market state, OnTester() where we write the final result to our csv-file and calcOptVal() where we calculate the value OptVal which is returned by OnTester() to the Strategy Tester for the ordering and the Genetic Algorithm. Its OnTester() function which is called at the and of an optimization pass returns a specific value and it adds a new line to a csv-file for an analysis after the whole optimization has finished.

Now our pseudo-EA is ready and we prepare the Strategy Tester for the Optimization:

  1. We disable "Genetic Algorithm" to test every combination.
  2. Set the "Optimized parameter" to Custom. This shows us more interesting pictures in the Optimization Graph.
  3. Make sure that the cache-file in ..\tester\caches was deleted
  4. For a csv-file make sure that fName is not empty and an existing csv-file in \tester\files was deleted
  5. If you leave a file name for the csv-file the optimizer will add line by line making it bigger and biggger until you'll in troulbe by its size!
  6. We choose symbol EURUSD.
  7. Period is set to H1 (here from 2015. 08. 13 to 2015.11.20).
  8. Model is set to "Open Price only".
  9. Don't forget to enable "Optimization".

After 25 minutes on my laptop from 2007 the Strategy Tester has completed the optimization and we find the resulting csv-file in ..\tester\files\.

In the Optimizations Graph we can see for example (bottom =LIM, right=PER):

Fig. 11 TesterGraph SwLim 100

Author: Carl Schreiber

kentaicm
164
kentaicm  

I am looking at the code.

What does the "RangesRaw    = FlatRange>0 ? TrndRange/FlatRange : 0.0; " question mark in the code stands for?

Carl Schreiber
Moderator
8167
Carl Schreiber  
kentaicm:

I am looking at the code.

What does the "RangesRaw    = FlatRange>0 ? TrndRange/FlatRange : 0.0; " question mark in the code stands for?

x = a>b ? y : z; is simple form of if (a>b) then x=y; else x=z;

See here: https://www.mql5.com/en/docs/basis/operators/ternary

Documentation on MQL5: Language Basics / Operators / Ternary Operator ?:
Documentation on MQL5: Language Basics / Operators / Ternary Operator ?:
  • www.mql5.com
, the third operand - "expression3" is performed. The second and third operands, i.e. "expression2" and "expression3" should return values of one type and should not be of void type. The result of the conditional operator execution is the result of expression2 or result of the expression3, depending on the result of expression1. Operator Use...
kentaicm
164
kentaicm  
Carl Schreiber:

x = a>b ? y : z; is simple form of if (a>b) then x=y; else x=z;

See here: https://www.mql5.com/en/docs/basis/operators/ternary

Thanks for the clarification. 

To add comments, please log in or register