Good evening to the mql4 community,
I was trying to modify an open position, to close 80% of the position to be precise.
And with those instructions an error message appear :
"some operator expected"
Any idea on how to fix the problem?
Thanks a lot !
Luciole
if (MarketInfo(Symbol(), MODE_BID) <= profit && OrderMagicNumber()==magic) { if(OrderSelect (OrderTicket(),SELECT_BY_TICKET) == true) { lot3 = NormalizeDouble((OrderLots() * 0.8),Digits); OrderClose (OrderTicket(), lot3, Ask, 10, Red); } }
lot3 = NormalizeDouble((OrderLots() * 0.8),Digits);
Using Digits to normalise may give invalid results.
https://docs.mql4.com/predefined/digitsvar
there are no connection between digits and lotsize
you may use directly selected orderlots and multiply your choice

- docs.mql4.com
Any idea on how to fix the problem?
Try the code below. But I'm not sure if you understand what you are doing. E.G. your comparison Bid with "profit" sounds really strange and there are more similar strange things in your code.
if (MarketInfo(Symbol(), MODE_BID) <= profit) // This is strange (profit is a price???) { if(OrderSelect (magic,SELECT_BY_TICKET)) // This is strange (magic as a ticket???) { lot3 = CDouble::RoundToLots(OrderLots() * 0.8); // Now it is correct OrderClose (OrderTicket(), lot3, Bid, 10, Red); // This is correct only if it is a LONG trade (Bid) } }
OrderClose (OrderTicket(), lot3, Bid, 10, Red); // This is correct only if it is a LONG trade (Bid)
A good habit to get into is to Use OrderClosePrice() as then it doesn't matter if it is a Long or a Short trade, it will always be correct.
OrderClose (OrderTicket(), lot3, OrderClosePrice(), 10, Red); // This is correct for either a long or short
A good habit to get into is to Use OrderClosePrice() as then it doesn't matter if it is a Long or a Short trade, it will always be correct.
if(OrderType()==OP_BUY) OrderClose (OrderTicket(), lot3, MarketInfo(OrderSymbol(), MODE_BID), 10, Red); if(OrderType()==OP_SELL) OrderClose (OrderTicket(), lot3, MarketInfo(OrderSymbol(), MODE_ASK), 10, Red);
if(OrderType()==OP_BUY) OrderClose (OrderTicket(), lot3, MarketInfo(OrderSymbol(), MODE_BID), 10, Red); if(OrderType()==OP_SELL) OrderClose (OrderTicket(), lot3, MarketInfo(OrderSymbol(), MODE_ASK), 10, Red);
What advantage is there over using the much simpler
OrderClose (OrderTicket(), lot3, OrderClosePrice(), 10, Red); // This is correct for either a long or short
??
Try the code below. But I'm not sure if you understand what you are doing. E.G. your comparison Bid with "profit" sounds really strange and there are more similar strange things in your code.
Thanks a lot for your help.
So if it is a short i should write ask instead of bid?
I do no understand why...
Thanks..
What advantage is there over using the much simpler
??
This a good question, I hope we get an answer :)
Try the code below. But I'm not sure if you understand what you are doing. E.G. your comparison Bid with "profit" sounds really strange and there are more similar strange things in your code.
My code is weird.. outch
yeah i am a beginner
What I wanted to write
is I am selling and when bid reach my first take profit (variable = profit),
then i want to close 80% of the position..
Should I write it differently?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good evening to the mql4 community,
I was trying to modify an open position, to close 80% of the position to be precise.
And with those instructions an error message appear :
"some operator expected"
Any idea on how to fix the problem?
Thanks a lot !
Luciole