Questions from Beginners MQL5 MT5 MetaTrader 5 - page 589
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
When checking the indicator step by step, I found a bounce in the subroutine behind the if {} and in which there is no W. Here is a simplified code to clarify the point:
//--- input parameters
input int w=10;
//---
{
int i;
//---
int co=0;
for(i=0;i<=w;i++)if(w==10){co++; Alert(co);}
//--- return value of prev_calculated for next call
return(rates_total);
}
Result (arlets):
2016.05.30 00:45:14.064 1 (EURUSD,H1) 11
2016.05.30 01:10:35.972 1 (EURUSD,H1) 10
........... etc. to 1.
2016.05.30 00:45:14.064 1 (EURUSD,H1) 1
Rule: If the expression in brackets is true, then operator1 is executed.
In code: operator1 is executed ALWAYS.
I think if() should work only once when the bracketed condition is true. But it actually occurs at each check, so all expressions in {} are executed at each step and chew machine time.
Questions: WHY did the CO variable grow from 0 to 11 during the loop? Why is Alert triggered at every step?
How many times do I have to tell you?
Look: you have w equal to 10,
You check w for 10: "if(w==10){co++; Alert(co);}" Do you think this expression is true?
Then why do you have the question?
When checking the indicator step by step, I detected a bounce in the subroutine behind the if {} and in which there is no W. Here is a simplified code to clarify the matter:
//--- input parameters
input int w=10;
//---
{
int i;
//---
int co=0;
for(i=0;i<=w;i++)if(w==10){co++; Alert(co);}
//--- return value of prev_calculated for next call
return(rates_total);
}
Result (arlet):
2016.05.30 00:45:14.064 1 (EURUSD,H1) 11
2016.05.30 01:10:35.972 1 (EURUSD,H1) 10
........... etc. to 1.
2016.05.30 00:45:14.064 1 (EURUSD,H1) 1
Rule: If the expression in brackets is true, then operator1 is executed.
In code: operator1 is executed ALWAYS.
I think if() should work only once when the bracketed condition is true. But it actually occurs at each check, so all expressions in {} are executed at each step and chew machine time.
Questions: WHY did the CO variable grow from 0 to 11 during the loop? Why Alert is triggered at every step?
Forum on trading, automated trading systems and trading strategy testing
Bugs, bugs, questions
Andrey Barinov, 2016.05.30 10:38
Apparently you have a typo in the code, and wanted to write like this:
Hello Gentlemen! I have a small problem when writing an EA(( The EA opens pending orders mostly all right, but sometimes I need to open orders very close to the current price, so how to prescribe that would open pending orders as close as possible?
How many times do I have to tell you?
Look: you have w equal to 10,
You check w for equal to 10: "if(w==10){co++; Alert(co);}" Do you think this expression is true?
Then why do you have the question?
My apologies for the stupid question and thank you for your patience and understanding. I was let down by mechanically moving the probe if(w==10){ Alert(I,"/",F); through the program looking for an error in steps. It happens sometimes when you hit a wall of your own ignorance of the reason, but once you stand aside from the problem for a while, the question sort of goes away by itself. What you perceive as "jarring" actually turns out to be an unaccounted-for request from another part of the programme. With thanks, Vladimir.
Hello, can you help me with the maths please?
How to know what will be the lot of the fifth position, if you know the lot of the first and that the lot of each new position increases in arithmetic progression.
The second option is that the lot increases with geometric progression.
Hello, can you help me with the maths please?
How to know what will be the lot of the fifth position, if you know the lot of the first and that the lot of each new position increases in arithmetic progression.
The second option is that the lot increases with geometric progression.
Are you banned from Google? I'm sorry, why are you so cruel? ))
arithmetic progression is defined by a formula.
thegeometric progress ion is given by the formula
I don't understand, for the first variant it is enough to multiply the first lot by 5, if it increases by the starting lot
For the second option: first position's lot* multiplier*5 ...but
I don't get it, in theory for the first option, it is enough to multiply the first lot by 5
For the second option, the lot of the first position * coefficient * 5 ...but
It's okay, I've forgotten the maths myself since school )) I dug out a book on mathematics, retyped the definition of arith. progression.
-------------
A sequence of numbers, each of which, starting from the second, is obtained from the previous one by adding a constant number d, called the difference of an arithmetic progression.
If the first term is a1, then the arith. prog. with length n has the form:
a1, a1+d, a1+2*d, ...., a1 + n*d
The code in MQL is like this, I've created a simple example
It's all right, I've forgotten maths myself since school ))