[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 180

 

When working with numbers of type double, when you need to assign some value to a variable (e.g. zero), different authors have different spellings. For example, a=0; or a=0.0; or a=0.0000; Is there any difference in terms of correct program operation?

 

if ((OrderSymbol()==Symbol()) && ((OrderMagicNumber()==44) || (OrderMagicNumber()==55)) && (ticket==0)){

OrderDelete(OrderTicket());

int err1=GetLastError();

Print(err1);}

This piece of code has been working fine for a while now...now an error ERR_OFF_QUOTES is returned. Please note, the error is returned by OrderDelete, even if the ticket number is entered manually. Can anyone clarify the situation? Thank you.

 
Elenn:

When working with numbers of type double, when you need to assign some value to a variable (for example, zero), different authors have different spellings. For example, a=0; or a=0.0; or a=0.0000; Is there any difference in terms of correct program operation?


No, there is no rule. But personally, I prefer to write constant double values using a dot.

For example:

if ( a == 1.0 )
{}

// ...

b = 3.0;

First, a quick glance at the text shows that the value type is double.

Secondly, it avoids some errors. Compare:

double a=2/3;
double b=2.0/3.0;

Print("a=",a," b=",b);
 

Please help. Doesn't want to execute the code:

int start()
{
int pre12;
{
if(PRICE_CLOSE>PRICE_OPEN)
pre12=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,"",Bid-100*Point,Ask+100*Point,CLR_NONE);
}
return;

}

I.e., as intended, if candle is ascending - open.

Everything compiles. But nothing happens during the test. I.e. it doesn't place any orders. Poke a hole in the error, please...

 
NaVolne:

Please help. The code does not want to execute:

int start()
{
int pre12;
{
if(PRICE_CLOSE>PRICE_OPEN)
pre12=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,"",Bid-100*Point,Ask+100*Point,CLR_NONE);
}
return;

}

I.e., if the candle is going up, it opens.

Everything compiles. But nothing happens during the test. I.e. it does not place any orders. Please, just point the finger at the error.

Which candlestick is the current candlestick on the chart? The previous day's candlestick? The previous week's candlestick? If it is the previous day's candlestick, for example... it would look like this

if(iOpen(NULL,1440,1)<iClose(NULL,1440,1)) the iOpen/iClose helplet clearly describes everything

 
NaVolne:

Please help. Doesn't want to execute the code:

int start()
{
int pre12;
{
if(PRICE_CLOSE>PRICE_OPEN)
pre12=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,"",Bid-100*Point,Ask+100*Point,CLR_NONE);
}
return;

}

I.e. as intended, if the candle is going up, it opens.

Everything compiles. But nothing happens during the test. I.e. it doesn't place any orders. Poke a hole in the error, please...

The point is that PRICE_CLOSE and PRICE_OPEN are constants, not functions and not arrays of time-series. To get the values of the open and close prices of candlesticks, we need to refer to functions(iOpen and iClose) or arrays of time-series(Open and Close).

To find out more, read the tutorial, for example, this section explains the predefined variables (which include the time-series arrays you want, Open and Close).

 
Elenn:

When working with numbers of type double, when you need to assign some value to a variable (for example, zero), different authors have different spellings. For example, a=0; or a=0.0; or a=0.0000; Is there any difference in terms of correct program operation?

I understand that in the case of

double a = 1;

The compiler takes "1" as a value of int type and type conversion is performed (int to target double type).

And in case of:

double a = 1.0

or (there is no difference)

double a = 1.0000

the compiler sees "1.(xxxx)" as a value of the double type and type conversion is not performed.


P.S.: Thanks to PapaYozh for the example. The above thoughts came after it.

I guess it's easier for the compiler when it doesn't cite the types too many times. Or maybe there are lines with "unconverted" types in ex4 too? Does it mean that performance is slowing down? Although the compiler is supposed to optimize the code.

Let the more experienced MQL4 programmers correct me.

 
Thanks for the mega answers. Reading, digging in.
 
NaVolne:
Thanks for the mega answers. Reading, digging in.
You should read the textbook, not our answers! :)) From crust to crust, naturally.
 
LexAlex:

This piece of code worked fine until recently...now error ERR_OFF_QUOTES is returned. Please note that the error is returned by OrderDelete, even if the ticket number is entered manually. Can anyone clarify the situation? Thank you.

Maybe it's in the freeze level. Maybe something is wrong with the account and the broker has stopped the flow due to frequent transactions on the account.