360 发表于 2018-3-8 14:58:11

OsMA_ColorHist_Alert



//+------------------------------------------------------------------+
//|                                                         OsMA.mq4 |
//|                      Copyright ?2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//|                                    Copyright ?2006, Robert Hill |
//|                                    Copyright ?2008, Linuxser    |
//+------------------------------------------------------------------+
#propertycopyright "Copyright ?2006, Robert Hill"
#propertycopyright "Copyright ?2008, Linuxser and Forex-TSD"
#propertylink      "http://www.metaquotes.net/"
//---- indicator settings
#propertyindicator_separate_window
#propertyindicator_buffers 2
#propertyindicator_color1DarkSeaGreen
#propertyindicator_color2Tomato

//---- indicator parameters
extern bool SoundON=true;
extern bool EmailON=false;
extern bool HistogramAlarm=false;
extern bool ZeroLineAlarm=false;
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;

//---- indicator buffers
double   OsmaBuffer[];
double   MacdBuffer[];
double   SignalBuffer[];
double HistogramBufferUp[];
double HistogramBufferDown[];
bool HistAboveZero = false;
bool HistBelowZero = false;
bool MACDAboveZero = false;
bool MACDBelowZero = false;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(5);
//---- drawing settings
   SetIndexDrawBegin(0,SignalSMA);
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(0,HistogramBufferUp);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(1,HistogramBufferDown);
   IndicatorDigits(Digits+2);
//---- 3 indicator buffers mapping
   SetIndexBuffer(2,OsmaBuffer);
   SetIndexBuffer(3,MacdBuffer);
   SetIndexBuffer(4,SignalBuffer);
   SetIndexBuffer(0,HistogramBufferUp);
   SetIndexBuffer(1,HistogramBufferDown);
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//---- initialization done
   return(0);
}
//+------------------------------------------------------------------+
//| Moving Average of Oscillator                                     |
//+------------------------------------------------------------------+
int start()
{

   double current, prev;
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer
   for(int i=0; i<limit; i++)
      MacdBuffer=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd additional buffer
   for(i=0; i<limit; i++)
      SignalBuffer=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- main loop
   for(i=0; i<limit; i++)
      OsmaBuffer=MacdBuffer-SignalBuffer;

   for(i=0; i<limit; i++)
   {
      HistogramBufferUp = 0;
      HistogramBufferDown = 0;
      current = MacdBuffer - SignalBuffer;
      prev = MacdBuffer - SignalBuffer;
      if (current > prev)
      {
      HistogramBufferUp = current;
      HistogramBufferDown = 0.0;
      }
      else
      {
      HistogramBufferDown = current;
      HistogramBufferUp = 0.0;
      }
      
      if (MACDAboveZero) Comment ("\nThe trend has changed to UP");
      if (MACDBelowZero) Comment ("\nThe trend has changed to DOWN");
      
      if (i == 1)
      {
// Check for Histogram Change Color
      if(HistogramAlarm==true)
      {
      if (HistogramBufferUp > HistogramBufferDown)
      {
// Cross up
         if (HistAboveZero == false)
         {
         HistAboveZero=true;
         HistBelowZero=false;
         if (SoundON) Alert("OSMA is Positive","\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
         if (EmailON) SendMail("OSMA is Positive", "MACD Crossed up, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
      }
      else if (HistogramBufferDown <HistogramBufferUp > 0)
      {
// Cross down
         if (HistBelowZero == false)
         {
          HistBelowZero=true;
          HistAboveZero=false;
          if (SoundON) Alert("OSMA is Negative","\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
          if (EmailON) SendMail("OSMA is Negative","MACD Crossed Down, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
      }
      }
// Check for MACD Signal line crossing 0 line
      if (ZeroLineAlarm==true)
      {
      if (OsmaBuffer > 0 && OsmaBuffer < 0)
      {
// Cross up
         if (MACDAboveZero == false)
         {
         MACDAboveZero=true;
         MACDBelowZero=false;
         if (SoundON) Alert("Histogram is Above Zero Line","\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
         if (EmailON) SendMail("Histogram is Above Zero Line", "OSMA Crossed up, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
      }
      else if (OsmaBuffer < 0 && OsmaBuffer > 0)
      {
// Cross down
         if (MACDBelowZero == false)
         {
          MACDBelowZero=true;
          MACDAboveZero=false;
          if (SoundON) Alert("Histogram is Below Zero Line","\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
          if (EmailON) SendMail("Histogram is Below Zero Line","OSMA Crossed Down, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
      }
      }
    }
   }
      
//---- done
   return(0);
}


zruLsWqE 发表于 2018-9-6 11:15:42

我是来刷分的,嘿嘿

范文芳 发表于 2020-7-31 15:10:56

谢谢楼主分享

ipwzlbw772 发表于 2020-8-27 13:05:54

学习了,不错

{大号还好} 发表于 2020-9-8 18:39:09

谢谢楼主分享

bkeoyvwv 发表于 2021-7-19 10:36:48

{:1_186:}

sunzhefu 发表于 2021-7-26 15:27:49

谢谢

趋势 发表于 2021-8-6 17:10:30

{:1_179:}

80738295 发表于 2021-8-8 21:31:29

支持下
页: [1]
查看完整版本: OsMA_ColorHist_Alert