Multicurrency advisor question - page 11

 
Vinin >> :

Create two arrays. One by ticket number, the second by price. Then sort the array by price, moving the ticket numbers at the same time (without breaking the connection). Then at one end of the array will be the lowest price, at the other the highest price. Now we have to change one of extreme orders.

>> Thank you.
I haven't practically worked with arrays yet.
For example, let's say I have 10 BUYSTOP orders. I set their setup prices:

double price1 = GetOrderOpenPrice(NULL,OP_BUYSTOP, 1);//цена 1 байстоп
double price2 = GetOrderOpenPrice(NULL,OP_BUYSTOP, 2);//цена 2 байстоп
double price3 = GetOrderOpenPrice(NULL,OP_BUYSTOP, 3);//цена 3 байстоп
double price4 = GetOrderOpenPrice(NULL,OP_BUYSTOP, 4);//цена 4 байстоп
double price5 = GetOrderOpenPrice(NULL,OP_BUYSTOP, 5);//цена 5 байстоп
double price6 = GetOrderOpenPrice(NULL,OP_BUYSTOP, 6);//цена 6 байстоп
double price7 = GetOrderOpenPrice(NULL,OP_BUYSTOP, 7);//цена 7 байстоп
double price8 = GetOrderOpenPrice(NULL,OP_BUYSTOP, 8);//цена 8 байстоп
double price9 = GetOrderOpenPrice(NULL,OP_BUYSTOP, 9);//цена 9 байстоп
double price10= GetOrderOpenPrice(NULL,OP_BUYSTOP, 10);//цена 10 байстоп



Then, I set an array of setup prices, with order 1 being the price closest to the current price.

int ArrayCents = { price1,price2,price3,price4,price5,price6,price7,price8,price9,price10 }

And how to create an array by ticket is not clear to me. Where do I get the order tickets?

 

What's something like this

// Функция возвращает номер тикета ордера с самой маленькой ценой или с самой большой
// По умолчанию сортировка по возрастанию
// Только вот что за цену брать, я возьму стоп (цену открытия мы менять не можем)
int MiniMaxOrderPrice(string lSymbol="", int lMagic=-1, int lOP=-1, int reversi=0){
   double   ArrayPrice[];
   int      ArrayTicket[];
   int      Total=OrdersTotal();
   int      tmpTicket;
   double   tmpPrice;
   bool     bSort=true;
   
   ArrayResize( ArrayPrice, Total);
   ArrayResize( ArrayTicket, Total);
   int i, count=0;
   for ( i=0; i< Total; i++) {
      if (!OrderSelect( i, SELECT_BY_POS))             continue;
      if (!(OrderSymbol()== lSymbol || lSymbol==""))   continue;
      if (!(OrderMagicNumber()== lMagic || lMagic==-1))continue;
      if (!(OrderType()== lOP || lOP==-1))             continue;
      ArrayPrice[ count]=OrderStopLoss();
      ArrayTicket[ count]=OrderTicket();
      count++;
   }
   
   
   if ( count>0) {
      ArrayResize( ArrayPrice, count);
      ArrayResize( ArrayTicket, count);
      while ( bSort) {
         bSort=false;
         for ( i=1; i< count; i++) {
            if ( ArrayPrice[ i-1]> ArrayPrice[ i]) {
               tmpPrice= ArrayPrice[ i-1];
               ArrayPrice[ i-1]= ArrayPrice[ i];
               ArrayPrice[ i]= tmpPrice;
               tmpTicket= ArrayTicket[ i-1];
               ArrayTicket[ i-1]= ArrayTicket[ i];
               ArrayTicket[ i]= tmpTicket;
               bSort=true;
            }
         }
      }
      if ( reversi==0) return( ArrayTicket[0]); else return( ArrayTicket[ count-1]);
   }
   return(-1);
}

   
Didn't check the code.
 
Thank you, Vinin ! I'll look into it.
 

Apparently function works like this:

MiniMaxOrderPrice(string lSymbol="", int lMagic=-1, int lOP=-1, int reversi=0)

Parameters:
lSymbol= - symbol name ("" - any symbol, NULL - the current symbol)

lOP=-1 - operation (-1 - any order, in our case -OP_BUYSTOP )
lMagic=-1 - MagicNumber (-1 - any magician)

//---------------------------------------------------------------------------------------------

But what does "int reversi=0" mean - it is not quite clear to me !

The function was copied normally:

0 - lowest price

1 - the biggest ?


//-------------------------------------------------------------------

And also, -why exactly did we take the stoploss as a price ?

And why can't we change the opening price ?

OP_BUYSTOP - because these are pending orders (and not positions), and just the end result of the event is to change the opening (triggering) price of a specific order.

 
rid писал(а) >>

Apparently function works like this:

MiniMaxOrderPrice(string lSymbol="", int lMagic=-1, int lOP=-1, int reversi=0)

Parameters:
lSymbol= - instrument name (" - any symbol, NULL - current symbol)

lOP=-1-operation (-1 - any order, in our case -OP_BUYSTOP )
lMagic=-1 - MagicNumber (-1 - any magik)

//---------------------------------------------------------------------------------------------

But what does "int reversi=0" mean - it is not quite clear to me !

The function was copied normally:

0 - the smallest price

1 - the biggest ?


//-------------------------------------------------------------------

And also, -why exactly did we take the stoploss as a price ?

And why can not we change the opening price?

OP_BUYSTOP - these are pending orders (and not positions) which means that in the end we have to change the opening price of the chosen order.

So take whatever price you need. The open price for the pending orders. I just did it as an example.

 

I think it's easier to set up a two-dimensional array and sort by the first dimension. And there, accordingly, you can store what you need. In your case, the price.

double Price_Ticket[][2]
int total=OrdersTotal();
ArrayResize( Price_Ticket, total);
for (int i=0; i< total; i++) if (OrderSelect( i, SELECT_BY_POS))
{
 Price_Ticket[ i][0]=OrderOpenPrice();
 Price_Ticket[ i][1]=OrderTicket();
}
ArraySort( Price_Ticket);
 
Xupypr >> :

I think it's easier to set up a two-dimensional array and sort by the first dimension. And there, accordingly, you can store what you need. In your case it's price.

   SetIndexBuffer(0, Test);
   SetIndexStyle(0, DRAW_HISTOGRAM);
//---- indicators
//----

   double Price_Ticket[][2];
   
   int size = 10;
   ArrayResize( Price_Ticket, size);
It's in the inite. The turkey's just hanging up. The start function is empty, build 220.
 
Vinin >> :

So take whatever price you want. For pendants, take the opening price. I just did it as an example.

Suppose I have 10 bystop orders set. They are not set in order, but they are separated by time.

I need to delete the order which is currently furthest away from the current price.

Is this the correct way to find this order? -

//******************************

p.s.

I have inserted a function in the comment.

Comment( MiniMaxOrderPrice(NULL, -1, OP_BUYSTOP, 1 );

But it keeps returning "-1". Although there are from 5 to 10 orders on the chart.

there is a mistake somewhere...

// Функция возвращает номер тикета ордера с  с самой
// малой или , int reversi=0,большой ценой
// По умолчанию сортировка по возрастанию


int MiniMaxOrderPrice(string lSymbol="", int lMagic=-1, int lOP=-1, int reversi=0 ){
   double   ArrayPrice[];
   int      ArrayTicket[];
   int      Total=OrdersTotal();
   int      tmpTicket;
   double   tmpPrice;
   bool     bSort=true;
   
   ArrayResize( ArrayPrice, Total);
   ArrayResize( ArrayTicket, Total);
   int i, count=0;
   for ( i=0; i< Total; i++) {
      if (!OrderSelect( i, SELECT_BY_TICKET, MODE_TRADES))     continue;
      if (!(OrderSymbol()== lSymbol || lSymbol==""))   continue;
      if (!(OrderMagicNumber()== lMagic || lMagic==-1))continue;
      if (!(OrderType()== lOP || lOP==-1))             continue;
      ArrayPrice[ count]= OrderOpenPrice();
      ArrayTicket[ count]=OrderTicket();
      count++;
   }
   
   
   if ( count>0) {
      ArrayResize( ArrayPrice, count);
      ArrayResize( ArrayTicket, count);
      while ( bSort) {
         bSort=false;
         for ( i=1; i< count; i++) {
            if ( ArrayPrice[ i-1]> ArrayPrice[ i]) {
               tmpPrice= ArrayPrice[ i-1];
               ArrayPrice[ i-1]= ArrayPrice[ i];
               ArrayPrice[ i]= tmpPrice;
               tmpTicket= ArrayTicket[ i-1];
               ArrayTicket[ i-1]= ArrayTicket[ i];
               ArrayTicket[ i]= tmpTicket;
               bSort=true;
            }
         }
      }
      if ( reversi==0) return( ArrayTicket[0]); else return( ArrayTicket[ count-1]);
   }
   return(-1); }
 
rid писал(а) >>

I have, let's say, 10 bystop orders set. They are not placed in order, but are separated by time.

I need to delete the order which is currently furthest away from the current price.

Is this the correct way to find this order? -

//******************************

p.s.

I put the function in the comment.

Comment( MiniMaxOrderPrice(NULL, -1, OP_BUYSTOP, 1 ));

But the function constantly returns "-1". Although there are from 5 to 10 orders on the chart.

There is an error somewhere...

Comment( MiniMaxOrderPrice("", -1, OP_BUYSTOP, 1 )); // any symbol

Comment( MiniMaxOrderPrice(Symbol(), -1, OP_BUYSTOP, 1 )); // current symbol

 

OK! Thank you Vinin !

The function seems to be working! I'll look into it further!

Reason: