[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 410

 
How accurate is the testing on the strategy tester built into MT4? How can it be increased?
 
sergeev:

no


The problem here is simply in the loop. It goes through i from 0 to 2. You want 2 to 0.



Show me an example please, I did
 for(i = OrdersTotal(); i > 0; i--)
Didn't work.
 

sss2019:



Show me an example please, I did It didn't work


I made the script like this

int orderstotal = OrdersTotal();
        for(i = 0; i < orderstotal; i++ )
                {
                if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == FALSE) break;
                if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
                        {
                        if(OrderType() == OP_BUY)
                        if(OrderClose(OrderTicket(),OrderLots(),Bid,Slippage) == false)
                                {
                                Print(GetLastError());
                                }
                        if(OrderType() == OP_SELL)
                        if(OrderClose(OrderTicket(),OrderLots(),Ask,Slippage) == false)
                                {
                                Print(GetLastError());
                                }
                        if(OrderType() > 1)
                        if(OrderDelete(OrderTicket()) == false)
                                {
                                Print(GetLastError());
                                }
                        }
                Print(i," ",orderstotal);
                }

As a result, Print outputs the following

0 4

1 4

That's all, for some reason the loop does not print

2 4

3 4

I have added to the loop OrderSelect(i, SELECT_BY_POS, MODE_TRADES instead of I 0, i.e. the first order is always selected and the script works correctly. It turns out that when the loop deletes two orders, it tries to select the third order when there are only two orders in the list.

 
sss2019:


Made the script like this

In the end...

Examples
 
sss2019:

Please show me an example, I did

for(i = OrdersTotal(); i > 0; i--)

Didn't help.


because you still have to think.

for(i = OrdersTotal()-1; i >=0; i--)
 

Help me solve this dilemma

int i;
    double maxrange,range;
    double Ma1 = iMA(Symbol(),Period(),FastMaPeriod,0,MODE_EMA,PRICE_OPEN,i);
    double Ma2 = iMA(Symbol(),Period(),SlowMaPeriod,0,MODE_EMA,PRICE_OPEN,i);
   
                    while(Ma1 > Ma2)
                        {
                        i++;
                        Ma1 = iMA(Symbol(),Period(),FastMaPeriod,0,MODE_EMA,PRICE_OPEN,i);
                        Ma2 = iMA(Symbol(),Period(),SlowMaPeriod,0,MODE_EMA,PRICE_OPEN,i);
                        range = (Ma1 - Ma2)/Point;
                        if(range > maxrange) maxrange = range;
                        }

The script searches for the maximal distance between the lines. It outputs all values on all bars, the maxrange is 1.6235 on one bar and 1.6208 on the other one.

I try to print Print(maxrange); it prints 0.086, I don't understand why, I am dividing by Point

 
sss2019:

Help me solve this dilemma

The script searches for the maximal distance between the lines. It outputs all values on all bars, the maxrange is 1.6235 on one bar and 1.6208 on the other one.

I try to output Print(maxrange); it returns 0.086, I don't understand why at all, I'm dividing by Point


This is not a dilemma. A dilemma is when you don't know which of two solutions is best.

Well, first, the iMA() function has seven parameters, not six. Second, you have declared a variable by the int i string. And further on, the i variable is not initialized anywhere with a value. As a result, it is either zero or contains memory junk left over from the previous activity. And third, the while loop is arranged incorrectly. Well, let's say the i variable is equal to zero after initialization. Let's also assume that the Ma1 > Ma2 expression is also true. As a result, the while(Ma1 > Ma2) line will start the loop. At the next loop iteration we will find out that the (Ma1 > Ma2) expression is no longer true and the loop will be terminated. The variables Ma1 and Ma2 will not contain the distance that is maximal - the maximal distance was once. This condition will only show that Ma1 has now become less than or equal to Ma2.

Further, the maxrange variable will be initialized with a value only in the string range = (Ma1 - Ma2)/Point; Well, what if the condition if(range > maxrange) will never occur, because you don't initialize the maxrange variable with a value anywhere else in the code? So it turns out that you are comparing the result of calculations with memory cells' junk. Here you have incomprehensible prints as a result of code execution.

 
The thing is that I was outputting all MA values in the loop, and all values are correct, i.e. all MA values for this period have been enumerated. But calculation is wrong in this place - range = (Ma1 - Ma2)/Point;
if(range > maxrange) maxrange = range;
 
sss2019:
That's the point, I was outputting all MA values in the loop and all values are correct, i.e. all MA values for this period were searched. But calculation is wrong in this place - range = (Ma1 - Ma2)/Point;
if(range > maxrange) maxrange = range;

*Point

range = (Ma1 - Ma2)*Point





 
pako:

*Point

range = (Ma1 - Ma2)*Point

MA1 = 0.6526, MA2 = 0.6516. MA1-MA2 = 0.6526-0.6516 = 0.0010. Point = 0.0001. If multiplied, it is a bilibrary. 0,0010 * 0,0001 = 0,0000001
Reason: