Scripts Exemplos
Scripts Exemplos
//|
close-all-orders.mq4 |
//|
Copyright 2005, Matias Romeo. |
//|
Custom Metatrader Systems. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2005, Matias Romeo."
#property link
"mailto:matiasDOTromeoATgmail.com"
int start()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type
= OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY
: result = OrderClose( OrderTicket(),
OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL
: result = OrderClose( OrderTicket(),
OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
break;
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" ,
GetLastError() );
Sleep(3000);
}
}
return(0);
}
//+------------------------------------------------------------------+
//|
close-all-orders.mq4 |
//|
Copyright 2005, Matias Romeo. |
//|
Custom Metatrader Systems. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2005, Matias Romeo."
#property link
"mailto:matiasDOTromeoATgmail.com"
int start()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type
= OrderType();
bool result = false;
switch(type)
{
//Close pending orders
case OP_BUYLIMIT :
case OP_BUYSTOP
:
case OP_SELLLIMIT :
case OP_SELLSTOP : result = OrderDelete( OrderTicket() );
}
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" ,
GetLastError() );
Sleep(3000);
}
}
return(0);
}
//+------------------------------------------------------------------+
//|
close-all-orders.mq4 |
//|
Copyright 2005, Matias Romeo. |
//|
Custom Metatrader Systems. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2005, Matias Romeo."
#property link
"mailto:matiasDOTromeoATgmail.com"
int start()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type
= OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY
: result = OrderClose( OrderTicket(),
OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL
: result = OrderClose( OrderTicket(),
OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
}
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" ,
GetLastError() );
Sleep(3000);
}
}
}
return(0);
//+------------------------------------------------------------------+
//|
close-all-orders.mq4 |
//|
Copyright 2005, Matias Romeo. |
//|
Custom Metatrader Systems. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2005, Matias Romeo."
#property link
"mailto:matiasDOTromeoATgmail.com"
extern int ProfitTarget = 10; // Profit target in dollars
int start()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type
= OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY
: if ( OrderProfit() >= ProfitTarget) result =
OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),
MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL
: if ( OrderProfit() >= ProfitTarget) result =
OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),
MODE_ASK), 5, Red );
}
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" ,
GetLastError() );
Sleep(3000);
}
}
return(0);
}
//+------------------------------------------------------------------+
//|
CloseAllTrades.mq4 |
//|
Copyright 2005, Renato |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2005, rodrigokaus"
#property link
"http://www.forex-tsd.com/expert-advisorsmetatrader-4/703-100-pips.html"
extern color clCloseBuy = Yellow;
extern color clCloseSell = Yellow;
extern string Name_Expert = "CloseAllTrades";
void deinit() {
Comment("");
}
//+------------------------------------------------------------------+
//|
|
//+------------------------------------------------------------------+
int start(){
CloseAllTrades();
return (0);
}
void CloseAllTrades() {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol()) {
if (OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,GetSlippage(),clCloseBuy);
if (OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask,GetSlippage(),clCloseSell);
if (OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT
||
OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)
OrderDelete(OrderTicket());
}
}
}
}
double GetSlippage() { return((Ask-Bid)/Point); }
//+------------------------------------------------------------------+
//|
CloseAll.mq4 |
//|
Copyright 2015, FlashTrade JFL |
//|
https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, FlashTrade JFL"
#property link
"https://www.mql5.com"
#property version
"1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function
|
//+------------------------------------------------------------------+
void OnStart()
{
//--for(int x=OrdersTotal()-1;x>=0;x--)
{
if(!OrderSelect(x,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
if(!
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,CLR_NONE))
{ Alert("fail deleting trade order"); }
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| CloseAll.mq4 |
//| ThinkTrustTrade |
//| www.think-trust-trade.com |
//+------------------------------------------------------------------+
#property copyright "ThinkTrustTrade"
#property link "www.think-trust-trade.com"
extern string Visit="www.think-trust-trade.com";
extern string Like="www.facebook.com/ThinkTrustTrade";
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//---int ticket;
if (OrdersTotal()==0) return(0);
for (int i=OrdersTotal()-1; i>=0; i--)
{//pozicio kivalasztasa
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)//ha kivalasztas ok
{
//Print ("order ticket: ", OrderTicket(), "order magic: ",
OrderMagicNumber());
if (OrderType()==0)
{//ha long
ticket=OrderClose(OrderTicket(),OrderLots(),
MarketInfo(OrderSymbol(),MODE_BID), 3,Red);
if (ticket==-1) Print ("Error: ", GetLastError());
if (ticket>0) Print ("Position ", OrderTicket() ," closed. Thank you for using
our script! Visit www.think-trust-trade.com for more free tools.");
}
if (OrderType()==1)
{//ha short
ticket=OrderClose(OrderTicket(),OrderLots(),
MarketInfo(OrderSymbol(),MODE_ASK), 3,Red);
if (ticket==-1) Print ("Error: ", GetLastError());
if (ticket>0) Print ("Position ", OrderTicket() ," closed. Thank you for using
our script! Visit www.think-trust-trade.com for more free tools.");
}
}
}//pozicio kivalszatas vege
//---return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| KillAll.mq4 |
//| [email protected] |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "CodeMonkey"
#property link "[email protected]"
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#property copyright "Copyright 2008, Ardiansyah"
#property link "ardfx.blogspot.com"
#property show_inputs
extern int pembagi = 2;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//---int ticket;
int err;
double Margin;
Margin = AccountFreeMargin( ) ;
double Hasil;
double Lots ;
Hasil = Margin/pembagi/1000;
Lots = MathFloor(Hasil);
while(true)
{
ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Bid + 1,0,NULL,0,0,White);
if(ticket<0)
{
err=GetLastError();
Print("OrderSend failed with error ",err);
if (err == 135)
{
RefreshRates();
break;
}
}
else
{
Print("Hasil =", Hasil);
return(0);
}
}
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| _Open_SELL.mq4 |
//| " " |
//| SELL FreeMargin |
//| Bookkeeper, 2006, [email protected] |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property show_inputs //
//+------------------------------------------------------------------+
extern double Share = 0.1; // FreeMargin :
// = 0
// = 1
extern int DistSL = 35; // SL
extern int DistTP = 35; // TP
extern int Slippage = 5; //
extern bool StopLoss = true; //
extern bool TakeProfit = true; //
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void start()
{
int ticket;
double SL = 0, TP = 0, Stake, StepDgts;
int i, j = 0;
for(i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i, SELECT_BY_POS))
{
if(OrderSymbol() != Symbol())
continue;
if((OrderOpenPrice() >= target - within*Point) &&
(OrderOpenPrice() <= target + within*Point))
{
OpenOrdersBuffer[j] = OrderTicket();
j++;
}
}
}
if(j > 1)
{
for(i = 0; i < j; i++)
{
if(MessageBox("Multiple Tickets Found\nClose Ticket " +
DoubleToStr(OpenOrdersBuffer[i],0), "Close Order",
MB_YESNO|MB_ICONQUESTION) == IDYES)
{
if(OrderSelect(OpenOrdersBuffer[i], SELECT_BY_TICKET))
if(OrderClose(OrderTicket(), OrderLots(), GetPrice(OrderType()), 2))
PlaySound("ok.wav");
}
}
}
else
if(j > 0)
{
if(MessageBox("Will Close Ticket " + DoubleToStr(OpenOrdersBuffer[0], 0),
"Close Order", MB_OKCANCEL|MB_ICONQUESTION) == IDOK)
{
if(OrderSelect(OpenOrdersBuffer[0], SELECT_BY_TICKET))
if(OrderClose(OrderTicket(), OrderLots(), GetPrice(OrderType()), 2))
PlaySound("ok.wav");
}
}
return(ret);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetPrice(int ordertype)
{
switch(ordertype)
{
case OP_BUY: return(Bid);
case OP_SELL: return(Ask);
}
}
//+------------------------------------------------------------------+
SENDING Pending Oders
//+------------------------------------------------------------------+
//| send_pending.mq4 |
//| Copyright 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property show_confirm
//+------------------------------------------------------------------+
//| script "send pending order with expiration data" |
//+------------------------------------------------------------------+
int start()
{
int ticket,expiration;
double point;
//---point=MarketInfo(Symbol(),MODE_POINT);
expiration=CurTime()+PERIOD_D1*60;
//---while(true)
{
ticket=OrderSend(Symbol(),OP_SELLSTOP,1.0,Bid-100*point,0,0,0,"some
comment",16384,expiration,Green);
if(ticket<=0) Print("Error = ",GetLastError());
else { Print("ticket = ",ticket); break; }
//---- 10 seconds wait
Sleep(10000);
}
//---return(0);
}
//+------------------------------------------------------------------+
#include <stdlib.mqh>
//+-----------------------------SCRIPT CODE--------------------------+
int start()
{
double Resistance = WindowPriceOnDropped();
datetime time = WindowTimeOnDropped();
int TimeNow = TimeCurrent();
int timeframe = Period();
double factor;
switch(timeframe)
{
case 1 : factor = 0.2; break;
case 5 : factor = 1; break;
case 15 : factor = 3; break;
case 30 : factor = 6; break;
case 60 : factor = 12; break;
case 240 : factor = 48; break;
case 1440 : factor = 288; break;
//+-----------------------------SCRIPT CODE--------------------------+
int start()
{
double Support = WindowPriceOnDropped();
datetime time = WindowTimeOnDropped();
int TimeNow = TimeCurrent();
int timeframe = Period();
double factor;
switch(timeframe)
{
case 1 : factor = 0.2; break;
case 5 : factor = 1; break;
case 15 : factor = 3; break;
case 30 : factor = 6; break;
case 60 : factor = 12; break;
case 240 : factor = 48; break;
case 1440 : factor = 288; break;
case 10080 : factor = 2016; break;
case 43200 : factor = 8640; break;
}
int length = factor * Support_length;
ObjectCreate("Support_Line" + TimeNow,OBJ_TREND,0,time+length,Support,timelength,Support);
ObjectSet("Support_Line" + TimeNow,OBJPROP_COLOR,Support_Color);
ObjectSet("Support_Line" + TimeNow,OBJPROP_WIDTH,Support_Width);
ObjectSet("Support_Line" + TimeNow,OBJPROP_RAY,false);
return(0);
}
//+------------------------------------------------------------------+
OPEN ORDERS
}
if (error || err >10) return;
}
return;
}
//-------------------------------------------------------------------void ShowERROR()
{
int err=GetLastError();
switch ( err )
{
case 1: return;
default: Alert("Error " ,err," ",Symbol());return;
}
}
//-------------------------------------------------------------------#property copyright "Copyright 2010, Khlystov Vladimir"
#property link "[email protected]"
#property show_inputs
//-------------------------------------------------------------------extern bool SELL = false,
BUY = false;
extern double Lot = 1.0;
int slippage = 3;
//-------------------------------------------------------------------int start()
{
if (BUY)
{
OPENORDER ("Buy", NormalizeDouble(Bid - 70*Point,Digits),NormalizeDouble(Ask +
25*Point,Digits));
}
if (SELL)
{
OPENORDER ("Sell",NormalizeDouble(Ask + 70*Point,Digits),NormalizeDouble(Bid 25*Point,Digits));
}
return(0);
}
//-------------------------------------------------------------------void OPENORDER(string ord,double SL,double TP)
{
int error,err;
while (true)
{ error=true;
if (ord=="Buy" ) error=OrderSend(Symbol(),OP_BUY,
Lot,NormalizeDouble(Ask,Digits),slippage,SL,TP,"",0,3,Blue);
if (ord=="Sell")
error=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),slippage,SL,T
P,"",0,3,Red);
if (error==-1)
{
ShowERROR();
err++;Sleep(2000);RefreshRates();
}
if (error || err >10) return;
}
return;
}
//-------------------------------------------------------------------void ShowERROR()
{
int err=GetLastError();
switch ( err )
{
case 1: return;
default: Alert("Error " ,err," ",Symbol());return;
}
}
//--------------------------------------------------------------------