自动交易EA renko badawi v3.mq4-MT4 EA-峰汇在线
诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4 EA > 正文

自动交易EA renko badawi v3.mq4

renko badawi v3 EA 是比较K线连续阴阳来自动开仓交易。

源码:

//+------------------------------------------------------------------+
//|                                              renko badawi v3.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property  link      "http://www.125808047.com/" 

extern string begin_Time = "00:00";
extern string end_Time = "4:00";
extern bool usetime=false;

extern int StopLoss=10;
extern int TakeProfit=10;
extern int MagicNumber=2365;
extern int  MaxTrades = 1;           
extern double  Lots = 1; 

extern int win_USD=20;
extern bool winUSD=false;

extern int win_pips=20;
extern bool winpips=false;

extern int TrailingStop=0;
extern int TrailingStep=0;

extern bool  UseMoneyManagement = false;                                                
extern int  RiskPercent = 10;  

extern string  MM = "Choose your style of trading";
extern string  OO = "Choose 1 TO USE 1 candle";
extern string  NN = "Choose 2 TO USE 2 candles";
extern string  No = "Choose 3 TO USE 3 candles";

extern int N_candles=3;
extern bool Reverse_signal=false;
extern bool active_sell_buy=true;

bool buy=true;
bool sell=true;
bool trade=true;
int digits,Q;
double point;
datetime bt,nt;
datetime t;
int day,dayc;
bool cg=false;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
   int OnInit()
     {
    if(Digits==5||Digits==3)Q=10;
  else Q=1;
    if(Digits==2)
   {
      point=0.01;
      digits=2;
   }
   if(Digits==4)
   {
      point=0.0001;
      digits=4;
   }
   if(Digits==3)
   {
      point=0.01;
      digits=3;
   }
   if(Digits==5)
   {
      point=0.0001;
      digits=5;
   }
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void OnTick()
  {
     double open3=iOpen(0,0,3);
     double open2=iOpen(0,0,2);
     double open1=iOpen(0,0,1);
     double close3=iClose(0,0,3);
     double close2=iClose(0,0,2);
     double close1=iClose(0,0,1);

      bt = StrToTime(TimeToStr(Time[0], TIME_DATE) + " " + begin_Time);
      nt = StrToTime(TimeToStr(Time[0], TIME_DATE) + " " + end_Time);
      
      t=Time[1];
      day=TimeDay(t);
      dayc=TimeDay(TimeCurrent());
      
      if(TrailingStop>0)MoveTrailingStop();
      
      if(pofet()>=win_USD&&winUSD==true){
    closeordar(OP_BUY);closeordar(OP_SELL); }
    
    if(ProfitPipssell(point)+ProfitPipsbuy(point)>=win_pips&&winpips==true){
    closeordar(OP_BUY);closeordar(OP_SELL); }
    
    if(UseMoneyManagement)Lots=LotManage();
      
      if(usetime==true)
      {
      if(day==dayc&&Time[0]>=bt&&Time[0]<=nt)
      {
      trade=true;
      }
      else
      {
      trade=false;
      }}
      
      if(N_candles<1||N_candles>3)
      {
      N_candles=2;
      }
      if(active_sell_buy==false)
      {

     if(orderstotal()<MaxTrades&&close2>open2&&close1>open1&&trade==true&&N_candles==2)
     {
     open(OP_BUY,Lots,Ask,TakeProfit,StopLoss) ;
     }
     if(Reverse_signal==true&&close2>open2&&close1>open1&&N_candles==2)
     {
     CloseSellOrders();
     }
     if(orderstotal()<MaxTrades&&close2<open2&&close1<open1&&trade==true&&N_candles==2)
     {
     open(OP_SELL,Lots,Bid,TakeProfit,StopLoss) ;
     }
     if(Reverse_signal==true&&close2<open2&&close1<open1&&N_candles==2)
     {
     CloseBuyOrders();
     }

     if(orderstotal()<MaxTrades&&close1>open1&&trade==true&&N_candles==1)
     {
     open(OP_BUY,Lots,Ask,TakeProfit,StopLoss) ;
     }
     if(Reverse_signal==true&&close1>open1&&N_candles==1)
     {
     CloseSellOrders();
     }
     if(orderstotal()<MaxTrades&&close1<open1&&trade==true&&N_candles==1)
     {
     open(OP_SELL,Lots,Bid,TakeProfit,StopLoss) ;
     }
     if(Reverse_signal==true&&close1<open1&&N_candles==1)
     {
     CloseBuyOrders();
     }

     if(orderstotal()<MaxTrades&&close3>open3&&close2>open2&&close1>open1&&trade==true&&N_candles==3)
     {
     open(OP_BUY,Lots,Ask,TakeProfit,StopLoss) ;
     }
     if(Reverse_signal==true&&close3>open3&&close2>open2&&close1>open1&&N_candles==3)
     {
     CloseSellOrders();
     }
     if(orderstotal()<MaxTrades&&close3<open3&&close2<open2&&close1<open1&&trade==true&&N_candles==3)
     {
     open(OP_SELL,Lots,Bid,TakeProfit,StopLoss) ;
     }
     if(Reverse_signal==true&&close3<open3&&close2<open2&&close1<open1&&N_candles==3)
     {
     CloseBuyOrders();
     }
     }
     
     if(active_sell_buy==true)
     {
     if(orderstotal()<MaxTrades&&close2>open2&&close1>open1&&trade==true&&N_candles==2&&buy==true)
     {
     open(OP_BUY,Lots,Ask,TakeProfit,StopLoss) ;
     buy=false;
     sell=true;
     }
     if(Reverse_signal==true&&close2>open2&&close1>open1&&N_candles==2)
     {
     CloseSellOrders();
     }
     if(orderstotal()<MaxTrades&&close2<open2&&close1<open1&&trade==true&&N_candles==2&&sell==true)
     {
     open(OP_SELL,Lots,Bid,TakeProfit,StopLoss) ;
     buy=true;
     sell=false;
     }
     if(Reverse_signal==true&&close2<open2&&close1<open1&&N_candles==2)
     {
     CloseBuyOrders();
     }

     if(orderstotal()<MaxTrades&&close1>open1&&trade==true&&N_candles==1&&buy==true)
     {
     open(OP_BUY,Lots,Ask,TakeProfit,StopLoss) ;
     buy=false;
     sell=true;
     }
     if(Reverse_signal==true&&close1>open1&&N_candles==1)
     {
     CloseSellOrders();
     }
     if(orderstotal()<MaxTrades&&close1<open1&&trade==true&&N_candles==1&&sell==true)
     {
     open(OP_SELL,Lots,Bid,TakeProfit,StopLoss) ;
     buy=true;
     sell=false;
     }
     if(Reverse_signal==true&&close1<open1&&N_candles==1)
     {
     CloseBuyOrders();
     }

     if(orderstotal()<MaxTrades&&close3>open3&&close2>open2&&close1>open1&&trade==true&&N_candles==3&&buy==true)
     {
     open(OP_BUY,Lots,Ask,TakeProfit,StopLoss) ;
     buy=false;
     sell=true;
     }
     if(Reverse_signal==true&&close3>open3&&close2>open2&&close1>open1&&N_candles==3)
     {
     CloseSellOrders();
     }
     if(orderstotal()<MaxTrades&&close3<open3&&close2<open2&&close1<open1&&trade==true&&N_candles==3&&sell==true)
     {
     open(OP_SELL,Lots,Bid,TakeProfit,StopLoss) ;
     buy=true;
     sell=false;
     }
     if(Reverse_signal==true&&close3<open3&&close2<open2&&close1<open1&&N_candles==3)
     {
     CloseBuyOrders();
     }
     }
  }

int orderstotal(){
 int cnt=0;
   for(int i =0;i<OrdersTotal();i++){
     cg=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
       if(OrderSymbol()==Symbol() && MagicNumber==OrderMagicNumber()){
         cnt++;
       }
     }
    return(cnt);
  }
  
void closeordar(int typer){
 for(int c=0;c<OrdersTotal();c++){
 cg=OrderSelect(c,SELECT_BY_POS,MODE_TRADES);
 if(OrderType()== typer){
 if(OrderType()==OP_BUY)cg=OrderClose(OrderTicket(),OrderLots(),Bid,30);
 if(OrderType()==OP_SELL)cg=OrderClose(OrderTicket(),OrderLots(),Ask,30);
 RefreshRates();
    }
   }
  }

int DeletePendingOrders(int Magic)
{
int total = OrdersTotal();

for (int cnt=total ; cnt>=0 ;cnt--)
{
cg=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()!=OP_BUY && OrderType()!=OP_SELL))
  {
   cg=OrderDelete(OrderTicket());
  }
}
  return(0);
}

  double pofet()
  {
 double pr;
 for(int p=0;p<OrdersTotal();p++){
 cg=OrderSelect(p,SELECT_BY_POS,MODE_TRADES);
 
 pr=pr+OrderProfit();
 }
return(pr);
 }
 
int ProfitPipsbuy(double point_1) { 
   double valueb=0;
   for (int i=0; i<OrdersTotal(); i++) { 
   if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
   if((OrderSymbol()==Symbol()) && OrderMagicNumber() == MagicNumber) 
     {
       if(OrderType()==OP_BUY) valueb=(OrderClosePrice()-OrderOpenPrice())/point_1;

     }
  }  
   return(valueb); 
}
int ProfitPipssell(double point_1) { 
   double values=0;
   for (int i=0; i<OrdersTotal(); i++) { 
   if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
   if((OrderSymbol()==Symbol()) && OrderMagicNumber() == MagicNumber) 
     {
       if(OrderType()==OP_SELL) values=(OrderOpenPrice()-OrderClosePrice())/point_1;
     }
  }  
   return(values); 
}

int MyPendingOrdersTotal(int Magic)
{
int c=0;
int total = OrdersTotal();

for (int cnt=0 ; cnt < total ; cnt++)
{
cg=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && OrderType()>OP_SELL)
 {
 c++;
 }
}
return(c);
}

void MoveTrailingStop()
{
   for(int cnt=0;cnt<OrdersTotal();cnt++)
   {
      cg=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
      {
         if(OrderType()==OP_BUY)
         {
            if(TrailingStop>0&&NormalizeDouble(Ask-TrailingStep*point,digits)>NormalizeDouble(OrderOpenPrice()+TrailingStop*point,digits))  
            {                 
               if((NormalizeDouble(OrderStopLoss(),digits)<NormalizeDouble(Bid-TrailingStop*point,digits))||(OrderStopLoss()==0))
               {
                  cg=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailingStop*point,digits),OrderTakeProfit(),0,Blue);
                
               }
            }
         }
         else 
         {
            if(TrailingStop>0&&NormalizeDouble(Bid+TrailingStep*point,digits)<NormalizeDouble(OrderOpenPrice()-TrailingStop*point,digits))  
            {                 
               if((NormalizeDouble(OrderStopLoss(),digits)>(NormalizeDouble(Ask+TrailingStop*point,digits)))||(OrderStopLoss()==0))
               {
                  cg=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailingStop*point,digits),OrderTakeProfit(),0,Red);
                
               }
            }
         }
      }
   }
}

void CloseBuyOrders()
{
  for (int cnt = 0 ; cnt < OrdersTotal() ; cnt++)
  {
    cg=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == MagicNumber && OrderSymbol()==Symbol())
    {
      if (OrderType()==OP_BUY)
      {
        cg=OrderClose(OrderTicket(),OrderLots(),Bid,3);
      }
    }
  } 
 }  

void CloseSellOrders()
{
 for (int cnt = 0 ; cnt < OrdersTotal() ; cnt++)
  {
    cg=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    if (OrderMagicNumber() == MagicNumber && OrderSymbol()==Symbol())
    {
      if (OrderType()==OP_SELL)
      {
       cg=OrderClose(OrderTicket(),OrderLots(),Ask,3);
      }
     }
    }
   } 

  double LotManage()
  {
      double lot = MathCeil(AccountFreeMargin() *  RiskPercent / 1000) / 100; 
	  if(lot<MarketInfo(Symbol(),MODE_MINLOT))lot=MarketInfo(Symbol(),MODE_MINLOT);
	  if(lot>MarketInfo(Symbol(),MODE_MAXLOT))lot=MarketInfo(Symbol(),MODE_MAXLOT);
	   return (lot);
  }

  int open(int ty,double lot,double prc,int pof,int sll)
   {
     double sl=0,tp=0;
     color clr;
     bool modi;
     string T;double pr;
     if(ty==OP_BUY || ty==OP_BUYSTOP || ty==OP_BUYLIMIT)
        {
         if(sll>0){sl=prc-(sll*point);}else{sl=0;}
         if(pof>0){tp=prc+(pof*point);}else{tp=0;}
         clr=Green;
         T="Ask ";
         pr=NormalizeDouble(Ask,Digits);
        }
     if(ty==OP_SELL || ty==OP_SELLSTOP || ty==OP_SELLLIMIT)
       { 
         if(sll>0){sl=prc+(sll*point);}else{sl=0;}
         if(pof>0){tp=prc-(pof*point);}else{tp=0;}
         clr=Red;
         T="Bid";
         pr=NormalizeDouble(Bid,Digits);
       }     
         int tik=OrderSend(Symbol()
                ,ty
                ,lot
                ,NormalizeDouble(prc,Digits)
                ,10
                ,0
                ,0
                ,""
                ,MagicNumber
                ,0
                ,clr);
          string tx;
            if(ty==OP_BUY)tx="BUY";if(ty==OP_SELL)tx="SELL";if(ty==OP_BUYSTOP)tx="BUY STOP";if(ty==OP_SELLSTOP)tx="SELL STOP";if(ty==OP_BUYLIMIT)tx="BUY LIMIT";if(ty==OP_SELLLIMIT)tx="SELL LIMIT";
      if(tik>0)
         {
          if(tp>0 || sl>0)modi=OrderModify(tik,prc,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),0,CLR_NONE);   else modi=true;
          if(!modi){Print("Modify Err#= ",GetLastError(),"   ",Symbol()," ",Period(),"   Open Price= ",DoubleToStr(prc,Digits),"   SL= ",DoubleToStr(sl,Digits),"   Tp= ",DoubleToStr(tp,Digits));} 
           Print("Order Opened successfully   " ,"Type   ",tx,"  LotSize   ",lot,"  Price   ",DoubleToStr(prc,Digits),"  TP   ",DoubleToStr(tp,Digits),"  SL   ",DoubleToStr(sl,Digits));
         }
         else
           {
            Print("OrderSend failed with error #",GetLastError(), " Type ",tx,"   LotSize= ",lot,"   ",T,"Now= ",DoubleToStr(pr,Digits),"   Price= ",DoubleToStr(prc,Digits),"   TP= ",DoubleToStr(tp,Digits),"   SL= ",DoubleToStr(sl,Digits),"   Spread= ",MarketInfo(Symbol(),MODE_SPREAD));
           }
         return(tik);
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 自动交易EA renko badawi v3.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏