this is simple close at profit ea. i want use it in such a way . if the certain price come it start working. like Ask = 1.2000 . it began start. not before ask not after ask .
//|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//| Close
//| Last Updated 12-12-2006 10:00pm
//|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#define NL "\n"
extern int ProfitTarget = 100; // closes all orders once Float hits this $ amount
extern bool CloseAllNow = false;
extern int MagicNumber = 1100; // closes all orders now
extern bool CloseProfitableTradesOnly = false; // closes only profitable trades
extern double ProftableTradeAmount = 1; // Only trades above this amount close out
extern bool ClosePendingOnly = false; // closes pending orders only
extern bool UseAlerts = true;
//+-------------+
//| Custom init |
//|-------------+
int init()
{
}
//+----------------+
//| Custom DE-init |
//+----------------+
int deinit()
{
}
//+------------------------------------------------------------------------+
//| Closes everything
//+------------------------------------------------------------------------+
//+------------------------------------------------------------------------+
//| Closes everything
//+------------------------------------------------------------------------+
void CloseAll()
{
int i;
bool result = false;
while(OrdersTotal()>0)
{
// Close open positions first to lock in profit/loss
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i, SELECT_BY_POS)==false) continue;
result = false;
if ( OrderType() == OP_BUY) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 15, Red );
if ( OrderType() == OP_SELL) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 15, Red );
if (UseAlerts) PlaySound("alert.wav");
}
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i, SELECT_BY_POS)==false) continue;
result = false;
if ( OrderType()== OP_BUYSTOP) result = OrderDelete( OrderTicket() );
if ( OrderType()== OP_SELLSTOP) result = OrderDelete( OrderTicket() );
if ( OrderType()== OP_BUYLIMIT) result = OrderDelete( OrderTicket() );
if ( OrderType()== OP_SELLLIMIT) result = OrderDelete( OrderTicket() );
if (UseAlerts) PlaySound("alert.wav");
}
Sleep(0);
}
}
//+------------------------------------------------------------------------+
//| cancels all orders that are in profit
//+------------------------------------------------------------------------+
void CloseAllinProfit()
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
bool result = false;
if ( OrderType() == OP_BUY && (OrderMagicNumber() == MagicNumber)&& OrderProfit()+OrderSwap()>ProftableTradeAmount) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
if ( OrderType() == OP_SELL && (OrderMagicNumber() == MagicNumber)&& OrderProfit()+OrderSwap()>ProftableTradeAmount) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
if (UseAlerts) PlaySound("alert.wav");
}
return;
}
//+------------------------------------------------------------------------+
//| cancels all pending orders
//+------------------------------------------------------------------------+
void ClosePendingOrdersOnly()
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
bool result = false;
if ( OrderType()== OP_BUYSTOP) result = OrderDelete( OrderTicket() );
if ( OrderType()== OP_SELLSTOP) result = OrderDelete( OrderTicket() );
}
return;
}
//+-----------+
//| Main |
//+-----------+
int start()
{
int OrdersBUY;
int OrdersSELL;
double BuyLots, SellLots, BuyProfit, SellProfit;
//+------------------------------------------------------------------+
// Determine last order price |
//-------------------------------------------------------------------+
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;
if(OrderType()==OP_BUY)
{
OrdersBUY++;
BuyLots += OrderLots();
BuyProfit += OrderProfit() + OrderCommission() + OrderSwap();
}
if(OrderType()==OP_SELL)
{
OrdersSELL++;
SellLots += OrderLots();
SellProfit += OrderProfit() + OrderCommission() + OrderSwap();
}
}
if(CloseAllNow) CloseAll();
if(CloseProfitableTradesOnly) CloseAllinProfit();
if(CloseAllNow) CloseAll();
if(CloseProfitableTradesOnly) CloseAllinProfit();
if(BuyProfit+SellProfit >= ProfitTarget) CloseAll();
if(ClosePendingOnly) ClosePendingOrdersOnly();
Comment(" Comments Last Update 12-12-2006 10:00pm", NL,
" Buys ", OrdersBUY, NL,
" BuyLots ", BuyLots, NL,
" Sells ", OrdersSELL, NL,
" SellLots ", SellLots, NL,
" Balance ", AccountBalance(), NL,
" Equity ", AccountEquity(), NL,
" Margin ", AccountMargin(), NL,
" MarginPercent ", MathRound((AccountEquity()/AccountMargin())*100), NL,
" Current Time is ",TimeHour(CurTime()),":",TimeMinute(CurTime()),".",TimeSeconds(CurTime()));
} // start()
//|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//| Close
//| Last Updated 12-12-2006 10:00pm
//|$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#define NL "\n"
extern int ProfitTarget = 100; // closes all orders once Float hits this $ amount
extern bool CloseAllNow = false;
extern int MagicNumber = 1100; // closes all orders now
extern bool CloseProfitableTradesOnly = false; // closes only profitable trades
extern double ProftableTradeAmount = 1; // Only trades above this amount close out
extern bool ClosePendingOnly = false; // closes pending orders only
extern bool UseAlerts = true;
//+-------------+
//| Custom init |
//|-------------+
int init()
{
}
//+----------------+
//| Custom DE-init |
//+----------------+
int deinit()
{
}
//+------------------------------------------------------------------------+
//| Closes everything
//+------------------------------------------------------------------------+
//+------------------------------------------------------------------------+
//| Closes everything
//+------------------------------------------------------------------------+
void CloseAll()
{
int i;
bool result = false;
while(OrdersTotal()>0)
{
// Close open positions first to lock in profit/loss
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i, SELECT_BY_POS)==false) continue;
result = false;
if ( OrderType() == OP_BUY) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 15, Red );
if ( OrderType() == OP_SELL) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 15, Red );
if (UseAlerts) PlaySound("alert.wav");
}
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i, SELECT_BY_POS)==false) continue;
result = false;
if ( OrderType()== OP_BUYSTOP) result = OrderDelete( OrderTicket() );
if ( OrderType()== OP_SELLSTOP) result = OrderDelete( OrderTicket() );
if ( OrderType()== OP_BUYLIMIT) result = OrderDelete( OrderTicket() );
if ( OrderType()== OP_SELLLIMIT) result = OrderDelete( OrderTicket() );
if (UseAlerts) PlaySound("alert.wav");
}
Sleep(0);
}
}
//+------------------------------------------------------------------------+
//| cancels all orders that are in profit
//+------------------------------------------------------------------------+
void CloseAllinProfit()
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
bool result = false;
if ( OrderType() == OP_BUY && (OrderMagicNumber() == MagicNumber)&& OrderProfit()+OrderSwap()>ProftableTradeAmount) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
if ( OrderType() == OP_SELL && (OrderMagicNumber() == MagicNumber)&& OrderProfit()+OrderSwap()>ProftableTradeAmount) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
if (UseAlerts) PlaySound("alert.wav");
}
return;
}
//+------------------------------------------------------------------------+
//| cancels all pending orders
//+------------------------------------------------------------------------+
void ClosePendingOrdersOnly()
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
bool result = false;
if ( OrderType()== OP_BUYSTOP) result = OrderDelete( OrderTicket() );
if ( OrderType()== OP_SELLSTOP) result = OrderDelete( OrderTicket() );
}
return;
}
//+-----------+
//| Main |
//+-----------+
int start()
{
int OrdersBUY;
int OrdersSELL;
double BuyLots, SellLots, BuyProfit, SellProfit;
//+------------------------------------------------------------------+
// Determine last order price |
//-------------------------------------------------------------------+
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;
if(OrderType()==OP_BUY)
{
OrdersBUY++;
BuyLots += OrderLots();
BuyProfit += OrderProfit() + OrderCommission() + OrderSwap();
}
if(OrderType()==OP_SELL)
{
OrdersSELL++;
SellLots += OrderLots();
SellProfit += OrderProfit() + OrderCommission() + OrderSwap();
}
}
if(CloseAllNow) CloseAll();
if(CloseProfitableTradesOnly) CloseAllinProfit();
if(CloseAllNow) CloseAll();
if(CloseProfitableTradesOnly) CloseAllinProfit();
if(BuyProfit+SellProfit >= ProfitTarget) CloseAll();
if(ClosePendingOnly) ClosePendingOrdersOnly();
Comment(" Comments Last Update 12-12-2006 10:00pm", NL,
" Buys ", OrdersBUY, NL,
" BuyLots ", BuyLots, NL,
" Sells ", OrdersSELL, NL,
" SellLots ", SellLots, NL,
" Balance ", AccountBalance(), NL,
" Equity ", AccountEquity(), NL,
" Margin ", AccountMargin(), NL,
" MarginPercent ", MathRound((AccountEquity()/AccountMargin())*100), NL,
" Current Time is ",TimeHour(CurTime()),":",TimeMinute(CurTime()),".",TimeSeconds(CurTime()));
} // start()