OrderClose >> some operator expected - page 2

 
Luciole:

is I am selling and when bid reach my first take profit (variable = profit),

then i want to close 80% of the position..

If the variable "profit" is a price level (not a profit in points, pips or currency) then the first condition could be so. If the variable "magic" is a ticket number (not a magic number) the second condition could be so too. In the function OrderClose use OrderClosePrice() instead of Bid as Keith said. Realize that we see a piece of your code and we can't have an overall picture.

 
Petr Nosek:

If the variable "profit" is a price level (not a profit in points, pips or currency) then the first condition could be so. If the variable "magic" is a ticket number (not a magic number) the second condition could be so too. In the function OrderClose use OrderClosePrice() instead of Bid as Keith said. Realize that we see a piece of your code and we can't have an overall picture.

Thanks for your comment.


I really appreciate. it is true that I do not know what I am doing with this magic number.

playing with it for nothing I think.

thanks for pointing out that to me.

Have a good week-end

Luciole

 
Petr Nosek:

If the variable "profit" is a price level (not a profit in points, pips or currency) then the first condition could be so. If the variable "magic" is a ticket number (not a magic number) the second condition could be so too. In the function OrderClose use OrderClosePrice() instead of Bid as Keith said. Realize that we see a piece of your code and we can't have an overall picture.

I do not understand the problem with the magic number.

i use it only to make sure that my EA manage the trade i want only.. 

1. Why do you suggest that was a problem?

2. If i do not want a magic number what should I write instead?

 int sell = OrderSend(Symbol(), OP_SELL, lot2, Bid, 4, Bid + stop2, Bid - profit, "Ordre Vente Executee", magic, 0, clrRed);
 
Luciole:

I do not understand the problem with the magic number.

i use it only to make sure that my EA manage the trade i want only.. 

1. Why do you suggest that was a problem?

2. If i do not want a magic number what should I write instead?

You mix a magic number with a ticket. Magic number is a number which can help you to recognize which EA created the order (you needn't use it). But ticket is a unique number for each order (it be assigned by broker). You used "magic" as a ticket in OrderSelect() in your first post but there must be used "ticket" instead of. You should read documentation or search for using magic number and ticket in this forum. In simplified way your code should look like:
int ticket = OrderSend(_Symbol, OP_SELL, lot2, Bid, 4, stoploss, takeprofit, "Ordre Vente Executee", magicNumber, 0, clrRed);

and then you can select the order by ticket:

if(OrderSelect (ticket,SELECT_BY_TICKET)) 


If you want to filter your orders by magic number you can use something like this:

  int pos=OrdersTotal()-1;
  for(;pos>-1;pos--)
     if(OrderSelect(pos,SELECT_BY_POS) && OrderMagicNumber()==magicNumber)
       {
        // do something
       }
        
 
Petr Nosek:
You mix a magic number with a ticket. Magic number is a number which can help you to recognize which EA created the order (you needn't use it). But ticket is a unique number for each order (it be assigned by broker). You used "magic" as a ticket in OrderSelect() in your first post but there must be used "ticket" instead of. You should read documentation or search for using magic number and ticket in this forum. In simplified way your code should look like:

and then you can select the order by ticket:


If you want to filter your orders by magic number you can use something like this:

I understand clearly what you are saying.

So, I change and everything work, but the variable "magicNumber" appear in red through all the codes.

Do you know what this mean?




 
Luciole:

I understand clearly what you are saying.

So, I change and everything work, but the variable "magicNumber" appear in red through all the codes.

Do you know what this mean?

This is standard color text formatting in MQL editor. If you declare a variable as extern or input then it will be red in the code. As you can see numbers are green, built-in functions are violet...

 
Petr Nosek:

This is standard color text formatting in MQL editor. If you declare a variable as extern or input then it will be red in the code. As you can see numbers are green, built-in functions are violet...

Thanks :)

Reason: