Questions from Beginners MQL4 MT4 MetaTrader 4 - page 102

 
STARIJ:

Price on the chart on the vertical axis from bottom to top, and time and bar numbering on the horizontal axis to the right

Zero bar is the last bar currently available. The following bars exist in the history, but are not available for the tester. Later, when this bar is calculated, the tester will go to the next bar, which will become zero for him.


So, I understand correctly, as soon as the Open price of the next bar appears in the tester, it becomes null[0]. And if the indicator is made in the way that it is calculated 500 bars before the current [0] bar, it means that the tester will calculate the indicator for ~ 2 years (500 D1 bars) before the current [0] bar...

This raises the following question:

Now the indicator is based on Start() event processing - ancient version. I feel that during testing in each call of iCustom() the indicator is calculated on the previous 500 bars, the 1600 tester runs were calculated for an hour and a half.
We can build the indicator on OnCalculate() event processing, which allows calculating only the uncomputed bars before the next OnCalculate() - but it is possible to do it on a real data flow in a current time - as I understood from the MQL4 Reference.
In the tester, it will reduce the number of calculated bars at each call of iCustom() ?

 
MikeZv:

So I understood correctly, as soon as Open next bar price appeared in the tester - it becomes null[0]. And if the indicator is made in such a way, that it starts to be calculated 500 before the current [0] bar, it means, that tester will calculate the indicator for ~ 2 years (500 bars D1) before the current [0] bar...

This raises the following question:

Now the indicator is based on Start() event processing - ancient version. As you feel, during testing in each call of iCustom(), the indicator is calculated on the previous 500 bars, 1600 tester runs were calculated for an hour and a half.
We can build the indicator on OnCalculate() event processing, which allows calculating only the uncalculated bars before the next OnCalculate() - but it is done on a real data flow in the current time - as I understood from the MQL4 Reference.
In the tester, it will reduce the number of calculated bars at each call of iCustom() ?


The indicator is just written crookedly, so it's slow, I need a professional rewrite, then it will read the whole history and very fast... that's all...

 
Nikolay Ivanov:


The indicator is just crookedly written, so it's slow, you need a professional rewrite, then it will read the whole story and very fast... that's all...


Already rewritten ... :)

 

Wrote new indicator [ onCalculate()] based on old one [on Start()], above question was raised.
I run a script comparing them to each other for 5 years (period D1) - one to one, all values coincide.
I copied the same ICustom() into Expert Advisor and have it displayed in a file whentesting the Expert Advisor.
The old indicator values are displayed as in the script, the new indicator values are all different !!!
Why is iCustom() in an Expert Advisor for an indicator on Start() outputting the same values as in the script,
but for an indicator on OnCalculate() the output in the Expert Advisor is different from the output in the script ?


 

Hi all.

Guys, can you advise me who has come across this?

Some binary brokers, e.g. Grand Capital, accrue income and debit the account not through profit on a trade, but as income to/from the balance(s) of the account.


I have several alternative working options on how to find out the result of a trade, but still the most correct one is to read the value of the balance sheet line and the amount of gains/losses.

So the question is - how can this be done "in the moment" but over the entire transaction history? That is, I'm interested in some (included in MQL4) function that would look through all balance type records and read the comment and the value itself. This is the first time I've faced such a task in several years of programming.

 
MikeZv:

I wrote a new indicator [on OnCalculate()] based on the old one [on Start()], this issue was raised above.
I run the script comparing them to each other for 5 years (period D1) - one-to-one, all values coincide.
I copied the same ICustom() into Expert Advisor and have it displayed in a file whentesting the Expert Advisor.
The old indicator values are displayed as in the script, the new indicator values are all different !!!
Why is iCustom() in an Expert Advisor for the indicator on Start() it outputs the same values as in the script?
and for the indicator on OnCalculate() the output in the Expert Advisor is different from the output in the script ?


It can take a long time to guess.

I would check the code for wrong data type conversion, doubling of variable names (i.e. in the old code the names are used that are now reserved) - as a result the variable is not getting the values it should get (first of all, check variable names used in OnCalculate - open, high, low, close, etc. - You may come across them quite often in old code).
And as for iCustom, it is the simplest variant, and errors here most likely can be related to incorrectly passed parameters (again, for the reasons given above).

Print all values, or run in debug mode and check where there is a discrepancy.
 
Artyom Kuraev:

It can take a long time to guess.

I would check the code for incorrect data type conversion, duplicated variable names (i.e. old code uses names which are now reserved) - as a result the variable is picking up wrong values which it should get (first of all check variable names used in OnCalculate - open, high, low, close, etc. - You may come across them quite often in old code).
And as for iCustom, it is the simplest variant, and errors here most likely can be related to incorrectly passed parameters (again, for the reasons mentioned above).

Print all values, or run in debug mode and check where the discrepancy is going.
Output of both indicators in the script is the same.

Expert has COOPERATED lines with iCustom() from the script. The same parameters are passed.

 
MikeZv:

The Expert COPYs the lines with iCustom() from the script. The same parameters are passed.

The fact that they are copied may cause errors. I only suggested possible causes and what I would check first.

The second point, and this is probably the most obvious answer, is that the indicator itself is overpriced and will give one value when applied to history and another one when working in strategy tester mode. I wrote about it once, you can see it in two pictures.

I am not insisting on anything at all, and my answer will be based on my experience. If you are sure that none of the options I suggested is suitable, just wait for other answers or give much more background information :)

 
Artyom Kuraev:

Hi all.

Guys, can you advise me who has come across this?

Some binary brokers, e.g. Grand Capital, charge income and debit the account not through profit on a trade, but as income to/from the balance(s) of the account.


I have several alternative working options on how to find out the result of a trade, but still the most correct one is to read the value of the balance sheet line and the amount of gains/losses.

So the question is - how can this be done "in the moment" but over the entire transaction history? That is, I'm interested in some (included in MQL4) function that would look through all balance type records and read the comment and the value itself. This is the first time I've faced such a task in several years of programming.


#define  OP_BALANCE 6
#define  OP_CREDIT  7

Plus

OrdersHistoryTotal
StringFind(OrderComment(),txt,0)
 
Taras Slobodyanik:

plus

THANK YOU!

It all worked out!
Reason: