Open project - tester-optimiser in-house - page 2

 
However, I don't know the compiler's reaction beforehand, will it let the trading constants in the indicator body through or not? <br / translate="no"> Most likely it will.

Of course it should, they are all just integers, not a separate type.

A little tip.

Of course, it is desirable not to rewrite the strategy for the tester. Once written, the strategy should work in the tester and without it (in the real world).

This can be done with the help of libraries.
1. All functions related to trading, change their names a little (my... - not very good, maybe better _....).
2. Create 2 libraries. The first one contains code for testing (without actually sending orders), the second just duplicates parameters in calls of standard functions. Switching Work/Testing is done simply by replacing the library.

Of course, we could put it all in one library and introduce a global parameter to switch, but it is probably unnecessary.

And it would be wonderful to introduce to MT one more function, which, imho, would radically simplify the writing of such a tester - the function of setting the current last bar.

I.e. suppose we have 1000 bars in the history on which we are testing.
Let's define 200 bar as the last one and use Close[200] instead of Close[0]. This feature should work in all built-in functions.

The tester will then look like a loop on the bar number in which this value is set (the last bar in the test) and the call of the start function in the strategy.

In fact, it's not that simple :))
I need some more points ...
 
I don't understand it, please explain
2. We create 2 libraries. The first library contains code for testing (without actually sending orders), the second one simply duplicates the parameters in the standard function calls. Switching between working/testing is done by simply replacing the library
.
Is the phrase "code for testing" a tester code or EA code? Be more specific.

That too
I.e. let us have 1000 bars in the history on which we are testing.
We define 200 bars as the last one, then instead of Close[0] we use Close[200] everywhere.
And this fic should work (affect) in all inline functions.


Any EA code is easily converted to code for an indicator :
We take the start() block of the EA, add a construct for( testerconter=Bars;testerconter>=0;testerconter--)
{
close it with a bracket at the end
}
Replace all places that use references with [testerconter+reference].

Here is an example from the built-in MACD_sample.mq4 Expert Advisor .
Source code:
   MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
   MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
   SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
   MaCurrent=iMA(NULL,0,MATrendPeriod,MODE_EMA,0,PRICE_CLOSE,0);
   MaPrevious=iMA(NULL,0,MATrendPeriod,MODE_EMA,0,PRICE_CLOSE,1);


Modified

   MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,testerconter+0);
   MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,testerconter+1);
   SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,testerconter+0);
   SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,testerconter+1);
   MaCurrent=iMA(NULL,0,MATrendPeriod,MODE_EMA,0,PRICE_CLOSE,testerconter+0);
   MaPrevious=iMA(NULL,0,MATrendPeriod,MODE_EMA,0,PRICE_CLOSE,testerconter+1);


As you can see, there is no problem at all. If you want, you can always redefine testerconter=0 if
code is executed in the Expert Advisor body, not in Expert Advisor body .

 
Is the phrase "code for testing" a tester code or an Expert Advisor code? Be more specific.

In the first library the function
_OrderSend(Symbol(), OP_SELL, 1, Bid, 5, Bid + Stop * Point, Bid - Take * Point);


emulates order execution in the tester, i.e. adds it to the list of orders in the tester and does not send the order to the server.

In the second library, this function simply calls the embedded function

int _OrderSend( string symbol, int cmd, double volume, double price, int slippage, 
                double stoploss, double takeprofit, string comment=NULL, int magic=0, 
                datetime expiration=0, color arrow_color=CLR_NONE) 
{
   return (OrderSend(symbol, cmd, volume, price, slippage, stoploss, 
                        takeprofit, comment, magic, expiration, arrow_color) );
}


Any code of the Expert Advisor can be easily reworked in the code for the indicator :
We take the start() block of the EA, add a construct for(testerconter=Bars;testerconter>=0;testerconter--)
{
close it with a bracket at the end
}
Replace all places that use references with [testerconter+reference]

That's what I mean.
It would be easier to call the function that sets value of the variable testerconter in MT (0 by default) instead of replacing it and this substitution ([testerconter+reference]) would be done in MT itself.
Then we would not have to make these substitutions in the strategy itself.

for(testerconter=Bars;testerconter>=0;testerconter--)
{
   SetTestPoint(testerconter);
      далее текст эксперта без переделки,
      или лучше вызов его функции start (или _start)
}



Please replace pre with. pre to quote in "i.e. let's say we have 1000 bars in ...".
otherwise the page is gone again.

 
I replaced it with quote, it looks like your text is going away, make a forced translation of the string in your example
about
int _OrderSend( string symbol,....


My conclusion: it seems we are talking about the same thing. We can forget about the current last bar request for now -
I have to try to do it that way.
For now just redefine standard trading functions, the prefix _. , it's even more respectable :)
 
to avm
Testing in this way is possible. And it's good enough. But, unfortunately, you won't get universalism. <br / translate="no"> I spent a couple of weeks on such tests. At first sight it seems simple.


I suspect that you tested "with a lot of blood", i.e. you didn't redefine trading functions. And every new test
. Every new test requires a new tester-indicator to be written. But you only need to do it once - and no problems.
If I'm wrong - post the functions - don't be stingy.
 
Another point.

It seems that we can'tcall directly the startfunction from the Expert Advisor.
Therefore, it would be better to write the Expert Advisor's code in a library and have there functions _init, _deinit and _start.

In the Expert Advisor, we will write
#include ".....";
   ...............

int init()
{
   return(_init());
}

int deinit()
{
   return(_deinit());
}

int start()
{
   return(_start());
}


It's a bit unclear, though, what the parameters are.

 
By the way, you can combine several EAs/signals on one chart.
As it is done in Omega:
#include "A1.....";
#include "A2.....";
   ...............

int init()
{
   _initA1();
   _initA2();
   return(0);
}

int deinit()
{
   _deinitA1();
   _deinitA2();
   return(0);
}

int start()
{
   _startA1();
   _startA2();
   return(0);
}


It's not very nice, but it will work.
In general, a homemade event processing system will work :))

 
Maybe it's easier? You make a parser script, which is applied to an mq4-file (with Expert Advisor code).
It processes this code - inserts all sorts of include, working arrays for Balance , Equity, etc,
renames variables Lots into _Lots (and others). In general, it does the rough work.
I will only have to file the output and go. :)
Simple conveyor method.
 
to avm<br / translate="no">
Testing in this way is possible. And it's good enough. But, unfortunately, you won't get universalism. I have spent a couple of weeks on such tests. At first glance it seems simple.

I suspect that you tested "with a lot of blood", i.e. you didn't redefine trading functions. And each new test required you to write a new tester indicator. But you only need to do it once - and no more problems. If I'm wrong, I want you to post functions - don't be stingy.

Absolutely right. "Big blood." There were no substitutions. I have made such testers back in MT3.x. MQL4 is as different from MQL2 as sky is from earth. However, I have not taken advantage of MQL4. I have a psychological stupor. I should have thought first, and then worked.
The woman was advised: "Think first, speak later". The woman replied: "How can I think about what I haven't said yet".
 
I got a little ahead of myself about the parser, the functions need to be written first. But I remember that the developers said there won't be a multi-currency tester (portfolio tester). Or am I confusing something? If I'm not confused - all the more reason to write your own.
Reason: