Need Help with Expert to Close Postion at Specfic Time

 
Hi,

I am a Metrader Newbie and amd trying to put together a Expert that Will Close a Position at a Certain Time. Nothing every happens with the Expert Below. Can someone tell me what is wrong?

//+------------------------------------------------------------------+
//| Close Position at EOD.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int MagicNumber = 101031;
if (Hour()==16&&Minute()==45)
Print("Executing Expert");
{
bool found = false;
for( int i = OrdersTotal() - 1; i>=0; i--)
{
if ( ! OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if ( found)
Alert( OrderSymbol(), " ", MagicNumber, " Double Order");

switch ( OrderType())
{
case OP_BUY:
case OP_SELL:
found = true;
OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
break;
default:
Alert( OrderSymbol(), " ", MagicNumber, " Wrong Order Type #1");
} // switch
} // for

if ( !found)
{

}
}

//----
return(0);
}
//+------------------------------------------------------------------+
 
Ok. Let's play! One item at a time...

When is 'found" true?
 

Ok. Let's play! One item at a time...

When is 'found" true?




Well I want it yo be when if (Hour()==16&&Minute()==45). Obviously I am missing something pretty basic.
 
Wanting it to be true is not enough, you will have to make it happen:

if (Hour()==16&&Minute()==45){
     Print("Executing Expert");
     found = true;
}
 
Thanks. When I go to compile I get found variable not defined. If I add int found; I get found variable already defined. Any help would be appreaciated.

//+------------------------------------------------------------------+
//| Close Position at EOD.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----

int MagicNumber = 101031;
int found;
if (Hour()==15&&Minute()==58)
Print("Executing Expert");

{
bool found = false;
for( int i = OrdersTotal() - 1; i>=0; i--)
{
if ( ! OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if ( found)
Alert( OrderSymbol(), " ", MagicNumber, " Double Order");

switch ( OrderType())
{
case OP_BUY:
case OP_SELL:
found = true;
OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
break;
default:
Alert( OrderSymbol(), " ", MagicNumber, " Wrong Order Type #1");
} // switch
} // for

if ( !found)
{

}
}

//----
return(0);
}
//+------------------------------------------------------------------+
 
Sorry, Ingonore above. This is what I have currently.

//+------------------------------------------------------------------+
//| Close Position at EOD.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----

int MagicNumber = 101031;
int found;
if (Hour()==15&&Minute()==58)
found = true;
Print("Executing Expert");

{
bool found = false;
for( int i = OrdersTotal() - 1; i>=0; i--)
{
if ( ! OrderSelect( i, SELECT_BY_POS, MODE_TRADES)) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if ( found)
Alert( OrderSymbol(), " ", MagicNumber, " Double Order");

switch ( OrderType())
{
case OP_BUY:
case OP_SELL:
found = true;
OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
break;
default:
Alert( OrderSymbol(), " ", MagicNumber, " Wrong Order Type #1");
} // switch
} // for

if ( !found)
{

}
}

//----
return(0);
}
//+------------------------------------------------------------------+
 
Does it work?
 
Nope. When I go to compile I get found variable not defined. If I add int found; asd in the code above I get found variable already defined. Any help would be appreaciated.
 
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
bool found;

init()..
deinit()...
start(){

remove "int found;" or "bool found;" in this part

}
Reason: