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

Heiken299 EA

Heiken299_EA是结合自定义指标Heiken Ashi、均线MA、震动指标AO信号开发的智能交易系统。

Heiken299_EA源码:

//+------------------------------------------------------------------+
//|                                                  Heiken299_EA.mq4|
//|                       Copyright @2005, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property  copyright "Copyright @2005, MetaQuotes Software Corp."
#property  link      "http://www.125808047.com/"
#define MAGICMA  20050000

extern double Lots               = 0.1;
extern double MaximumRisk        = 0.5;
extern double TakeProfit = 2000;
extern double TrailingStop = 0;
extern double Stoploss = 60;
extern double risk = 10;
double lotMM;
bool cg = false;
//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==symbol && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
   if(buys>0) return(buys);
   else       return(-sells);
  }

bool CheckHeikenAshi(int cmd)
{
   double HA0, HA1, HA2, HA3;
   
   HA0 = iCustom(NULL,0,"Heiken Ashi",0,0);
   HA1 = iCustom(NULL,0,"Heiken Ashi",1,0);
   HA2 = iCustom(NULL,0,"Heiken Ashi",2,0);
   HA3 = iCustom(NULL,0,"Heiken Ashi",3,0);
   
   if (cmd == OP_SELL)
   {
     if (HA2 > HA3 && HA1 < HA0) return(true);
   }
   if (cmd == OP_BUY)
   {
      if (HA2 < HA3 && HA1 > HA0) return(true);
   }
   return(false);
}
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   int    res;

  double HA0, HA1, HA2, HA3;  // delete this line if you use CheckHeikenAshi function
   double Close1, MA200,AO;
   
   HA0 = iCustom(NULL,0,"Heiken Ashi",0,0);  // delete this line if you use CheckHeikenAshi function
   HA1 = iCustom(NULL,0,"Heiken Ashi",1,0);  // delete this line if you use CheckHeikenAshi function
   HA2 = iCustom(NULL,0,"Heiken Ashi",2,0);  // delete this line if you use CheckHeikenAshi function
   HA3 = iCustom(NULL,0,"Heiken Ashi",3,0);  // delete this line if you use CheckHeikenAshi function
   Close1 = Close[1];
   MA200 = iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0);
   AO = iAO(NULL,0,0);

  if (CheckHeikenAshi(OP_SELL) && Close1 < MA200 && AO < 0) // Function version
     {
      res=OrderSend(Symbol(),OP_SELL,MathCeil(AccountBalance() * risk / 100000),Bid,1,Bid+Stoploss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red);
      return;
     }
  if (CheckHeikenAshi(OP_BUY) && Close1 > MA200 && AO > 0)  // Function version
     {
      res=OrderSend(Symbol(),OP_BUY,MathCeil(AccountBalance() * risk / 100000),Ask,1,Ask-Stoploss*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);
      return;
     }
//----
  }

void CheckForClose()
  {
   double HA0, HA1, HA2, HA3;  
   
   HA0 = iCustom(NULL,0,"Heiken Ashi",0,0);  
   HA1 = iCustom(NULL,0,"Heiken Ashi",1,0);  
   HA2 = iCustom(NULL,0,"Heiken Ashi",2,0);  
   HA3 = iCustom(NULL,0,"Heiken Ashi",3,0); 

//----
   for(int i=0;i<OrdersTotal();i++)
     {
      cg = OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol())  
        {
         if(OrderType()==OP_BUY)  
           {

          if (CheckHeikenAshi(OP_SELL)) 
                {
                 cg = OrderClose(OrderTicket(),OrderLots(),Bid,1,Violet); 
                }
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     cg = OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                    }
                 }
              }
           }
         else 
           {
         if (CheckHeikenAshi(OP_BUY)) 
              {
               cg = OrderClose(OrderTicket(),OrderLots(),Ask,1,Violet); // close position
              }
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     cg = OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                    }
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void OnTick()
{
   Comment("www.125808047.com");
   if(Bars<100 || IsTradeAllowed()==false) return;

   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose();
  }
//+--------------------------------------------------------------
打赏
版权所有转载请注明标题及链接:峰汇在线 » Heiken299 EA
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏