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

 

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.

 
first_may:

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.

 
first_may:

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

 
Vinin:

The variable t is assigned the opening price, although it is declared as an integer

Right, I meant to write OrderOpenTime(), but wrote OrderOpenPrice();
 
Thank you, I realised my mistake.
 

How do you describe such a condition?



avatar
13
4absinth 25.09.2011 19:23

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?


Roger 25.09.2011 20:25 corrected | delete
if(MathAbs(High[1]-iHigh(NULL,PERIOD_D1,0))<Point)
 

help good people!!!


avatar
1
droopy 25.09.2011 19:34

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!!!


avatar
2222
Roger 9/25/2011 20:22

Note this line

FileWriteInteger(file_handle_bala,balance,DOUBLE_VALUE);


3461
Zhunko 25/09/2011 20:27

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)

TimeTypeOrderVolumePriceS / LT / PProfitBalance
12011.09.19 02:10buy stop10.0176.93576.73577.135
22011.09.19 02:10buy10.0176.93576.73577.135

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);

Thank you all very much in advance!

 
Shniperson:

\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:

double Hi(int pos=0)
inside the start() function
Reason: