Questions from Beginners MQL5 MT5 MetaTrader 5 - page 486

 

Question - does the tester take swap into account?

Calculated in Excel (cent account) and got a strange result

P.P. Data Type Lot Price MaxHigh MaxEqDrd
1 2014.06.12 09:52 sell 0.1 1.6824 0.16824 1.7179 -3.55
2 2014.06.12 15:18 sell 0.2 1.6831 0.33662 1.7179 -6.96
3 2014.06.12 17:52 sell 0.3 1.6836 0.50508 1.7179 -10.29
4 2014.06.12 19:10 sell 0.5 1.6839 0.84195 1.7179 -17.00
5 2014.06.12 23:00 sell 0.8 1.6845 1.3476 1.7179 -26.72
6 2014.06.16 09:59 sell 1.3 1.6985 2.20805 1.7179 -25.22
7 2014.06.19 09:58 sell 2.1 1.7017 3.57357 1.7179 -34.02
8 2014.06.19 11:21 sell 3.4 1.7018 5.78612 1.7179 -54.74
9 2014.06.19 20:40 sell 5.5 1.7033 9.36815 1.7179 -80.30
10 2014.06.19 22:12 sell 8.9 1.7036 15.16204 1.7179 -127.27
11 2014.06.20 05:10 sell 14.4 1.7047 24.54768 1.7179 -190.08
12 2014.06.20 05:22 sell 23.3 1.7049 39.72417 1.7179 -302.90
13 2014.06.26 12:38 sell 37.7 1.7030 64.2031 1.7179 -561.73
14 2014.06.26 15:18 sell 61.0 1.7033 103.9013 1.7179 -890.60
15 2014.06.27 06:51 sell 98.7 1.7050 168.2835 1.7179 -1273.23
16 2014.06.30 17:37 sell 100.0 1.7079 170.79 1.7179 -1000.00
17 2014.06.06.30 17:37 sell 59.7 1.7079 101.96163 1.7179 -597.00
18 2014.07.01 09:03 sell 100.0 1.7100 171 1.7179 -790.00
19 2014.07.01 09:03 sell 100.0 1,7100 171 1,7179 -790.00
20 2014.07.01 09:03 sell 58.4 1,7100 99,864 1,7179 -461.36
21 2014.07.01 11:30 sell 100.0 1,7110 171.1 1,7179 -690.00
22 2014.07.01 11:30 sell 100.0 1,7110 171.1 1,7179 -690.00
23 2014.07.01 11:30 sell 100,0 1,7110 171,1 1,7179 -690,00
24 2014.07.01 11:30 sell 100,0 1,7110 171,1 1,7179 -690,00
25 2014.07.01 11:30 sell 18.1 1 1.7110 30.9691 1.7179 -124.89
26 2014.07.02 02:33 sell 100.0 1.7145 171.45 1.7179 -340.00
27 2014.07.02 02 02:33 sell 100.0 1.7145 171.45 1.7179 -340.00
28 2014.07.02 02:33 sell 100.0 1.7145 171.45 1.7179 -340.00
29 2014.07.02 02:33 sell 100.0 1.7145 171.45 1.7179 -340.00
30 2014.07.02.02:33 sell 100.0 1.7145 171.45 1.7179 -340.00
31 2014.07.02 02:33 sell 100.0 1.7145 171.45 1.7179 -340.00
32 2014.07.02 02:33 sell 76.5 1.7145 131.15925 1.7179 -260.10
33 2014.07.02.02 11:32 sell 100.0 1.7176 171.76 1.7179 -30.00
34 2014.07.02 11:32 sell 100.0 1.7176 171.76 1.7179 -30.00
35 2014.07.02 11:32 sell 100.0 1,7176 171.76 1,7179 -30.00
36 2014.07.02 11:32 sell 100.0 1,7176 171.76 1,7179 -30.00
37 2014.07.02 11:32 sell 100.0 1,7176 171.76 1,7179 -30.00
38 2014.07.02 11:32 sell 100.0 1,7176 171.76 1,7179 -30.00
39 2014.07.02 11:32 sell 100.0 1,7176 171.76 1,7179 -30.00
40 2014.07.0202 11:32 sell 100.0 1,7176 171.76 1,7179 -30.00
41 2014.07.02 11:32 sell 100.0 1,7176 171.76 1,7179 -30.00
42 2014.07.0202 11:32 sell 100.0 1,7176 171.76 1,7179 -30.00
43 2014.07.02 11:32 sell 94.6 1.7176 162.48496 1.7179 -28.38
Total:2865.5 4909.88611 -12756.34
Average opening price -> 1.7134

High 04.07.2014 1.7179

Drawdown in pips -> 0.0045
Drawdown in currency ->12756,34

Drawdown according to code -> 13823,00
Drawdown according to tester report ->23669,03

TP - > 1.7084
Profit in pips -> 0.0050
Profit according to calculation - > 14465.91

Profit according to report - > 13915.05


How does the drawdown not add up - especially to the tester's report? There were no closed positions before!

 

This is what the situation on the chart looks like



 
I have attached the calculation in excel - maybe I was stupid there!?
Files:
Calculation.zip  104 kb
 

-Aleks-:

The global variable is relevant for real market work - I need test information - that's why I didn't bother with it.

I wasn't talking about GlobalVariable, I was talking about the level of global variables.

-Aleks-:

What is equity and balance - of course I know, but I still do not know how drawdown is calculated. My code examples show that I tried to take both balance and funds as maximal ones and similarly I took balance and funds as minimal.

I haven't mastered the formula of calculating the drawdown in the tester, but you may try to calculate the difference between your balance before the order opening and the minimum equity before the order closing. Or, calculate the minimum and maximum funds and the maximum difference will be the maximum drawdown.

-Aleks-:

Why do you think that the inequalityif (BalansNew<BalansMax) ProfitNew=BalansNew-BalansMax; never holds? It is only not fulfilled on the bar when the new balance maximum is reached (or equity - still not true), but at that point I fix the profit drawdownProfitMin=ProfitNew.

This is more relevant as the maximal drawdown is usually not reached at the moment of order closing, and the goal is to calculate the average amount of money necessary for the work of the EA.

I agree, I was not attentive enough.

But the drawdown is not per day but per order(s) lifetime and after that the equity becomes a balance. This is exactly the places on the tester chart where the equity and balance lines are in one point.

 
Alexey Viktorov:

I wasn't talking about GlobalVariable, I was talking about global variable level.

Apparently I misunderstood you - my variables are initialized before code execution block int start(), so there shouldn't be any problems with mashing or something like that... Or there is another reason?


Alexey Viktorov:

I haven't got into the formula of calculating the drawdown in the tester, but we can try to calculate the difference between the balance before the order opening and the minimum equity before the order closing. Or, you can try to count the difference between the maximum and minimum funds and the maximum difference will be the maximum drawdown.

And if there are many orders, should we count for each order and choose the largest one? In my example, we can see that the drawdown calculated was twice less compared to the tester's result and according to your algorithm it will be even less.

Alexey Viktorov:

The frequency of writing to the file is a purely personal matter, but the drawdown is not counted for the day, but for the lifetime of the order(s), and then the funds become a balance. This is exactly those places on the tester's chart where lines of equity and balance are in one point.

It does not matter when the tester takes into account the drawdown - the fact is that it will be maximal on a certain day and the result should coincide, and it doesn't - and that's surprising.

I need the drawdown by day to test the trading portfolio - to understand how much funds may be needed at one time and how often.

 

Mathematically (the drawdown turned out to be 23497.1 against the tester's 23669.03), the drawdown is close to the size of the segment which symbolises the change in the deposit - i.e. the difference between the maximum Equity value and the minimum Equity value.

 
-Aleks-:

I must have misunderstood you - my variables are initialized before the code execution block int start(), so there shouldn't be any problems with mashing or something... Or there is another reason?


And, if there are a lot of orders, should we calculate for each order and select the largest one? In my example you can see that the calculated drawdown is almost half of that of the tester and according to your algorithm it will be even less.

It doesn't matter when the tester takes the drawdown into account - the fact is that it will be maximal on a certain day and the result should coincide, and it doesn't - and that's surprising.

I need the drawdown by day to test the trading portfolio - to understand how much funds might be needed at one time and how often.

Not exactly. Not for each order, but from opening the first order to closing the last one. I.e., from OrdersTotal() == 0 to OrdersTotal() == 0.

This is the point from the opening of the first order to the closing of the last one; we should determine the drawdown since the real launch will take place at any time, and accordingly, the drawdown may happen during 24-hour periods.

All the rest... I don't like to look into other people's research, as well as in long code, I can discuss ways of solving some problems, but not code examples. But it's strange that no one corrected my assumptions about how the drawdown is calculated...

Anyway, I don't like your method of calculating drawdown. It seems to me that it prints so often, that it takes a lot of patience to figure it out.

 

Karputov Vladimir:
Не кусок, а программу, которую можно скомпилировать и прогнать в режиме отладки.

Sorry to bother you, while cleaning the program to find the problem of the tester stopping, in the text of the program I found a violation of its algorithm. The compilation was going fine, but the tester stopped without indicating the failure point
 
Alexey Viktorov:

Not exactly. Not for each order, but from the opening of the first order to the closing of the last. I.e., from OrdersTotal() == 0 to OrdersTotal() == 0.

This is the point from the moment of opening the first order to the closing of the last one; we should determine the drawdown since the real launch will take place at any time, not at 0:00, thus the drawdown may happen during a 24-hour period.

So, in this example these conditions are exactly observed - the orders are opened and tracked to close at every tick.

If indeed the calculation goes from equity maximum to equity minimum, then this showdown will help me rethink the tester's readings...

Alexey Viktorov:

Anyway, I didn't like your method of calculating the drawdown. It seems to me that it prints so often that it takes a lot of patience to figure it out.

What I'm interested in is how much money the EA actually needs - i.e. the real drawdown (current loss) from order opening till its closing minus any lost profit.

It prints once a day - that's not often at all, and it's needed for certain purposes.

 
Hello!

At first glance, the task seems as simple as three cents. BUT! ....
There is a line of any oscillator in the indicator window, which wiggles relative to "0" with different amplitude.
The actual problem is:
- At "0" crossing from bottom to top, draw an arrow at the bottom border of the indicator window,
- At "0" crossing from the top downwards, to draw an arrow near the upper border of the indicator window,
- at self-scaling of the oscillator chart in the indicator window, the arrows should automatically remain at their borders of the indicator window.
I.e., scrolling the chart backwards and forwards through the history, or changing its horizontal scale, the arrows should always remain at the boundaries of the indicator window automatically.

Please don't give any advices, "help me with money")). I need an example of a working code, which implements this function, or a link to one.

Thanks in advance!
Reason: