كود PHP:
//+------------------------------------------------------------------+
//| الله اكبر.mq4 |
//| +++++++++@hotmail.com |
//| +++++++++@hotmail.com |
//+------------------------------------------------------------------+
#property copyright "++++++++@hotmail.com"
#property link "+++++++++++@hotmail.com"
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
extern int MaxTrades = 1; // ---------------- 1
extern int stoploss = 100; // ---------------- 2
extern int takeprofit = 50; // ---------------- 3
extern double TrailingStop =10; // ---------------- 4
extern bool UseHourTrade = false; // ---------------- 5
extern int FromHourTrade = 7; // ---------------- 6
extern int ToHourTrade = 17; // ---------------- 7
extern string MM_Parameters = "---------- Money Management";
extern double Lots = 1;
extern bool MM = false, // ---------------- 8
AccountIsMicro = false;
extern int Risk = 10; // ---------------- 9
int ID=200; // -------------------- 10
//+------------------------------------------------------------------+
//| FUNCTION DEFINITIONS deinitialization function |
//+------------------------------------------------------------------+
void deinit() {
Comment("");
}
int orderscnt(){
int cnt=0;
for(int i =0;i<OrdersTotal();i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
if(OrderSymbol()==Symbol() && ID==OrderMagicNumber()){
cnt++;
}
}
}
return(cnt);
}
//+------------------------------------------------------------------+
//| FUNCTION DEFINITIONS Start function |
//+------------------------------------------------------------------+
int start()
{
if (UseHourTrade){
if(!(Hour()>=FromHourTrade&&Hour()<=ToHourTrade)){
Comment("Non-Trading Hours!");
return(0);
}
}
double EMA3cr, EMA3pr, EMA7cr, EMA7pr; // --------------- 11
EMA3cr=iMA(NULL, 0, 3, 0, MODE_SMA, PRICE_CLOSE,0); // ----- 12
EMA3pr=iMA(NULL, 0, 3, 0, MODE_SMA, PRICE_CLOSE,1); // ----- 13
EMA7cr=iMA(NULL, 0, 7, 0, MODE_SMA, PRICE_CLOSE,0); // ----- 14
EMA7pr=iMA(NULL, 0, 7, 0, MODE_SMA, PRICE_CLOSE,1); // ----- 15
double sl,tp;
if(MM) Lots = subLotSize();
if (EMA3cr>EMA7cr && EMA3pr<EMA7pr){ // ------------------------ 22
if(orderscnt()<MaxTrades){
if(stoploss==0){sl=0;}else{sl=Ask-stoploss*Point;}
if(takeprofit==0){tp=0;}else{tp=Ask+takeprofit*Point;}
OrderSend(Symbol(),OP_BUY,Lots,Ask,2,sl,tp,"My Own Expert",ID,0,Blue);
PlaySound("Alert.wav");
}
}
if (EMA3cr<EMA7cr && EMA3pr>EMA7pr){ // ------------------------ 23
if(orderscnt()<MaxTrades){
if(stoploss==0){sl=0;}else{sl=Bid+stoploss*Point;}
if(takeprofit==0){tp=0;}else{tp=Bid-takeprofit*Point;}
OrderSend(Symbol(),OP_SELL,Lots,Bid,2,sl,tp,"My Own Expert",ID,0,Red);
PlaySound("Alert.wav");
}
}
//+------------------------------------------------------------------+
//| FUNCTION DEFINITIONS TrailingStop |
//+------------------------------------------------------------------+
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,
OrderTakeProfit(),0,Green);
return(0);
}
}
}
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,
OrderTakeProfit(),0,Red);
return(0);
}
}
}
return(0);
}
//+------------------------------------------------------------------+
//| FUNCTION DEFINITIONS Money Managment |
//+------------------------------------------------------------------+
double subLotSize()
{
double lotMM = MathCeil(AccountFreeMargin() * Risk / 1000) / 100;
if(AccountIsMicro==false)
{
if(lotMM < 0.1) lotMM = Lots;
if((lotMM > 0.5) && (lotMM < 1)) lotMM = 0.5;
if(lotMM > 1.0) lotMM = MathCeil(lotMM);
if(lotMM > 100) lotMM = 100;
}
else
{
if(lotMM < 0.01) lotMM = Lots;
if(lotMM > 1.0) lotMM = MathCeil(lotMM);
if(lotMM > 100) lotMM = 100;
}
return (lotMM);
}
//+---------------------------------------------------------------------------------+