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

根据RSI信号交易的EA King EA.mq4

King EA 根据RSI信号在进行自动交易。

源码:

//+------------------------------------------------------------------+
//|                                                      King EA.mq4 |
//|                                                        opensurce |
//+------------------------------------------------------------------+
#property copyright "opensurce"
#property link      "http://www.125808047.com/"

extern int       Magic         = 1110;
extern double    Lots          = 1.0;
extern int       SL            = 250;
extern int       TP            = 50;
extern int       Start         = 21;
extern int       End           = 6;
extern double    RSI_BUY       = 30;
extern double    RSI_SELL      = 70;
extern int       RSI_PERIOD    = 10;
extern int       RSI_TF        = 1;
extern bool      MM            = false;
extern int       LotsPercent   = 10;
extern int    MaxOpenTime_BUY  = 10;
extern int    MaxOpenTime_SELL = 10;
/////////////////////////////////////////
int       MaxLot        = 100;
double    MinLot        = 0.01;
double    RSI_BUY_Zera  = 40;
double    RSI_SELL_Zera = 60;
bool      Compra        = true;
bool      Venda         = true;
int    i,tmp,ordtotal,closeprice,cnt,total;
bool      cg = true;

int isMgNum(int magic)
{
 ordtotal = OrdersTotal();
for ( i = 0; i < ordtotal; i++)
   {
   cg = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   if ((OrderMagicNumber() == magic) && (OrderSymbol() == Symbol())) return(1);
   }
return(0);
}

//+------------------------------------------------------------------+

void OnTick()
{
tmp = (TimeCurrent()-OrderOpenTime())/36000.0;

if (MM)
   {
   if (LotsPercent > 0)
      Lots = NormalizeDouble(MathCeil(AccountFreeMargin() / 1000.0 * LotsPercent) / 10.0,1);
         else
      Lots = Lots;
   }
   
   if (Lots < MinLot) Lots = MinLot;
   if (Lots > MaxLot) Lots = MaxLot;

double IN;
double RSI_1   = iRSI(NULL, RSI_TF, RSI_PERIOD, PRICE_CLOSE, 0);
double RSI_2   = iRSI(NULL, RSI_TF, RSI_PERIOD, PRICE_CLOSE, 1);

Comment("Trading hours: ",Start," to ",End,"\n","Trading is disabled");
if ((Start < End) && ((TimeHour(TimeCurrent()) < Start ) || (TimeHour(TimeCurrent()) >= End))) return;
else
if ((Start > End) && ((TimeHour(TimeCurrent()) < Start ) && (TimeHour(TimeCurrent()) >= End))) return;
else
Comment("Trading hours: ",Start," to ",End,"\n","Trading is enabled");

IN = NormalizeDouble(AccountFreeMargin() / 2500,2);

if ((isMgNum(Magic) == 0) && (RSI_1 < RSI_BUY)&& (RSI_1< RSI_2))
   {
   if (Compra)
   cg = OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Ask - SL * Point, Ask + TP * Point,0,Magic,0,Blue);
   Compra = false;
   Venda = true;
  }
 
  if(MaxOpenTime_BUY>0)
  {
    for(cnt=0;cnt>OrdersTotal();cnt++)
    {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if (((NormalizeDouble(tmp,8)-MaxOpenTime_BUY)>=0))
        {     
          RefreshRates();
          if (OrderType()==OP_BUY)
            closeprice=Bid;
          if (OrderClose(OrderTicket(),OrderLots(),closeprice,10,Yellow))
          {
            Print("CloseLong(),OrderSelect():",OrderTicket());
            OrderPrint();
          }
          else 
            Print("Error close Long order :",GetLastError());        
        } 
      }
      else 
        Print("TimeOver",GetLastError());
    } 
    }
if ((isMgNum(Magic) == 0) && (RSI_1 > RSI_SELL)&& (RSI_1> RSI_2))
   {
   if (Venda)
   cg = OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Bid + SL * Point,Bid - TP * Point,0,Magic,0,Red);
   Venda = false;
   Compra = true;
   }
  
  if(MaxOpenTime_SELL>0)
  {
    for(cnt=0;cnt<OrdersTotal();cnt++)
    {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if (((NormalizeDouble(tmp,8)-MaxOpenTime_SELL)>=0))
        {     
          RefreshRates();
          if (OrderType()==OP_SELL)
            closeprice=Ask;          
          if (OrderClose(OrderTicket(),OrderLots(),closeprice,10,Yellow))
          {
            Print("CloseShort(),OrderSelect():",OrderTicket());
            OrderPrint();
          }
          else 
            Print("Error close Sell order :",GetLastError());        
        } 
      }
      else 
        Print("TimeOver",GetLastError());
    } 
  }     
   
if ( ( RSI_1 < RSI_SELL_Zera ) && ( RSI_1 > RSI_BUY_Zera ))
   {
   Venda = true;
   Compra = true;
}
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 根据RSI信号交易的EA King EA.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏