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

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
Good afternoon. I have written a function that should return the number of bars when an order was opened:
int BarLastOpenPose()
{
datetime t;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()>1) continue;
if (t<OrderOpenPrice()) t=OrderOpenPrice();
}
}
return (iBarShift(Symbol(),Period(),t,true));
}
However, it always returns -1. Where did I make a mistake? Thanks in advance.
Good afternoon. I have written a function that should return the number of bars when an order was opened:
int BarLastOpenPose()
{
datetime t;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()>1) continue;
if (t<OrderOpenPrice()) t=OrderOpenPrice();
}
}
return (iBarShift(Symbol(),Period(),t,true));
}
However, it always returns -1. Where did I make a mistake? Thanks in advance.
Maybe it goes like this:
return(iBarShift(Symbol(),Period(),t)); that is, without true.
Good afternoon. I have written a function that should return the number of bars when an order was opened:
int BarLastOpenPose()
{
datetime t;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()>1) continue;
if (t<OrderOpenPrice()) t=OrderOpenPrice();
}
}
return (iBarShift(Symbol(),Period(),t,true));
}
However, it always returns -1. Where did I make a mistake? Thank you in advance.
The t variable is assigned the opening price, although it is declared as an integer
The variable t is assigned the opening price, although it is declared as an integer
How do you describe such a condition?
Please advise.
If an extremum (e.g. high) of the first 5-minute bar of the current day coincides with an extremum of the current day (on the daily), then we do something. How would you describe it?
help good people!!!
Hello Dear users of the resource!
Please help, who faced with reading/writing a real number to a file.
The task is to read from a file balance, if the current balance is more - overwrite the file.
The problem is that it always outputs 0 (zero).
With writing/reading integers I didn't find such problems.
Here is the code:
double balance;
int file_handle_bala;
file_handle_bala=FileOpen("file_bala.dat",FILE_BIN|FILE_READ);
//copy position, in case of an empty file - position = 0
if (FileSize(file_handle_bala)>0)
{
balance=FileReadDouble(file_handle_bala,DOUBLE_VALUE);
Alert(balance); ------------------------------------- this is where zero should be written although the previously saved balance should be written
FileClose(file_handle_bala);
if (AccountBalance()>balance) ------------------------------------ and this rule does not work because the alert below does not output anything
{
file_handle_bala=FileOpen("file_bala.dat",FILE_BIN|FILE_WRITE);
balance=AccountBalance();
Alert(balance);
FileWriteInteger(file_handle_bala,balance,DOUBLE_VALUE);
FileClose(file_handle_bala);
}
}
else // if file is empty
{
FileClose(file_handle_bala); // first, close the open file
file_handle_bala=FileOpen("file_bala.dat",FILE_BIN|FILE_WRITE); //open for writing
balance=AccountBalance();
FileWriteDouble(file_handle_bala,balance,DOUBLE_VALUE);
FileClose(file_handle_bala);
}
Thanks a lot earlier!!!
Note this line
FileWriteInteger(file_handle_bala,balance,DOUBLE_VALUE);
1. You should be more respectful and friendly to publish your code.
2. You are trying to write an integer 8 bytes. MQL4 does not have such a data type.
\What did I do wrong? Why so many errors? (I need to know the maximum
(I need to know the maximum value of the indicator in the last 10 bars). thanks in advance.
Good day to all!
I'm writing my first bot, and at the same time I'm getting acquainted with MQL. I have the following problem during testing:
Order OP_BUYSTOP is executed right after the order is placed, although judging by the chart, the price does not reach the target value (see below)
USDJPY,M5 (visual)
Date 2011.09.19
Time 02:15
Open 76.903
High 76.909
Low 76.890
Close 76.890
Volume 66
I am testing all ticks.
Maybe I do not understand OP_BUYSTOP order correctly? To buy if the price exceeds a certain value, right?
Here is a bit of source code that places an order
int ticket=OrderSend(Symb, OP_BUYSTOP, Lot, Price, 0, SL, TP);
\What did I do wrong? Why so many errors? (I need to know the maximum value of the indicator for the last 10 bars). thanks in advance.
You are declaring the function Hi:
inside the start() function