This
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.
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.
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");
}
A ticket number is not a position count. | if( OrderSelect(Ticket,SELECT_BY_POS, MODE_HISTORY)) |
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:
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!
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
Thanks also to Carl Schreiber

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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
}
//-------------------------------------------------------------------------------------------
}
//+------------------------------------------------------------------+