int GetMagic(Order &order)
{
int magic = 0;
if(order.cmd == OP_SELLSTOP || order.cmd == OP_BUYSTOP)for(int i = OrdersTotal(); i > 0 ; i --)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderType()==OP_SELLSTOP || OrderType()==OP_BUYSTOP)
{
if(magic == OrderMagicNumber()) magic+=1;
else magic=0;
}
}
}
return (magic);
}
That fixed it, I had if (order.cmd == OP_SELLSTOP || OP_BUYSTOP) only the problem was not solved. But I need it to pass through all orders. The mage itself is set at the moment of creation only to the stopper. We can't understand that the stopper is created by OrderType() because it hasn't been there yet; we have a preliminary record of order type in order.cmd for that. And here we need two loops: one nested in the other, so that one iteration of the variable magic is checked with all orders from OrdersTotal(). I have it all implemented, only there is an endless loop, I don't know why ...
Nerd Trader #: This is fine, I had if (order.cmd == OP_SELLSTOP || OP_BUYSTOP) But I need all orders to be passed. The mage itself is set when only the stopper is created. We can't know that the stopper is created by OrderType() since it hasn't been there yet, we need to write the order type in order.cmd beforehand. And here we need two loops: one nested in the other, so that one iteration of the magic variable is checked with all orders from OrdersTotal()
void OpenOrder(int db = -1){
if(db == -1){
Print("'db' должен иметь корректное значение");
return;
}
Order order;
//Если бид в границах ДБ (его хай/лоу) то инициализируем ордер для селстопа или байстопаif(Bid > db_last.low && Bid < db_last.hight){
if(db == BEAR) order.InitForSell(SELLSTOP);
if(db == BULL) order.InitForBuy(BUYSTOP);
}
...
if(order.is_init == true)
{
int order_send = OrderSend(Symbol(), order.cmd, 0.01, order.open_price, 10,
order.sl_price, order.tp_price, "", GetMagic(order), 0, order.arrow_color);
if(order_send == -1){
Print(order.error_text," | ",GetLastError()," db_last.third ",db_last.third,
" | db_last.size_open_to_low ",db_last.size_open_to_low," | order.sl_price: ",
order.sl_price," | order.cmd ",order.cmd);
ResetLastError();
return;
}
}
}
...
int GetMagic(Order &order)
{
int magic = 0;
//Если должен быть открыт стопордер и если есть уже открытые или отложенные //ордера, то возможно некоторые с маджиком, это надо проверить и сгенерировать //для нашего ордера уникальный маджик и отправить его на запись в массивif(order.cmd == OP_SELLSTOP || OP_BUYSTOP)
if(OrdersTotal() >= 1)
for(;;){
magic++;
for(int i = OrdersTotal(); i > 0 ; i --)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) != false)
if(magic != OrderMagicNumber())
return magic;
}
//Если нет открытых или отложенных ордеров то увеличиваем значение //маджика, чтобы он равнялся единице и отправляем на запись в массивelseif (OrdersTotal() == 0)
return (magic + 1);
return magic;
}
It says in the commentary that it sends the majic to the write array, so don't be misled by this, as long as the majic goes back to the retorn.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
is this a joke?
You have it in black and white for(;;)
Well yes, only there is a way out of it: when magic does not equal order magic.
Try this
What if there is a grid of orders?
Does anyone have a function to calculate the sum of all swaps of a grid of orders for a magic order and a financial instrument.
Thanks for the help!!!
What do you need it for?
When closing a large grid of orders with a long grid life, order swaps eat into profits and distort the result very much.
I want to compensate for the loss on swaps with this function.
When closing a large grid of orders with a long grid life, order swaps eat into profits and distort the result very much.
I want to compensate for the loss on swaps with this function.
Try this
But I need it to pass through all orders. The mage itself is set at the moment of creation only to the stopper. We can't understand that the stopper is created by OrderType() because it hasn't been there yet; we have a preliminary record of order type in order.cmd for that. And here we need two loops: one nested in the other, so that one iteration of the variable magic is checked with all orders from OrdersTotal(). I have it all implemented, only there is an endless loop, I don't know why ...
Is the grid closed at profit or at breakeven?
Yes, at a certain level of drawdown, there is a loss to zero and to no loss there is an ugly loss due to swaps
This is fine, I had if (order.cmd == OP_SELLSTOP || OP_BUYSTOP)
But I need all orders to be passed. The mage itself is set when only the stopper is created. We can't know that the stopper is created by OrderType() since it hasn't been there yet, we need to write the order type in order.cmd beforehand. And here we need two loops: one nested in the other, so that one iteration of the magic variable is checked with all orders from OrdersTotal()
Yes, at a certain level of drawdown, there is a loss to zero and to no loss there is an ugly loss due to swaps