Probelm OrderSelect()

 

Hello everyone, I have a problem with OrderSelect () function, I would understand if the selected order is in Gain or Loss. This simple EA works at a Binary Options Broker.


I should know if the automatic closing of the Ticket, the price closed higher opening. I'm not sure that you have correctly written the function OrderSelect

//+------------------------------------------------------------------+
//|                                                    PrimoTest.mq4 |
//+------------------------------------------------------------------+
#property copyright "PrimoTest"
#property link      ""
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+



int Ticket;
double myPoint;
//int Count1 = 0;



int OnInit()
  {
//---


Ticket = -1;

//initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 4 || Digits() == 3 || Digits() == 2)
     {
      myPoint *= 10;
     }
  
  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason,)
  {
//---
  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
  
   // Ask == Buy
   // Bid == Sell
  
   //Sell Condition
   if(OrdersTotal() == 0  // Check open orders
   && iRSI(Symbol(),0,2,PRICE_CLOSE,2) > 70
   && iRSI(Symbol(),0,2,PRICE_CLOSE,1) < 70

   )
  
  
   {    
   Ticket = OrderSend(Symbol(), OP_SELL, 10.0, Open[0], 0, 0, 0, "BO exp:60", 0, 0, clrRed); // Order Send (dedicated to Binary Options Broker)
   if(Ticket < 0) Print("Errore invio ordine:"+IntegerToString(GetLastError())); // Controllo errori
   else Print("Ordine inviato correttamente"); // Ordine ok

   }


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

   //Condizione SELL Second Trade
   if(OrdersTotal() == 0 && OrderSelect(Ticket,SELECT_BY_TICKET)) // Chek open order + SELECTED order
  
  
   {      
   if(OrderClosePrice() > OrderOpenPrice()) // Check if the price closed above the opening
   Ticket = OrderSend(Symbol(), OP_SELL, 10.0, Open[0], 0, 0, 0, "BO exp:60", 0, 0, clrRed); // Order Send (dedicated to Binary Options Broker)
  
   if(Ticket < 0) Print("Errore invio ordine:"+IntegerToString(GetLastError())); // Check error
   else Print("Ordine inviato correttamente");  // order ok

   }

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

  




    
  
}
//+------------------------------------------------------------------+
 

This

if(OrdersTotal() == 0 && OrderSelect(Ticket,SELECT_BY_TICKET))

is contradictory. If there are no orders there is nothing to select!!

You probably don't want the second part if you want to open only if there are no open orders.

Read about OrderSelect(..) (mark it and press F!) to understand what it is meant for.



 
You're right, now I have verified that this anointed there is an error. How can I verify that the order has just closed the highest price of the opening price?
 

I don't understand: "How can I verify that the order has just closed the highest price of the opening price?"

An order is closed by the server by several possible reasons. You only can find out at which price your order has been closed - for this you need OrderSelect(..,SELECT_BY_POS, MODE_HISTORY).

 

Thanks for your help, so I wrote the code but I still have some doubts with this function OrderSelect.

//Condizione SELL
   if( OrderSelect(Ticket,SELECT_BY_POS, MODE_HISTORY)) // Check order Close ?!?
  
  
   {      
   if(OrderClosePrice() > OrderOpenPrice() && OrdersTotal() == 0) // chek order price just closed?!?
  
   Ticket = OrderSend(Symbol(), OP_SELL, 10.0, Open[0], 0, 0, 0, "BO exp:60", 0, 0, clrRed);
  
   if(Ticket < 0) Print("Errore invio ordine:"+IntegerToString(GetLastError()));
   else Print("Ordine inviato correttamente");
   }
 
Please check the help for OrdersHistoryTota() and start form its example (type it, mark it, press F1) or google for more examples!
 

thank you for your intervention!!!

This function, (OrdersHistoryTota()), returns the number of closed orders. I just need to know if the order just closed, has the closing price is higher or lower than the opening.
I can not understand how I can do

 
A ticket number is not a position count.
if( OrderSelect(Ticket,SELECT_BY_POS, MODE_HISTORY))
 
fly7680:

Hello everyone, I have a problem with OrderSelect () function, I would understand if the selected order is in Gain or Loss. This simple EA works at a Binary Options Broker.


I should know if the automatic closing of the Ticket, the price closed higher opening. I'm not sure that you have correctly written the function OrderSelectHello, What you need I think " selected order is in Gain or Loss" Right ?


How about this ?

//+------------------------------------------------------------------+
//| check for losses                                                 |
//+------------------------------------------------------------------+  
bool checkforlosses()                   // we check our last closed order
{                                       // from losses here
   int losses=0;                        // total of losses
   int i;                               // pos of our order
   for(i=0; i<OrdersHistoryTotal(); i++) // looping to check all of our
   {                                     // order history from pos 0 until
                                        // last pos
       OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); // is it right our order?
       if(OrderSymbol()!=Symbol() ||    // if symbol of order didn't match
       OrderMagicNumber()!=MagicNumber) // with current chart symbol
       continue;                        // or the magic numb of order
                                        // didn't match with our magic
                                        // number, it is not our's, just don't check it
       if(OrderProfit()<0) losses++;    // so we count it as a losses 'cause negative profit
       else                losses=0;    // otherwise we leave it as is
   }
   if(losses>0)  return(true);          // if last of our order is in losses
                                        // true "value" will returned from this function
   return(false);                       // when there is no losses false will returned
}

I'm sorry if I'm wrong, because I still amateur in Code

 

1) It might be an advantage if you make it your habit to count down for orders and objects:

int o = OrdersHistoryTotal();
while(o-->0) { ...

Otherwise you might run into troubles if you delete or close open orders or existing objects.

2) There is no guaranteed sequence of the orders like acc. to open time or close time or what ever! You have to check that yourself!

 
Achmad Wijaya:

Hello, What you need I think " selected order is in Gain or Loss" Right ?


How about this ?

//+------------------------------------------------------------------+
//| check for losses                                                 |
//+------------------------------------------------------------------+  
bool checkforlosses()                   // we check our last closed order
{                                       // from losses here
   int losses=0;                        // total of losses
   int i;                               // pos of our order
   for(i=0; i<OrdersHistoryTotal(); i++) // looping to check all of our
   {                                     // order history from pos 0 until
                                        // last pos
       OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); // is it right our order?
       if(OrderSymbol()!=Symbol() ||    // if symbol of order didn't match
       OrderMagicNumber()!=MagicNumber) // with current chart symbol
       continue;                        // or the magic numb of order
                                        // didn't match with our magic
                                        // number, it is not our's, just don't check it
       if(OrderProfit()<0) losses++;    // so we count it as a losses 'cause negative profit
       else                losses=0;    // otherwise we leave it as is
   }
   if(losses>0)  return(true);          // if last of our order is in losses
                                        // true "value" will returned from this function
   return(false);                       // when there is no losses false will returned
}

I'm sorry if I'm wrong, because I still amateur in Code

That's right, I have to know if the selected order, that is, the last, is at a loss or gain and in the Binary Options to know that this value is determined by the opening of trade and the closure, after a certain time of expiry. I will try to integrate your code.

Thanks also to Carl Schreiber
Reason: