Friday, 9 November 2012

Script Close order lengkap n muantap


##script Close order lengkap n muantap
//+------------------------------------------------------------------+
//| Close order lengkap n muantap.mq4 |
//| Oprekan by Bambang Sugianto |
//+------------------------------------------------------------------+
#property copyright "Bambang Sugianto"
#property show_inputs
#include
//+------------------------------------------------------------------+
//| input parameters: |
//+------------------------------------------------------------------+
extern bool CloseAllSymbols = false;
extern string Important = "Select one of the following:";
extern bool CloseOpenOrdersAndCancelPending = true;
extern bool CloseOpenOrders = false;
extern bool DeleteAllPendingOrders = false;
extern bool CloseOrdersWithPlusProfit = false;
extern bool CloseOrdersWithMinusProfit = false;
extern bool CloseOrdersOpenedBeforeToday = false;
//+------------------------------------------------------------------+
//| global variables to program: |
//+------------------------------------------------------------------+
double Price[2];
int giSlippage;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
void start() {
int iOrders=OrdersTotal()-1, i;
if(CloseOpenOrdersAndCancelPending) {
for(i=iOrders; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
if ( OrderSymbol()==Symbol() || CloseAllSymbols == true ) {
if((OrderType()<=OP_SELL) && GetMarketInfo()) {
if(!OrderClose(OrderTicket(),OrderLots(),Price[1-OrderType()],giSlippage)) Print(OrderError());
}
else if(OrderType()>OP_SELL) {
if(!OrderDelete(OrderTicket())) Print(OrderError());
}
}
}
}
}
if(CloseOpenOrders) {
for(i=iOrders; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
if ( OrderSymbol()==Symbol() || CloseAllSymbols == true ) {
if((OrderType()<=OP_SELL) && GetMarketInfo()) {
if(!OrderClose(OrderTicket(),OrderLots(),Price[1-OrderType()],giSlippage)) Print(OrderError());
}
}
}
}
}
if(DeleteAllPendingOrders) {
for(i=iOrders; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
if ( OrderSymbol()==Symbol() || CloseAllSymbols == true ) {
if(OrderType()>OP_SELL) {
if(!OrderDelete(OrderTicket())) Print(OrderError());
}
}
}
}
}
else if(CloseOrdersWithPlusProfit) {
for(i=iOrders; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderProfit() >= 0)) {
if ( OrderSymbol()==Symbol() || CloseAllSymbols == true ) {
if((OrderType()<=OP_SELL) && GetMarketInfo()) {
if(!OrderClose(OrderTicket(),OrderLots(),Price[1-OrderType()],giSlippage)) Print(OrderError());
}
}
}
}
}
else if(CloseOrdersWithMinusProfit) {
for(i=iOrders; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderProfit() <= 0)) {
if ( OrderSymbol()==Symbol() || CloseAllSymbols == true ) {
if((OrderType()<=OP_SELL) && GetMarketInfo()) {
if(!OrderClose(OrderTicket(),OrderLots(),Price[1-OrderType()],giSlippage)) Print(OrderError());
}
}
}
}
}
else if( CloseOrdersOpenedBeforeToday) {
datetime tTodayStart=TimeCurrent()-TimeHour(TimeCurrent())*60*60-TimeMinute(TimeCurrent())*60;
for(i=iOrders; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && (OrderOpenTime() < tTodayStart)) {
if ( OrderSymbol()==Symbol() || CloseAllSymbols == true ) {
if((OrderType()<=OP_SELL) && GetMarketInfo()) {
if(!OrderClose(OrderTicket(),OrderLots(),Price[1-OrderType()],giSlippage)) Print(OrderError());
}}
else if(OrderType()>OP_SELL) {
if(!OrderDelete(OrderTicket())) Print(OrderError());
}
}
}
} Alert("beres juragan...perintah CLOSE sudah terlaksana..." ); // tambahan alert
}
//+------------------------------------------------------------------+
//| Function..: OrderError |
//+------------------------------------------------------------------+
string OrderError() {
int iError=GetLastError();
return(StringConcatenate("Order:",OrderTicket()," GetLastError()=",iError," ",ErrorDescription(iError)));
}
//+------------------------------------------------------------------+
//| Function..: GetMarketInfo |
//| Returns...: bool Success. |
//+------------------------------------------------------------------+
bool GetMarketInfo() {
RefreshRates();
Price[0]=MarketInfo(OrderSymbol(),MODE_ASK);
Price[1]=MarketInfo(OrderSymbol(),MODE_BID);
double dPoint=MarketInfo(OrderSymbol(),MODE_POINT);
if(dPoint==0) return(false);
giSlippage=(Price[0]-Price[1])/dPoint;
return(Price[0]>0.0 && Price[1]>0.0);
}

No comments:

Post a Comment