Navigation:Home > Content >

Awesome_Macd.mq4

Time: 2017-06-15 | Download file:Awesome_Macd.mq4

//+------------------------------------------------------------------+
//|                                                      Awesome.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+   // with slight modifications by .....h
#property  copyright "Copyright © 2005, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 5
#property  indicator_color1  Black
#property  indicator_color2  Aqua
#property  indicator_color3  Magenta

#property  indicator_color4  MidnightBlue
#property  indicator_color5  Red

extern double profit        =  100.0;

extern double alertabove    =    0.0;
extern double alertbelow    =    0.0; 
extern int    bars          =    100;
extern int    FastEMA       =     12;
extern int    SlowEMA       =     26;
extern int    SignalSMA     =      9;
extern int    zigzag        =      5;
//----     macd buffers
double     MacdBuffer[];
double     SignalBuffer[];

//----     ao buffers
double     ExtBuffer0[];
double     ExtBuffer1[];
double     ExtBuffer2[];
int        win,orderstotal;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,3);
   SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,3);
   IndicatorDigits(Digits+1);
   SetIndexDrawBegin(0,34);
   SetIndexDrawBegin(1,34);
   SetIndexDrawBegin(2,34);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);
   
   
   SetIndexStyle(3,DRAW_HISTOGRAM,EMPTY,2);
   SetIndexStyle(4,DRAW_LINE,EMPTY,2);
   SetIndexDrawBegin(1,SignalSMA);


   SetIndexBuffer(3,MacdBuffer);
   SetIndexBuffer(4,SignalBuffer);   
   
   
   
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("AO");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   
   win=WindowFind("AO");
   
   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int start()
  {
  
     //if(orderstotal != OrdersTotal()) {Alert("Orders changed");  orderstotal = OrdersTotal();}  //PlaySound("news");
     
  if(AccountProfit() > profit) {Alert("profit alert");}
  
  Comment(MarketInfo(Symbol(),MODE_SPREAD)*0.1);
   int    i,limit;
   int    counted_bars=IndicatorCounted();
   double prev,current;
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   //limit = bars;
//---- macd
   for(i=0; i=0; i--)
     {
      current=ExtBuffer0[i];
      prev=ExtBuffer0[i+1];
      if(current>prev) up=true;
      if(current daypivot) {askdaypivot = "above daily pivot";} else {askdaypivot = "below daily pivot";}
     
     string askweekpivot;
     double weekpivot = (iClose(NULL,10080,1) + iHigh(NULL,10080,1) + iLow(NULL,10080,1))/3;
     if(Ask > weekpivot) {askweekpivot = "above weekly pivot";} else {askweekpivot = "below weekly pivot";}
     
     
     
     
     string trade = "none";
     if(count("buys")  > 0) {trade = " buy ";}
     if(count("sells") > 0) {trade = " sell ";}
     
     Label("Profit",Hour()+" gmt,  "+DoubleToStr(count("orders"),0)+" "+trade+" orders,  "+ DoubleToStr(count("lots"),2)+"  lots,  "+DoubleToStr(count("profit"),2)+"  profit  ",10,10);     
     
      
     double dailyatr  = iHigh(NULL,1440,0)-iLow(NULL,1440,0);
     double weeklyatr = iHigh(NULL,10080,0)-iLow(NULL,10080,0);
     
     Label("atr","daily atr is "+ DoubleToStr(iATR(Symbol(),1440,50,1)/(Point*10),0)+"  ("+DoubleToStr(dailyatr/(Point*10),0)+")"+"  weekly atr is  "+DoubleToStr(iATR(Symbol(),10080,1,1)/(Point*10),0)+"  ("+DoubleToStr(weeklyatr/(Point*10),0)+")",10,30);

     string askstoch = "";
     double stoch = iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,0);
     if(iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,0) > 80.0) {askstoch = "1440 stoch up extreme, sells ok, no new buys";}
     if(iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,0) < 20.0) {askstoch = "1440 stoch dn extreme, buys ok, no new sells";}
     
     if((iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,0) < 80.0) && (iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,0) > 20.0) && (iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,0) > iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,1))) {askstoch = "1440 stoch rising";} 
     if((iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,0) < 80.0) && (iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,0) > 20.0) && (iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,0) < iStochastic(Symbol(),1440,12,3,5,MODE_SMA,0,MODE_MAIN,1))) {askstoch = "1440 stoch falling";} 

     Label("stoch",  askstoch+"  "+DoubleToStr(stoch,2),10,50);

     
      string dir;
     if(zigzag(4,1440) == 1) {dir = "last 1440 zigzag up, sells ok, no new buys";} else {dir = "last 1440 zigzag down, buys ok, no new sells";}
     Label("zigzag",dir,10,70);
    
     Label("zz","daily zz is "+ DoubleToStr(zigzag(1,1440),0)+"  ("+DoubleToStr(zigzag(2,1440),0)+")"+"  weekly zz is  "+DoubleToStr(zigzag(1,10080),0)+"  ("+DoubleToStr(zigzag(2,10080),0)+")",10,90);

     Label("pivot",askdaypivot+"  "+  askweekpivot,10,110);
 
 
 
     Label("freemargin","free margin  "+DoubleToStr(AccountFreeMargin(),2)+",  margin level  "+DoubleToStr(AccountEquity()/AccountMargin()*100,2),10,130);
     
     
     if(alertabove > 0.0 && Ask > alertabove) {Alert(Symbol() ,"  is above alert setting");}
     if(alertbelow > 0.0 && Ask < alertbelow) {Alert(Symbol() ,"  is below alert setting");}
     
     if(alertabove > 0.0) {DrawHorizontalLine("above", alertabove);}
     if(alertbelow > 0.0) {DrawHorizontalLine("below", alertbelow);}
     
     
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

   void DrawHorizontalLine(string name, double level)              //  DrawHorizontalLine("horizontal", Ask);
   {  
   ObjectDelete(name);
   ObjectCreate(name, OBJ_HLINE, 0, 0, level);
   ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(name, OBJPROP_WIDTH, 2);
   ObjectSet(name, OBJPROP_COLOR, Red);
   }
   



double zigzag(int val,int tf)
   {
   
   double correction;
   double zig;
   double zag[100]; 
   double value;  
   int    n=0;   
   int    i=0;
   bool   up;
   double point = MarketInfo(Symbol(),MODE_POINT);
   while(n<12)
   {

   if(zig>0)
   {
   zag[n] = zig;
       
   }
   zig=iCustom(Symbol(),tf,"ZigZag",5,5,3, 0, i);
   if(zig>0) n+=1;
   i++;
   } 

   double average = ((MathAbs((zag[1] - zag[2])) + MathAbs((zag[2] - zag[3]))) + MathAbs((zag[3] - zag[4])) + MathAbs((zag[4] - zag[5])) + MathAbs((zag[5] - zag[6])) + MathAbs((zag[6] - zag[7])) + MathAbs((zag[7] - zag[8])) + MathAbs((zag[8] - zag[9])) + MathAbs((zag[9] - zag[10])) + MathAbs((zag[10] - zag[11]))/ 10)/(100*point);

   if((zag[1] - zag[2]) > 0.0) {correction = NormalizeDouble((zag[1] - iClose(Symbol(),0,0))/(point)*0.1,0);}

   if((zag[1] - zag[2]) < 0.0) {correction = NormalizeDouble((iClose(Symbol(),0,0) - zag[1])/(point)*0.1,0);}
   
   if((zag[1] - zag[2]) > 0.0) {up = true;} else {up = false;}

   if(val == 1) value = NormalizeDouble(average,0);
   else
   if(val == 2) value = NormalizeDouble(MathAbs(zag[1] - zag[2])/(10*point),0);
   else
   if(val == 3) value = correction;
   else
   if(val == 4) value = up;
   else
   if(val == 5 && iCustom(Symbol(),tf,"ZigZag",5,5,3, 0, 0) != 0 && iCustom(Symbol(),tf,"ZigZag",5,5,3, 0, 1) > iCustom(Symbol(),tf,"ZigZag",5,5,3, 0, 2))    value = 1;   
   else
   if(val == 6 && iCustom(Symbol(),tf,"ZigZag",5,5,3, 0, 0) != 0 && iCustom(Symbol(),tf,"ZigZag",5,5,3, 0, 1) < iCustom(Symbol(),tf,"ZigZag",5,5,3, 0, 2))    value = 1;   
   else
   if(val == 7 && NormalizeDouble(MathAbs(zag[1] - zag[2])/(10*point),0) > NormalizeDouble(average,0) && (zag[1] - zag[2]) > 0.0)  value = 1;
   else
   if(val == 8 && NormalizeDouble(MathAbs(zag[1] - zag[2])/(10*point),0) > NormalizeDouble(average,0) && (zag[1] - zag[2]) < 0.0)  value = 1;
   
   return(value);
   }

//------
//------

double count(string data)
   {
   int    total = OrdersTotal();
   double profit1,lots;
   int cnt,buy,sell;
   for (int i=0;i OP_SELL)         continue;
   
   if(OrderSymbol() != Symbol())     continue;
   if(OrderType() == OP_BUY) buy++;
   if(OrderType() == OP_SELL) sell++;
      cnt++;
      lots      += OrderLots();
      profit1    = OrderProfit()+profit1;

   }            
	if(data == "profit") {return(profit1);}
	if(data == "lots")   {return(lots);}
	if(data == "orders") {return(cnt);}   
	if(data == "buys") {return(buy);}   
	if(data == "sells") {return(sell);}   
	
//	return(0);
	}
//----
//----	
	
void Label(string name,string message,int x,int y)
          {
          ObjectCreate(name, OBJ_LABEL, WindowFind("AO"), 0, 0);
          ObjectSetText(name, message, 8,"Comic Sans MS",Aqua);
          ObjectSet(name, OBJPROP_CORNER, 1);
          ObjectSet(name, OBJPROP_BACK,false);
          ObjectSet(name, OBJPROP_XDISTANCE, x);
          ObjectSet(name, OBJPROP_YDISTANCE, y);          
          }

Recommend