Looking for the last order open price. Without MagicNumber A theme is closed. thanks:)

BorysekPL
205
BorysekPL  

The problem for me is that i don't know what was last order MagicNumber. - I need to check open price of the last order even when I close and start again computer.

If I know what was the magic number, than I could use this code...

int OPrice;

for(int pos=OrdersTotal()-1; pos >= 0; pos--) if (

OrderSelect(pos, SELECT_BY_POS)

&& OrderMagicNumber() == 1

&& OrderSymbol() == Symbol()

&& OrderType() == OP_BUY){

OPrice = OrderOpenPrice

{..............

Unfortunetly I don't know what was the magic number of the last order ...

looking for help:)

Simon Gniadkowski
17401
Simon Gniadkowski  
BorysekPL:


Unfortunetly I don't know what was the magic number of the last order ...


Why ?
BorysekPL
205
BorysekPL  
RaptorUK:
Why ?

  • 1. When I start program again i loose my variables from memory.
  • 2. My ea is sending many orders and there could be in the same time 15 buy an 7 sell orders on the market.

I think it should be easy to do if I give every next order number n+1 and than check the biggest number to find the last order.

So I see now three ways to get what I want: (but still don't know how to make any one of them;) )

  • 1. A possible to get instantly the magic number of the last order
  • 2. A possible to count what is the biggest number of all MagicNumbers and than I know that order with the biggest order is the last order.
  • 3. Count all orders and the number of all orders will be the same that the MagicNumber of last order is....... I think that is fastest way..... ( I need to learn about counting orders now:) )


If you get any prompts than i am open for propositions.

Thanks:)

BorysekPL
205
BorysekPL  

//| expert start function |
//+------------------------------------------------------------------+
int OpenBuyOrders;
int OpenSellOrders;
int total;

int OPrice;

int start()
{


OpenBuyOrders=0;
OpenSellOrders=0;
total=0;

//Count Orders
for(int i=0;i<OrdersTotal(); i++ )
{
if(OrderSelect(i, SELECT_BY_POS)==true)
{
if (OrderType()==OP_BUY)
OpenBuyOrders++; // Total number of buy orders
if (OrderType()==OP_SELL)
OpenSellOrders++; // Total number of sell orders
}
total=OpenBuyOrders + OpenSellOrders; // Total number of orders
}
Comment ("buy=",OpenBuyOrders," sell=",OpenSellOrders," total=",total);
}

// now time to select order with biggest MagicNumber

for(int pos=OrdersTotal()-1; pos >= 0; pos--) if (

OrderSelect(pos, SELECT_BY_POS)

&& OrderMagicNumber() == total

&& OrderSymbol() == Symbol()

&& OrderType() == OP_BUY){

OPrice = OrderOpenPrice // Last order open price

{..............

Simon Gniadkowski
17401
Simon Gniadkowski  
BorysekPL:

  • 1. When I start program again i loose my variables from memory.
  • 2. My ea is sending many orders and there could be in the same time 15 buy an 7 sell orders on the market.

I think it should be easy to do if I give every next order number n+1 and than check the biggest number to find the last order.

So I see now three ways to get what I want: (but still don't know how to make any one of them;) )

  • 1. A possible to get instantly the magic number of the last order
  • 2. A possible to count what is the biggest number of all MagicNumbers and than I know that order with the biggest order is the last order.
  • 3. Count all orders and the number of all orders will be the same that the MagicNumber of last order is....... I think that is fastest way..... ( I need to learn about counting orders now:) )

You don't need to give each order an individual Magic Number . . they already have unique Ticket numbers and positions in the order list . . .

You shouldn't count up through your Orders, it is bad practice . . count down . . . the first order that you come across will be the most recent. Use the Magic Number to distinguish between Orders placed by different EAs (and manually placed trades) and also the same EA on different TimeFrames.

liquidd
170
liquidd  

for the last order you could use this into your loop

that would seek for the last opened order then you can set the ticket to a variable and use it to whatever you want it to be used.

that's what I would do and you do not need the ticket to be able to find the last opened one

datetime last;
if (OrderOpenTime() > last) last=OrderOpenTime();
BorysekPL
205
BorysekPL  
RaptorUK:

You don't need to give each order an individual Magic Number . . they already have unique Ticket numbers and positions in the order list . . .

You shouldn't count up through your Orders, it is bad practice . . count down . . . the first order that you come across will be the most recent. Use the Magic Number to distinguish between Orders placed by different EAs (and manually placed trades) and also the same EA on different TimeFrames.

I'm in dot now:)

If there is a chance to select last order by Ticket and check what is the open price of this order then it could be very helpfull for me:)

Counting orders is a mistake if thinking about sending orders manually. It's a good advice - thanks for that:)

So mabe somebody have any prompts how select the last order?

  • If we haven't magic number
  • If we can't counting orders


Looking for help:)

Simon Gniadkowski
17401
Simon Gniadkowski  
BorysekPL
205
BorysekPL  
liquidd 2011.09.16 15:57

for the last order you could use this into your loop

that would seek for the last opened order then you can set the ticket to a variable and use it to whatever you want it to be used.

that's what I would do and you do not need the ticket to be able to find the last opened one

datetime last;
if (OrderOpenTime() > last) last=OrderOpenTime();

So how do you think it works? Asking only to better known the mechanic of how system works:)

1
System firstly select most recent used order?
2
System select all orders one by one and checking if orders are bigger than variable last? If it's not than finisch...

I think that I need first select the order to check

if (OrderOpenTime() > last) last=OrderOpenTime();

So if I haven't order selected than I can't check OrderOpenTime

is it correct?

Can you tell me how to use it?

BorysekPL
205
BorysekPL  


1157
RaptorUK 2011.09.16 16:05




Thanks, this is very helpfull. You are awesome:)
In this article somebody tells " However, this MQL4 uses normal UNIX timestamps you cannot distignuish between orders which have been opened in the same second."

So My EA is sometimes sending sell and buy order in the same time?

What if it going to send them in the same time?
Simon Gniadkowski
17401
Simon Gniadkowski  

BorysekPL:

What if it going to send them in the same time?


Don't . . . make your EA wait 1 sec.