- trading code
- OrderClose Error 4051 - Invalid Ticket
- What I am not thinking about?

219

Jhenrique Vissotto

Hi!

Exist a function analogous to Close[n] that returns the last ticket number of the opened position in function of n?

Like this:

Ticket[0] = 12340000 (buy)

Ticket[1] = 12340001 (buy)

Ticket[2] = 12340002 (sell)

Ticket[3] = 12340003 (buy)

Ticket[4] = 12340004 (sell)

Ticket[5] = 12340005 (sell)

Ticket[6] = 12340006 (buy)

Ticket[7] = 12340007 (sell)

Ticket[8] = 12340008 (buy)

And also for buy and sell, like this:

TicketBuy[0] = 12340000

TicketBuy[1] = 12340001

TicketBuy[2] = 12340003

TicketBuy[3] = 12340006

TicketBuy[4] = 12340008

TicketSell[0] = 12340002

TicketSell[1] = 12340004

TicketSell[2] = 12340005

TicketSell[3] = 12340007

- trading code
- OrderClose Error 4051 - Invalid Ticket
- What I am not thinking about?

211913

Hi!

Exist a function analogous to Close[n] that returns the last ticket number of the opened position in function of n?

Like this:

Ticket[0] = 12340000 (buy)

Ticket[1] = 12340001 (buy)

Ticket[2] = 12340002 (sell)

Ticket[3] = 12340003 (buy)

Ticket[4] = 12340004 (sell)

Ticket[5] = 12340005 (sell)

Ticket[6] = 12340006 (buy)

Ticket[7] = 12340007 (sell)

Ticket[8] = 12340008 (buy)

And also for buy and sell, like this:

TicketBuy[0] = 12340000

TicketBuy[1] = 12340001

TicketBuy[2] = 12340003

TicketBuy[3] = 12340006

TicketBuy[4] = 12340008

TicketSell[0] = 12340002

TicketSell[1] = 12340004

TicketSell[2] = 12340005

TicketSell[3] = 12340007

There is no such function

You have to go through the list of opened orders, save the ticket numbers in an array, sort the array and then you can have something like you want. It could be done similar to this :

int ordersByTicket[]; for (int i=OrdersTotal()-1,i>=0, i--) if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) { ArrayResize(ordersByTicket,ArraySize(ordersByTicket)+1); ordersByTicket[ArraySize(ordersByTicket)-1] = OrderTicket(); } ArraySort(ordersByTicket,WHOLE_ARRAY,MODE_DESCEND); ordersByTicket[0] == // last (biggest) ticket number and so on

219

Mladen, could you create the code of the these 6 functions below for me?

TicketNumber = N[n]

TicketNumber = M[m]

TicketNumber = X[x]

TicketNumber = Y[y]

TicketNumber = V[v]

TicketNumber = W[w]

Order = N[n] = M[m]

142370816 = N[0] = M[13]

142370788 = N[1] = M[12]

142370758 = N[2] = M[11]

:

:

:

142370606 = N[11] = M[2]

142370565 = N[12] = M[1]

142370543 = N[13] = M[0]

BUY Positions:

Order = X[x] = Y[y]

142370816 = X[0] = Y[7]

142370788 = X[1] = Y[6]

142370701 = X[2] = Y[5]

:

:

:

142370606 = X[5] = Y[2]

142370565 = X[6] = Y[1]

142370543 = X[7] = Y[0]

SELL Positions:

Order = V[v] = W[w]

142370758 = X[0] = Y[5]

142370743 = X[1] = Y[4]

142370711 = X[2] = Y[3]

:

:

:

142370679 = X[3] = Y[2]

142370645 = X[4] = Y[1]

142370631 = X[5] = Y[0]

Do you undestand??

211913

Mladen, could you create the code of the these 6 functions below for me?

TicketNumber = N[n]

TicketNumber = M[m]

TicketNumber = X[x]

TicketNumber = Y[y]

TicketNumber = V[v]

TicketNumber = W[w]

ALL Positions:

Order = N[n] = M[m]

142370816 = N[0] = M[13]

142370788 = N[1] = M[12]

142370758 = N[2] = M[11]

:

:

:

142370606 = N[11] = M[2]

142370565 = N[12] = M[1]

142370543 = N[13] = M[0]

BUY Positions:

Order = X[x] = Y[y]

142370816 = X[0] = Y[7]

142370788 = X[1] = Y[6]

142370701 = X[2] = Y[5]

:

:

:

142370606 = X[5] = Y[2]

142370565 = X[6] = Y[1]

142370543 = X[7] = Y[0]

SELL Positions:

Order = V[v] = W[w]

142370758 = X[0] = Y[5]

142370743 = X[1] = Y[4]

142370711 = X[2] = Y[3]

:

:

:

142370679 = X[3] = Y[2]

142370645 = X[4] = Y[1]

142370631 = X[5] = Y[0]

Do you undestand??

I don't (understand)

If you know the exact ticket numbers you want to access, then simply use OrderSelect(ticketNumber,SELECT_BY_TICKET,MODE_TRADES); function

219

No! I don't know the ticket number :S

WHat I want to do is the following:

I speaking for the EA:

"EA, close the first buy position!"

"EA, close the last sell position!"

"EA, close the three last position!"

"EA, close the last position and the 2nd of buy and 5nd of sell!"

In other words, I want to control which position the EA will close by "1st", "2nd", ..., "penultimate" and "last".

211913

No! I don't know the ticket number :S

WHat I want to do is the following:

I speaking for the EA:

"EA, close the first buy position!"

"EA, close the last sell position!"

"EA, close the three last position!"

"EA, close the last position and the 2nd of buy and 5nd of sell!"

In other words, I want to control which position the EA will close by "1st", "2nd", ..., "penultimate" and "last".

3231

WHat I want to do is the following:

I speaking for the EA:

"EA, close the first buy position!"

"EA, close the last sell position!"

"EA, close the three last position!"

"EA, close the last position and the 2nd of buy and 5nd of sell!"

In other words, I want to control which position the EA will close by "1st", "2nd", ..., "penultimate" and "last".

219

3231

Exist other form more simple?

You are missing trading opportunities:

- Free trading apps
- Free Forex VPS for 24 hours
- 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