Navigation:Home > Content >

Great_hope_Smart.mq4

Time: 2016-08-04 | Download file:Great_hope_Smart.mq4

//+------------------------------------------------------------------+
//|                                                       Great hope |
//+------------------------------------------------------------------+
extern double lots=0.1;
extern int tp1=30;
extern int tp2=50;
extern int tp3=80;
extern int magic=384756;
int lasttime;
int Ticket;
double pp;
double low_fr, up_fr, sl;
//+------------------------------------------------------------------+
int init()
  { 
      if (Digits < 4) 
      {
      pp = 0.01;
      } else 
      {
      pp = 0.0001;
      }    
   return(0);
  }
int smart()
{
  int i=0; 
   while (iFractals(NULL, 0, MODE_UPPER, i)==0.0)
   {
   i++;
   }   
  up_fr=iFractals(NULL, 0, MODE_UPPER, i); 
  i=0; 
   while (iFractals(NULL, 0, MODE_LOWER, i)==0.0)
   {
   i++;
   }   
  low_fr=iFractals(NULL, 0, MODE_LOWER, i); 
  
  double MA_5=iMA(NULL,0,5,0,MODE_LWMA,PRICE_TYPICAL,0);//MA
  double MA_14=iMA(NULL,0,14,0,MODE_LWMA,PRICE_TYPICAL,0);
  double MA_=iMA(NULL,0,65,0,MODE_EMA,PRICE_CLOSE,0);
  double main0 =iMACD(NULL,0,5,14,5,PRICE_WEIGHTED,MODE_MAIN,0);//MACD
  double main1 =iMACD(NULL,0,5,14,5,PRICE_WEIGHTED,MODE_MAIN,1);
  double St_signal=iStochastic(NULL,0,12,12,5,MODE_EMA,1,MODE_SIGNAL,0); 
  
  if (Close[0]>MA_)
  {//buy
    if (main1<0 && main0>0 && MA_5>MA_14 && St_signal<80)
    {
    sl=MathAbs(low_fr-Close[0])*10000+20;
    OpenOrder(0,tp1,sl,magic);
    OpenOrder(0,tp2,sl,magic);
    OpenOrder(0,tp3,sl,magic);
    lasttime=Time[0];
    }    
  }else
  if (Close[0]0 && main0<0 && MA_520)
    {
    sl=MathAbs(up_fr-Close[0])*10000+20;
    OpenOrder(1,tp1,sl,magic);
    OpenOrder(1,tp2,sl,magic);
    OpenOrder(1,tp3,sl,magic);
    lasttime=Time[0];
    }   
  } 
  
  return(0);
}
//+------------------------------------------------------------------+
void OpenOrder(int type, int tp, int sl, int magic1) //открытие ордера в указанном направлении
{
  double sizelot=lots;
  string s=Symbol();
   Ticket=-1; 
   int n=3;  
  if (type==0)
  {
    while (Ticket<0 && n>0)
    {
     Ticket=OrderSend(s,OP_BUY,sizelot,NormalizeDouble(Ask,Digits),50,NormalizeDouble((Bid-sl*pp+2*pp),Digits),NormalizeDouble((Bid+tp*pp+2*pp),Digits),"buy :"+TimeToStr(TimeCurrent(),TIME_MINUTES),magic1,0,Blue);
     n--;
    } 
  }
  else
  {
    while (Ticket<0 && n>0)
    {   
     Ticket=OrderSend(s,OP_SELL,sizelot,NormalizeDouble(Bid,Digits),50,NormalizeDouble((Ask+sl*pp-2*pp),Digits),NormalizeDouble((Ask-tp*pp-2*pp),Digits),"sell :"+TimeToStr(TimeCurrent(),TIME_MINUTES),magic1,0,Red);
     n--;
    }  
  }
}

int OpenningTime()
{
  if (lasttime==Time[0]) return(0); 

  smart();
 
     // в сигнал запихать lasttime=Time[0]; 

  return(0);  
}
//+------------------------------------------------------------------+
int start()
  {
     OpenningTime();

   return(0);
  }
//+------------------------------------------------------------------+

Recommend