诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4 EA > 正文

采用DeMarker和RSI信号开发的EA FarhadCrab6.mq4

FarhadCrab6 EA根据DeMarker和RSI信号在进行超短交易。

源码:

//+-------------------------------------------------------------------------------------+
//|                                                                     FarhadCrab6.mq4 |
//|                                                     Copyright @2007, Farhad Farshad |
//+-------------------------------------------------------------------------------------+
#property copyright "Copyright @2007, Farhad Farshad"
#property link      "http://www.125808047.com"
#include <stdlib.mqh>

extern double maxLoss        = 100;    
extern double maxYield       = 0.1;   
extern double lTakeProfit    = 300;
extern double sTakeProfit    = 300;
extern double takeProfit     = 300;
extern double pr             = 300;
extern double stopLoss       = 0;
extern int    magicEA        = 124;
extern double lTrailingStop  = 15;
extern double sTrailingStop  = 15;
extern color  clOpenBuy      = Blue;
extern color  clCloseBuy     = Aqua;
extern color  clOpenSell     = Red;
extern color  clCloseSell    = Violet;
extern color  clModiBuy      = Blue;
extern color  clModiSell     = Red;
extern int    Slippage       = 3;
extern string nameEA         = "FarhadCrab6.mq4";

double maLongCurrent, maShortCurrent, maLongPrevious, maShortPrevious, faRSICurrent;
double realTP, realSL, faMiddle, faHighest, faLowest, closeCurrent,faCloseM5, closeCurrentD, closePreviousD;
int cnt, ticket;
double initialDeposit; 
double lLots , sLots; 
bool cg = false;

int OnInit()
  {  
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
{
initialDeposit=AccountBalance();

if ((AccountEquity()>(initialDeposit+((maxYield/100)*initialDeposit))) || (AccountBalance()-AccountEquity()>((maxLoss/100)*initialDeposit)))
{
CloseBuyPositions(); 
}
if ((AccountEquity()>(initialDeposit+((maxYield/100)*initialDeposit)))|| (AccountBalance()-AccountEquity()>((maxLoss/100)*initialDeposit)))
{
CloseSellPositions();
}
         
   double overbought,oversold;
   if (maLongCurrent>closeCurrentD) //downtrend
   {
   oversold = 0.15;
   overbought = 0.85;
   }
   if (maLongCurrent<closeCurrentD) //uptrend
   {
    oversold = 0.15;
    overbought = 0.85;
   }
   
double deMark              = iDeMarker(NULL,PERIOD_M1,9,0);
double previousdeMark      = iDeMarker(NULL,PERIOD_M1,9,1);
double rsi                 = iRSI(NULL,PERIOD_M1,9,PRICE_CLOSE,0);

double n;
if ((AccountEquity()-AccountBalance()==0) || (AccountEquity()-AccountBalance()>-((OrderLots())*500)))
   
   n = 0;
   else 
    n = 1;

if (OrdersTotal()>n)
{
return;
}

int bnt;
   for(bnt=0;bnt<OrdersTotal();bnt++)
   {
      cg = OrderSelect (bnt, SELECT_BY_POS);
      if (TimeCurrent()-OrderOpenTime()<500) {
      return;
   }
   }

   if ((!takeBuyPositions()) && (n == 0) ){
      if ((deMark<oversold) && (rsi < 30))
      {
         OpenBuy();
      }
      }
      
         if ((!takeBuyPositions()) && (n == 1) ){
      if ((deMark<0.50) && (previousdeMark < deMark)&& (OrderType()==OP_SELL))
      {
         hedgeOpenBuy();
      }
      }

   if ((!takeSellPositions()) && (n == 0)){
      if ((deMark>overbought)&& (rsi > 70))
       {
         OpenSell();
      }
      }

       if ((!takeSellPositions()) && (n == 1)){
      if ((deMark>0.50)&& (previousdeMark > deMark)&& (OrderType()==OP_BUY))
       {
         hedgeOpenSell();
       }
       }
   TrailingPositionsBuy(lTrailingStop);
   TrailingPositionsSell(sTrailingStop);
}

bool takeBuyPositions() {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber() == magicEA) {
}
} 
}
return(0);
}

bool takeSellPositions() {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber() == magicEA) {
}
} 
}
return(0);
}

void TrailingPositionsBuy(int trailingStop) { 
   for (int i=0; i<OrdersTotal(); i++) { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
         if (OrderSymbol()==Symbol() && OrderMagicNumber() == magicEA) { 
            if (OrderType()==OP_BUY) { 
               if (Bid-OrderOpenPrice()>trailingStop*Point) { 
                  if (OrderStopLoss()<Bid-trailingStop*Point) 
                     ModifyStopLoss(Bid-trailingStop*Point); 
               } 
            } 
         } 
      } 
   } 
} 
void TrailingPositionsSell(int trailingStop) { 
   for (int i=0; i<OrdersTotal(); i++) { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
         if (OrderSymbol()==Symbol() && OrderMagicNumber() == magicEA) { 
            if (OrderType()==OP_SELL) { 
               if (OrderOpenPrice()-Ask>trailingStop*Point) { 
                  if (OrderStopLoss()>Ask+trailingStop*Point || OrderStopLoss()==0)  
                     ModifyStopLoss(Ask+trailingStop*Point); 
               } 
            } 
         } 
      } 
   } 
} 
void ModifyStopLoss(double ldStopLoss) { 
   bool fm;
   fm = OrderModify(OrderTicket(),OrderOpenPrice
(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE); 
  
} 

void OpenBuy() { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 
   ldLot = GetSizeLot(); 
   ldStop = GetStopLossBuy(); 
   ldTake = GetTakeProfitBuy(); 
   lsComm = GetCommentForOrder(); 
   if ((AccountEquity()-AccountBalance()==0) || (AccountEquity()-AccountBalance()>-((OrderLots())*500)))
   lLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/10),1);
   else 
   lLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/5),1);
   cg = OrderSend(Symbol(),OP_BUY,lLots,Ask,Slippage,ldStop,ldTake,nameEA,magicEA,0,clOpenBuy);  
} 
void OpenSell() { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 
   ldLot = GetSizeLot(); 
   ldStop = GetStopLossSell(); 
   ldTake = GetTakeProfitSell(); 
   lsComm = GetCommentForOrder(); 
   if ((AccountEquity()-AccountBalance()==0) || (AccountEquity()-AccountBalance()>-((OrderLots())*500)))
   sLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/10),1);
   else 
   sLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/5),1);
   cg = OrderSend(Symbol(),OP_SELL,sLots,Bid,Slippage,ldStop,ldTake,nameEA,magicEA,0,clOpenSell); 
} 

void hedgeOpenBuy() { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 
   ldLot = GetSizeLot(); 
   ldStop = GetStopLossBuy(); 
   ldTake = GetTakeProfitBuy(); 
   lsComm = GetCommentForOrder(); 
   lLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/5),1);
   cg = OrderSend(Symbol(),OP_BUY,lLots,Ask,Slippage,Ask-60*Point,ldTake,nameEA,magicEA,0,clOpenBuy);      
} 
void hedgeOpenSell() { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 
   ldLot = GetSizeLot(); 
   ldStop = GetStopLossSell(); 
   ldTake = GetTakeProfitSell(); 
   lsComm = GetCommentForOrder(); 
   sLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/5),1);
   cg = OrderSend(Symbol(),OP_SELL,sLots,Bid,Slippage,Bid+60*Point,ldTake,nameEA,magicEA,0,clOpenSell); 
} 

string GetCommentForOrder() { return(nameEA); } 
double GetSizeLot() { return(lLots); } 
double GetTakeProfitBuy() { if (iADX(NULL,0,14,PRICE_MEDIAN,MODE_MAIN,0)<25)  return(Ask+lTakeProfit*Point); else return(Ask+pr*Point); } 
double GetTakeProfitSell() { if (iADX(NULL,0,14,PRICE_MEDIAN,MODE_MAIN,0)<25) return(Bid-sTakeProfit*Point); else return (Bid-pr*Point);} 
double GetStopLossBuy() { if (stopLoss==0) return(0); else  return(Ask - stopLoss*Point);}
double GetStopLossSell() { if (stopLoss==0) return(0); else return(Bid + stopLoss*Point);}

void CloseBuyPositions(){ 
   for (int i=0; i<OrdersTotal(); i++) { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
         if (OrderSymbol()==Symbol() && OrderMagicNumber() == magicEA) { 
            if (OrderType()==OP_BUY) cg = OrderClose(OrderTicket(),lLots,Bid,Slippage);
         } 
      } 
   } 
} 

void CloseSellPositions(){ 
   for (int i=0; i<OrdersTotal(); i++) { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
         if (OrderSymbol()==Symbol() && OrderMagicNumber() == magicEA) { 
            if (OrderType()==OP_SELL) cg = OrderClose(OrderTicket(),sLots,Ask,Slippage);
         } 
      } 
   } 
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 采用DeMarker和RSI信号开发的EA FarhadCrab6.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏