[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 276

 
BBSL:

If we are talking about ticks, you can write code that saves the data file, but you will need to load from a file in ekspert. Would it make sense to just keep the computer running?
I guess I should use the second option. Thank you, BBSL.
 
artmedia70:

What you're doing is strange... When opening a position you assign the ticket number to one variable, but you check another one...

And OrderSend() returns -1 (minus one) in case of failure, and you check for less than one, when you need less than zero

This is the first thing that catches your eye. But I think you have a lot of interesting things there... :)


Ooh-ha-ha, yeah there's a lot of fun... Especially when you start checking))

Come on, one more time... It goes like this,

I open order:

order_id = OrderSend(Symbol(),OP_SELL,1.0,Bid,3,0,0,"expert comment",255,0,Red);
   if(order_id<0)
     {
      error=GetLastError();
      Print("send_orders, error = ",ErrorDescription(error));
      return;
     }
     } 

Closing order:

if(OrderSelect(0, SELECT_BY_POS)==true){

OrderClose(OrderTicket(),1,Bid,3,Red);

}

Right, given a single order?)

 
hedger:
Apparently the second option should be used. Thank you, BBSL.

You're welcome, I hope it really helps you))
 
artmedia70:

What you're doing is strange... When opening a position you assign the ticket number to one variable, but you check another one...

And OrderSend() returns -1 (minus one) in case of failure, and you check for less than one, when you need less than zero

This is the first thing that catches your eye. But I think you have a lot of interesting things there... :)


I get it, the tikit number should be obtained like this:

nomer_ticketa = OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,0,"expert comment",255,0,Green);
   if(ticket<1)
 
artmedia70:

What you're doing is strange... When opening a position you assign the ticket number to one variable, but you check another one...

And OrderSend() returns -1 (minus one) in case of failure, and you check for less than one, when you need less than zero

This is the first thing that catches your eye. But I think you have a lot of interesting things there... :)


Respect, thanks!))
 
BBSL:


I understand, you have to get the tickit number like this:

You know, with only one order, it might work, but if you still open it manually, it won't be the same. The ticket number should be saved in a variable, and after order selection we should compare its ticket with the stored one:

 if (OrderTicket()==number_ticket) {
   // ... код для работы с выбранным ордером при совпадении тикетов
   }

And in general, the order selection must be done using the OrderSelect() function in the loop:

for (i=0; i<OrdersTotal(); i++) {                    // цикл по всем рыночным ордерам терминала
   if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { // Если выбран любой рыночный ордер с индексом i
      if (OrderSymbol()!=Symbol())     continue;   // Если символ не текущего графика, переходим к выбору следующего ордера
      if (OrderMagicNumber()!=Magic)   continue;   // Если его магик не совпадает с магиком советника - переходим к выбору следующего
//... далее можно проверять другие параметры выбранного ордера, но в этом месте уже есть выбранный ордер текущего графика и номером магика советника
      if (OrderTicket()==number_ticket) {          // проверяем тикет выбранного ордера и, если есть совпадение, выполняем с ним дальнейшие действия
         // ... код, выполняющий дальнейшие действия с найденным нужным ордером ...
         }
      }
   else if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) // Иначе, если не удалось выбрать ордер
      Print ("Ошибка при выборе ордера из списка рыночных ордеров = ", GetLastError());  // Выведем сообщение об ошибке и её номер в журнал.
   }

This is just an example for understanding, not the finished working code, if anything... :)

 
artmedia70:

You know, if you have only one order, it might work, but if you open more by hand, it won't be the same. The ticket number should be stored in a variable, and after selecting an order, we should compare its ticket with the stored one:

And, in general, the selection of orders should be done using the OrderSelect() function in the loop:

This is just an example for understanding, not the complete working code, if anything... :)




When closing orders, if there is more than one order, we should use this loop:

int i, k=OrdersTotal();

  for (i=k-1; i>=0; i--) {
 //...
 
bolt:

When closing orders, if there is more than one order, a cycle like this should be used:

Read the last line of my post. Who said I wrote an example to close?

The rest is the plain truth. Write your own textbook.

 

Can you tell me why OrderOpenPrice does not work? The task is to look for an order in the pool at a certain price, and if it's not there, put the order in and flag it as set.


for(int i=1 ; i <= OrdersTotal() ; i++)
   {
   if(OrderSelect(i-1,SELECT_BY_POS,MODE_TRADES))
      {
      if(OrderOpenPrice() == price) 
        {
        orderset = true;
        }
      }
   }
     
if((orderset==false)
   {
   OrderSend(Symbol(),OP_SELLLIMIT,baselot,price,3,NULL,price-10,"Comment",0001+i,0,White); 
   }
 
Pyro:

Can you tell me why OrderOpenPrice does not work? The task is to search the pool for an order placed at a certain price, and if it's not there, put the order and set a flag that it's set.



We cannot compare real numbers.
Reason: