Sumberdan Tutor >
//+------------------------------------------------------------------+
//| 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)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Bid-StopLoss*Point,Ask+TakeProfit*Point,0);
}
if ((dSMA1<dSMA2) && (dSMA1before>dSMA2before) && RSI<50)
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Ask+StopLoss*Point,Bid-TakeProfit*Point,0);
}
}
/* >>> Fungsi Trailing Stop <<< */
if(Trailing==true)
{
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(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if((dSMA1>dSMA2) && (dSMA1before<dSMA2before))
{
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Violet);
}
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);
}
//+------------------------------------------------------------------+
Maszanet.blogspot.com
No comments:
Post a Comment