Navigation´╝ÜHome > Content >

Super_Signals_EA_(2).mq4

Time: 2015-12-05 | Download file:Super_Signals_EA_(2).mq4

//+------------------------------------------------------------------+
//|                                                                  |
//|        Super Signals EA.mq4 - Ver 1.0 @ 02/09/2007 by Bluto      |
//|                                                                  |
//+------------------------------------------------------------------+


#property copyright "Bluto"
#property link      "None"

extern double Lots=1;
extern int    Slippage=3;
extern double StopLoss=20;
extern double TakeProfit=500;

int           MagicNumber=0;
int           ticket;
int           BuyOrders=0;
int           SellOrders=0;
int           i;

double        RSX_0=0, RSX_1=0;
double        SS_SELL_0=0, SS_SELL_1=0, SS_BUY_0=0, SS_BUY_1=0;
double        LOWERBAND_0=0, LOWERBAND_1=0, UPPERBAND_0=0, UPPERBAND_1=0;

bool          SSIsBuy=false, SSIsSell=false;


int init()
{
   if (Symbol()=="AUDCADm" || Symbol()=="AUDCAD") {MagicNumber=200001;}
   if (Symbol()=="AUDJPYm" || Symbol()=="AUDJPY") {MagicNumber=200002;}
   if (Symbol()=="AUDNZDm" || Symbol()=="AUDNZD") {MagicNumber=200003;}
   if (Symbol()=="AUDUSDm" || Symbol()=="AUDUSD") {MagicNumber=200004;}
   if (Symbol()=="CHFJPYm" || Symbol()=="CHFJPY") {MagicNumber=200005;}
   if (Symbol()=="EURAUDm" || Symbol()=="EURAUD") {MagicNumber=200006;}
   if (Symbol()=="EURCADm" || Symbol()=="EURCAD") {MagicNumber=200007;}
   if (Symbol()=="EURCHFm" || Symbol()=="EURCHF") {MagicNumber=200008;}
   if (Symbol()=="EURGBPm" || Symbol()=="EURGBP") {MagicNumber=200009;}
   if (Symbol()=="EURJPYm" || Symbol()=="EURJPY") {MagicNumber=200010;}
   if (Symbol()=="EURUSDm" || Symbol()=="EURUSD") {MagicNumber=200011;}
   if (Symbol()=="GBPCHFm" || Symbol()=="GBPCHF") {MagicNumber=200012;}   
   if (Symbol()=="GBPJPYm" || Symbol()=="GBPJPY") {MagicNumber=200013;}
   if (Symbol()=="GBPUSDm" || Symbol()=="GBPUSD") {MagicNumber=200014;}
   if (Symbol()=="NZDJPYm" || Symbol()=="NZDJPY") {MagicNumber=200015;}
   if (Symbol()=="NZDUSDm" || Symbol()=="NZDUSD") {MagicNumber=200016;}
   if (Symbol()=="USDCHFm" || Symbol()=="USDCHF") {MagicNumber=200017;}
   if (Symbol()=="USDJPYm" || Symbol()=="USDJPY") {MagicNumber=200018;}
   if (Symbol()=="USDCADm" || Symbol()=="USDCAD") {MagicNumber=200019;}
   if (MagicNumber==0) {MagicNumber = 200999;}  
 
 return(0);
}

int deinit()
{
 return(0);
}

int start()
{ 
 
  RSX_0 = iCustom(Symbol(),0,"Turbo_JRSX",14,0,0);
  RSX_1 = iCustom(Symbol(),0,"Turbo_JRSX",14,0,1);
  
  LOWERBAND_0 = iBands(NULL,0,20,2,0,PRICE_TYPICAL,MODE_LOWER,0);
  LOWERBAND_1 = iBands(NULL,0,20,2,0,PRICE_TYPICAL,MODE_LOWER,1);
  UPPERBAND_0 = iBands(NULL,0,20,2,0,PRICE_TYPICAL,MODE_UPPER,0);
  UPPERBAND_1 = iBands(NULL,0,20,2,0,PRICE_TYPICAL,MODE_UPPER,1);
  
  SS_SELL_0 = iCustom(Symbol(),Period(),"super-signals_v2b",4,0,0);
  SS_SELL_1 = iCustom(Symbol(),Period(),"super-signals_v2b",4,0,1);
  SS_BUY_0 = iCustom(Symbol(),Period(),"super-signals_v2b",4,1,0);
  SS_BUY_1 = iCustom(Symbol(),Period(),"super-signals_v2b",4,1,1);
  
  if ((SS_SELL_0 > 0 || SS_SELL_1 > 0) && (RSX_0 > 70 || RSX_1 > 70) && (High[0] > UPPERBAND_0 || High[1] > UPPERBAND_1)) {SSIsSell=true;SSIsBuy=false;}
  if ((SS_BUY_0 > 0 || SS_BUY_1 > 0) && (RSX_0 < 30 || RSX_1 < 30) && (Low[0] < LOWERBAND_0 || Low[1] < LOWERBAND_1)) {SSIsSell=false;SSIsBuy=true;}
  
  
  BuyOrders=0;
  SellOrders=0; 
  
  for(i=OrdersTotal();i >= 0;i--) 
   {
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) 
     {
      if (OrderType() == OP_BUY && StopLoss > 0)
       {
        BuyOrders++;
        if (StopLoss > 0 && Bid - (StopLoss * Point) > OrderStopLoss())
         {
          OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid - (StopLoss * Point),Digits),OrderTakeProfit(),0);
         }
       }   
      if (OrderType() == OP_SELL)
       {
        SellOrders++;
        if (StopLoss > 0 && Ask + (StopLoss * Point) < OrderStopLoss())
         {
          OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask + (StopLoss * Point),Digits),OrderTakeProfit(),0);
         }
       }  
     }
   } 
    
   
  if (SSIsBuy==true) 
   {
    if(SellOrders > 0)
     {
      CloseShorts(MagicNumber);
      SellOrders = 0; 
     }
    if(BuyOrders == 0)
     {    
      ticket = OpenPendingOrder(OP_BUY,Lots,Ask,Slippage,Bid,StopLoss,TakeProfit,"Super Signals EA",MagicNumber,0,Lime);
      if(ticket<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }
      else
       {
        BuyOrders++;
       }    
     }
   }
   
  if (SSIsSell==true) 
   {
    if(BuyOrders > 0)
     {
      CloseLongs(MagicNumber);
      BuyOrders = 0;
     }  
    if (SellOrders == 0) 
     { 
      ticket = OpenPendingOrder(OP_SELL,Lots,Bid,Slippage,Ask,StopLoss,TakeProfit,"Super Signals EA",MagicNumber,0,HotPink);
      if(ticket<0)
       {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
       }
      else
       {
        SellOrders++;
       }    
     }
   }
   
  return(0);
}

//----- Order Processing Functions

void CloseLongs(int MagicNumber)
{
 int trade;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==false)
   continue;

  if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
   continue;
   
  if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
  if(OrderType()==OP_BUY)
   OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);
 }//for
}

void CloseShorts(int MagicNumber)
{
 int trade;
 for(trade=OrdersTotal()-1;trade>=0;trade--)
 {
  if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==false)
   continue;

  if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
   continue;
   
  if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
  if(OrderType()==OP_SELL)
   OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);
 }//for
}

int OpenPendingOrder(int pType,double pLots,double pLevel,int sp, double pr, int sl, int tp,string pComment,int pMagic,datetime pExpiration,color pColor)
{
  int ticket=0;
  int err=0;
  int c = 0;
  int NumberOfTries = 10;
  switch (pType)
  {
      case OP_BUY:
         for(c = 0 ; c < NumberOfTries ; c++)
         {  
            RefreshRates();
            ticket=OrderSend(Symbol(),OP_BUY,pLots,Ask,sp,StopLong(Bid,sl),TakeLong(Bid,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  Print("Error Code= ", err);
                  break;
               }  
            }
         } 
         break;
      case OP_SELL:
         for(c = 0 ; c < NumberOfTries ; c++)
         {
            RefreshRates();
            ticket=OrderSend(Symbol(),OP_SELL,pLots,Bid,sp,StopShort(Ask,sl),TakeShort(Ask,tp),pComment,pMagic,pExpiration,pColor);
            if (ticket > 0) break;
            err=GetLastError();
            if(err==0)
            { 
               break;
            }
            else
            {
               if(err==4 || err==137 ||err==146 || err==136) //Busy errors
               {
                  Sleep(5000);
                  continue;
               }
               else //normal error
               {
                  Print("Error Code= ", err);
                  break;
               }  
            }
         } 
         break;
  } 
  
  return(ticket);
}  

double StopLong(double price,int stop)
{
 if(stop==0)
  return(0);
 else
  return(price-(stop*Point));
}

double StopShort(double price,int stop)
{
 if(stop==0)
  return(0);
 else
  return(price+(stop*Point));
}

double TakeLong(double price,int take)
{
 if(take==0)
  return(0);
 else
  return(price+(take*Point));
}

double TakeShort(double price,int take)
{
 if(take==0)
  return(0);
 else
  return(price-(take*Point));
}



Recommend