//+------------------------------------------------------------------+ //| EA 2sma.mq4 | //| Dwi M ea@dwim.web.id | //| http://ea.dwim.web.id | //+------------------------------------------------------------------+ #property copyright "Dwi M ea@dwim.web.id" #property link "http://ea.dwim.web.id" extern int TakeProfit = 30; extern int StopLoss = 30; extern int Slippage = 3; extern double Lots = 1.0; extern int TrailingStop = 5; extern bool Trailing = true; extern int SMA1Periode = 4; extern int SMA2Periode = 8; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- double dSMA1, dSMA2, dSMA1before, dSMA2before, RSI; int iTrade=0; dSMA1=iMA(NULL,0,SMA1Periode,0,MODE_EMA,PRICE_CLOSE,0); dSMA2=iMA(NULL,0,SMA2Periode,0,MODE_EMA,PRICE_CLOSE,0); dSMA1before=iMA(NULL,0,SMA1Periode,0,MODE_EMA,PRICE_CLOSE,1); dSMA2before=iMA(NULL,0,SMA2Periode,0,MODE_EMA,PRICE_CLOSE,1); RSI = iRSI(NULL, PERIOD_D1, 14, PRICE_CLOSE, 0); Comment("EA 2SMA \n"+ "System : pantang_merah \n"+ "Coding : DwiM ea@dwim.web.id \n"+ "http://ea.dwim.web.id"); if (OrdersTotal()<1) { if (AccountFreeMargin()<1000*Lots) { Comment("EA tidak bekerja, dana kurang :", AccountFreeMargin()); return(0);} if ((dSMA1>dSMA2) && (dSMA1before<dSMA2before) && RSI>50) { Buy(); } if ((dSMA1<dSMA2) && (dSMA1before>dSMA2before) && RSI<50) { Sell(); } } /* >>> Fungsi Trailing Stop <<< */ for(iTrade=0;iTrade<OrdersTotal();iTrade++) { OrderSelect(iTrade,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY && OrderSymbol()==Symbol()) { if((dSMA1<dSMA2) && (dSMA1before>dSMA2before)) { OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Violet); } if (Trailing==true) { if(TrailingStop>0) { BuyTrailing(); } } } else { if((dSMA1>dSMA2) && (dSMA1before<dSMA2before)) { OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Violet); } if (Trailing==true) { if(TrailingStop>0) { SellTrailing(); } } } } //---- return(0); } //+------------------------------------------------------------------+ void Buy() { if (Digits==3 || Digits==5) // Perintah untuk broker 5 Digits { OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Bid-StopLoss*Point*10,Ask+TakeProfit*Point*10,0); } else // Perintah untuk broker 4 Digits { OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Bid-StopLoss*Point,Ask+TakeProfit*Point,0); } } void Sell() { if (Digits==3 || Digits==5) { OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Ask+StopLoss*Point*10,Bid-TakeProfit*Point*10,0); } else { OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Ask+StopLoss*Point,Bid-TakeProfit*Point,0); } } void BuyTrailing() { if (Digits==3 || Digits==5) { if(Bid-OrderOpenPrice()>Point*10*TrailingStop) { if(OrderStopLoss()<Bid-Point*10*TrailingStop) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*10*TrailingStop,OrderTakeProfit(),0,Green); return(0); } } } else { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()<Bid-Point*TrailingStop) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green); return(0); } } } } void SellTrailing() { if (Digits==3 || Digits==5) { if((OrderOpenPrice()-Ask)>(Point*10*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*10*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*10*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } else { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } }
Maszanet.blogspot.com
No comments:
Post a Comment