Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 351
You are missing trading opportunities:
- Free trading apps
- 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
Please help me fix the errors in this function. It has already squeezed all the juice out of me. The essence of the function, when it reaches a certain profit, the function should close half of the order.
Oh, and how do I make this function work only once per open order?
Please help me fix the errors in this function. It has already squeezed all the juice out of me. The essence of the function, when it reaches a certain profit, the function should close half of the order.
void CloseHalfOrder(){
for (int i = 0; i<=OrdersTotal(); i++)
{
if (OrderSelect (i,SELECT_BY_POS,MODE_TRADES) == true)
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic){//Нефига тут профиту делать, это так, для убыстрения....
if(OrderProfit()>= NormalizeDouble (TP*Point,Digits)) //А тут вообще непонятки что с чем сравниваете....
{
if (OrderType() == OP_BUY)
double Lots = OrderLots();
double HalfLot = NormalizeDouble (Lots*0.5,2);// Тут озаботится чтобы лот не стал меньше минимального
OrderClose(OrderTicket(),HalfLot,Bid,0,HotPink);
if (OrderType() == OP_SELL)
double Lots1 = OrderLots();
double HalfLot1 = NormalizeDouble (Lots*0.5,2);
OrderClose(OrderTicket(),HalfLot1,Ask,0,HotPink);
}
}
}
}
}
Oh, and how do I make this function work only once per open order?
You can see the principle of partially closing orders here.
Thank you. But I still want to understand my mistakes first and foremost. I'm still learning. Besides, I think I'm very close to the truth.
one more time... The function is not working. I want to understand the errors. + how to make it trigger only 1 time for 1 open order? Thank you very much in advance)
one more time... The function is not working. I want to understand the errors. + how to make it trigger only 1 time for 1 open order?
The condition once for an order is not very clear. Well, we will probably have to use global variables here. Maybe there is more than one order, and only once for each?
one more time... The function is not working. I want to understand the errors. + how to make it trigger only 1 time for 1 open order?
I have the following situation. There are several modules in the EA, each module takes several custom functions. In order not to drown in the code, I decided to put each module into scripts. Here is the variant of calling the script from the Expert Advisor. The next problem arises, however: when calling the script, I need to pass some parameters to it. We can use global variables. What other variants can be suggested?
Let me tell you right away: the "simpler" variant via iCustom() does not suit me, for two reasons. Firstly, the module's call should be occasional in memory, not constant. Secondly, I do not use indicator arrays.
The condition once for an order is not very clear. Well you probably have to use global variables here. Can there be multiple orders and only one time for each?
There can only be one order in the market. At the moment, this function does not work at all... for some reason. But if it will work properly, I understand that it will be triggered all the time, as long as the profit is higher than the set amount of pips. Of course, we need it to close half of a position once, and that's it. But I wish it would work at least once.)
I have the following situation. There are several modules in the EA, each module takes several custom functions. In order not to drown in the code, I decided to put each module into scripts. Here is the variant of calling the script from the Expert Advisor. The next problem arises, however: when calling the script, I need to pass some parameters to it. We can use global variables. What other variants can be suggested?
Let me tell you right away: the "simpler" variant via iCustom() does not suit me, for two reasons. Firstly, the module's call should be occasional in memory, not constant. Secondly, I do not use indicator arrays.
A library is an option.
there can only be one order in the market. At the moment this function doesn't work at all... for some reason. But if it will work properly, I understand that it will be triggered all the time, as long as the profit is higher than the set number of pips. Of course, we need it to close half of a position once, and that's it. But I wish it would work at least once.)