ahib0205
Legendary Member

- Messages
- 19,329
- Joined
- Nov 18, 2007
- Messages
- 19,329
- Reaction score
- 746
- Points
- 166
Aku tak pasti camna korang hide TP dan SL..
Aku guna EA spt dibawah:
//+------------------------------------------------------------------+
//| Close_All_with_SL.mq4 |
//| Copyright © 2011, [email protected] |
//| http://www.fxcitizen-malay.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, [email protected]"
#property link "http://www.fxcitizen-malay.com"
//---- input parameters
extern double Ambil_Untung = 100000.0;
extern double Bunyi_Untung = 1.0;
extern bool Trigger_Untung=true;
extern double Stop_Loss = -100000.0;
extern bool Aktifkan_StopLoss=false;
extern double Bunyi_Rugi = -1.0;
extern bool Trigger_Rugi=false;
extern bool Trigger_TutupTrade=false;
int magic=1;
double close_trade=0.00;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double MacdCurrent, MacdPrevious, SignalCurrent;
double SignalPrevious, MaCurrent, MaPrevious;
int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external
// variables (Lots, StopLoss, TakeProfit,
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
//if (IsDemo() != true)
//if(AccountNumber()!=63738)
// {
// Comment("Ahli berdaftar sahaja. Call Rosli 012-465-5804");
// return(0); // check if it is registered under IB's account
// }
// to simplify the coding and speed up access
// data are put into internal variables
total=OrdersTotal();
// it is important to enter the market correctly,
// but it is more important to exit it correctly...
for(cnt=0;cnt<total;cnt++)
{
// OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
//if(OrderSelect(cnt, SELECT_BY_POS)==true) Comment("Profit for the order ",OrderProfit()); //newly added line
//if (OrderProfit()>=Bunyi_Untung && Trigger_Untung) PlaySound("alert.wav"); //newly added line
// if (OrderProfit()<=Bunyi_Rugi && Trigger_Rugi) PlaySound("alert2.wav"); //newly added line
}
//return(0);
//}
if (AccountProfit()>=Bunyi_Untung && Trigger_Untung) PlaySound("alert.wav"); //newly added line
if (AccountProfit()>=Ambil_Untung) close_ALL();
if (AccountProfit()<=Stop_Loss && Aktifkan_StopLoss) close_ALL_WITH_PENDING();
if (AccountProfit()<=Bunyi_Rugi && Trigger_Rugi) PlaySound("alert2.wav"); //newly added line
if (AccountProfit()>=Bunyi_Untung && Trigger_Untung) Comment("Profit for the order ",AccountProfit());
if (AccountProfit()<=Bunyi_Rugi && Trigger_Rugi) Comment("Profit for the order ",AccountProfit());
if (AccountProfit()==close_trade && Trigger_TutupTrade) PlaySound("news.wav"); //newly added line
Comment("Profit for the order ",AccountProfit(), " TakeProfit: ",Ambil_Untung, " StopLoss: ",Stop_Loss);
return(0);
}
//+-----------------------------------------------------------------------------------------------+
void close_ALL()
{
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);
Sleep(30);
}
}
return(0);
}
//+---------------------------------------------------------------------------------------+
void close_ALL_WITH_PENDING()
{
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 );
//Close BUYLIMIT pending order
case OP_BUYLIMIT : result=OrderDelete(OrderTicket());
//Close SELLLIMIT pending order
case OP_SELLLIMIT : result=OrderDelete(OrderTicket());
//Close BUYSTOP pending order
case OP_BUYSTOP : result=OrderDelete(OrderTicket());
//Close SELLSTOP pending order
case OP_SELLSTOP : result=OrderDelete(OrderTicket());
}
if(result == false)
{
//Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
//Sleep(3000);
Sleep(30);
}
}
return(0);
}
//+------------------------------------------------------------------+
thanks bro, mau cuba EA ni