8评论

0收藏

OsMA_ColorHist_Alert

avatar 360 | 1240 人阅读 | 8 人评论 | 2018-03-08

EURGBPH1.png

  1. //+------------------------------------------------------------------+
  2. //|                                                         OsMA.mq4 |
  3. //|                      Copyright ?2004, MetaQuotes Software Corp. |
  4. //|                                       http://www.metaquotes.net/ |
  5. //|                                    Copyright ?2006, Robert Hill |
  6. //|                                    Copyright ?2008, Linuxser    |
  7. //+------------------------------------------------------------------+
  8. #property  copyright "Copyright ?2006, Robert Hill"
  9. #property  copyright "Copyright ?2008, Linuxser and Forex-TSD"
  10. #property  link      "http://www.metaquotes.net/"
  11. //---- indicator settings
  12. #property  indicator_separate_window
  13. #property  indicator_buffers 2
  14. #property  indicator_color1  DarkSeaGreen
  15. #property  indicator_color2  Tomato

  16. //---- indicator parameters
  17. extern bool SoundON=true;
  18. extern bool EmailON=false;
  19. extern bool HistogramAlarm=false;
  20. extern bool ZeroLineAlarm=false;
  21. extern int FastEMA=12;
  22. extern int SlowEMA=26;
  23. extern int SignalSMA=9;

  24. //---- indicator buffers
  25. double     OsmaBuffer[];
  26. double     MacdBuffer[];
  27. double     SignalBuffer[];
  28. double HistogramBufferUp[];
  29. double HistogramBufferDown[];
  30. bool HistAboveZero = false;
  31. bool HistBelowZero = false;
  32. bool MACDAboveZero = false;
  33. bool MACDBelowZero = false;

  34. //+------------------------------------------------------------------+
  35. //| Custom indicator initialization function                         |
  36. //+------------------------------------------------------------------+
  37. int init()
  38.   {
  39. //---- 2 additional buffers are used for counting.
  40.    IndicatorBuffers(5);
  41. //---- drawing settings
  42.    SetIndexDrawBegin(0,SignalSMA);
  43.    SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
  44.    SetIndexBuffer(0,HistogramBufferUp);
  45.    SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
  46.    SetIndexBuffer(1,HistogramBufferDown);
  47.    IndicatorDigits(Digits+2);
  48. //---- 3 indicator buffers mapping
  49.    SetIndexBuffer(2,OsmaBuffer);
  50.    SetIndexBuffer(3,MacdBuffer);
  51.    SetIndexBuffer(4,SignalBuffer);
  52.    SetIndexBuffer(0,HistogramBufferUp);
  53.    SetIndexBuffer(1,HistogramBufferDown);
  54.    
  55. //---- name for DataWindow and indicator subwindow label
  56.    IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
  57. //---- initialization done
  58.    return(0);
  59.   }
  60. //+------------------------------------------------------------------+
  61. //| Moving Average of Oscillator                                     |
  62. //+------------------------------------------------------------------+
  63. int start()
  64.   {

  65.    double current, prev;
  66.    int limit;
  67.    int counted_bars=IndicatorCounted();
  68. //---- last counted bar will be recounted
  69.    if(counted_bars>0) counted_bars--;
  70.    limit=Bars-counted_bars;
  71. //---- macd counted in the 1-st additional buffer
  72.    for(int i=0; i<limit; i++)
  73.       MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
  74. //---- signal line counted in the 2-nd additional buffer
  75.    for(i=0; i<limit; i++)
  76.       SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
  77. //---- main loop
  78.    for(i=0; i<limit; i++)
  79.       OsmaBuffer[i]=MacdBuffer[i]-SignalBuffer[i];

  80.    for(i=0; i<limit; i++)
  81.    {
  82.       HistogramBufferUp[i] = 0;
  83.       HistogramBufferDown[i] = 0;
  84.       current = MacdBuffer[i] - SignalBuffer[i];
  85.       prev = MacdBuffer[i+1] - SignalBuffer[i+1];
  86.       if (current > prev)
  87.       {
  88.         HistogramBufferUp[i] = current;
  89.         HistogramBufferDown[i] = 0.0;
  90.       }
  91.       else
  92.       {
  93.         HistogramBufferDown[i] = current;
  94.         HistogramBufferUp[i] = 0.0;
  95.       }
  96.       
  97.       if (MACDAboveZero) Comment ("\nThe trend has changed to UP");
  98.       if (MACDBelowZero) Comment ("\nThe trend has changed to DOWN");
  99.       
  100.       if (i == 1)
  101.       {
  102. // Check for Histogram Change Color
  103.         if  (HistogramAlarm==true)
  104.         {
  105.         if (HistogramBufferUp[i] > HistogramBufferDown[i + 1])
  106.         {
  107. // Cross up
  108.          if (HistAboveZero == false)
  109.          {
  110.            HistAboveZero=true;
  111.            HistBelowZero=false;
  112.            if (SoundON) Alert("OSMA is Positive","\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
  113.            if (EmailON) SendMail("OSMA is Positive", "MACD Crossed up, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
  114.          }
  115.         }
  116.         else if (HistogramBufferDown[i] <  HistogramBufferUp[i + 1] > 0)
  117.         {
  118. // Cross down
  119.          if (HistBelowZero == false)
  120.          {
  121.           HistBelowZero=true;
  122.           HistAboveZero=false;
  123.           if (SoundON) Alert("OSMA is Negative","\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
  124.           if (EmailON) SendMail("OSMA is Negative","MACD Crossed Down, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
  125.          }
  126.         }
  127.         }
  128. // Check for MACD Signal line crossing 0 line
  129.         if (ZeroLineAlarm==true)
  130.         {
  131.         if (OsmaBuffer[i] > 0 && OsmaBuffer[i + 1] < 0)
  132.         {
  133. // Cross up
  134.          if (MACDAboveZero == false)
  135.          {
  136.            MACDAboveZero=true;
  137.            MACDBelowZero=false;
  138.            if (SoundON) Alert("Histogram is Above Zero Line","\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
  139.            if (EmailON) SendMail("Histogram is Above Zero Line", "OSMA Crossed up, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
  140.          }
  141.         }
  142.         else if (OsmaBuffer[i] < 0 && OsmaBuffer[i + 1] > 0)
  143.         {
  144. // Cross down
  145.          if (MACDBelowZero == false)
  146.          {
  147.           MACDBelowZero=true;
  148.           MACDAboveZero=false;
  149.           if (SoundON) Alert("Histogram is Below Zero Line","\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
  150.           if (EmailON) SendMail("Histogram is Below Zero Line","OSMA Crossed Down, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
  151.          }
  152.         }
  153.       }
  154.     }  
  155.    }
  156.       
  157. //---- done
  158.    return(0);
  159.   }
复制代码


OsMA_ColorHist_AlertNew.mq4
""
还没有人打赏,支持一下

评论|共 8 个

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 | 显示全部楼层

sunzhefu

发表于 2021-7-26 15:27:49 | 显示全部楼层

谢谢

趋势

发表于 2021-8-6 17:10:30 | 显示全部楼层

80738295

发表于 2021-8-8 21:31:29 | 显示全部楼层

支持下

您需要登录后才可以回帖 登录 | 注册 微信登录

EA之家评论守则