Questions from Beginners MQL5 MT5 MetaTrader 5 - page 589

 
admoon:



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?

 
admoon:



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:

int i;
//---
   int co=0;
   for(i=0;i<=w;i++)
     {
      if(i==10)
        {
         co++; 
         Alert(co);
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);

 
Hello Gentlemen! I have a small problem with writing an EA(( the EA opens pending orders mostly ok, 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?
 
barudkinarseniy:
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?
I think I got it) If anyone is interested, here is how it works
 double ilow = iLow(Symbol(),TimeFrames_3,1);
 double ihigh = iHigh(Symbol(),TimeFrames_3,1);
 
 double OpenPriceBuy = NormalizeDouble(MathMax(ihigh,Ask + Point*SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL)),Digits);
 double OpenPriceSell = NormalizeDouble(MathMin(ilow,Bid - Point*SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL)),Digits);
 
 int StepST = (int)MathMax(OpenPriceBuy - OpenPriceSell,SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL));
 double lots = LotsByRisk(StepST);
 
Artyom Trishkin:

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.

 
mila.com:

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

 
mila.com:

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

#define  LEN 5 // задали длину последовательности

int start()
{
    int d = 4;    // это разность, любое значение
    int a[LEN];   // тут храним ариф. посл.
    a[0] = 3;     // любое стартовое значение, задаете сами
    Print(0, "  ", a[0]);

    for (int n = 1; n < 4; n++)
    {
       a[n] = a[0] + (n*d);
       Print(n, "  ", a[n]);
    }
}

2016.05.31 23:08:52.433 ChangeTimeFrame EURUSD.e,M1: 3  15
2016.05.31 23:08:52.433 ChangeTimeFrame EURUSD.e,M1: 2  11
2016.05.31 23:08:52.433 ChangeTimeFrame EURUSD.e,M1: 1  7
2016.05.31 23:08:52.433 ChangeTimeFrame EURUSD.e,M1: 0  3
 
Alexey Volchanskiy:

It's all right, I've forgotten maths myself since school ))

I'm going for a walk, then I'll write the code for the geometry program.