诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

另类OsMA EMAAngle.mq4

EMAAngle 指标在副图创建类似于OsMA的柱状线。

图表:EMAAngle 指标

源码:

//+------------------------------------------------------------------+
//|                                                     EMAAngle.mq4 |
//|                                                           jpkfox |
//+------------------------------------------------------------------+
#property  copyright "jpkfox"
#property link      "http://www.125808047.com"

#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  FireBrick
#property  indicator_color2  LimeGreen
#property  indicator_level1  0

extern int EMAPeriod=120;
extern double AngleTreshold=0.32;
extern int StartEMAShift=6;
extern int EndEMAShift=0;

double UpBuffer[];
double DownBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
   if(!SetIndexBuffer(0,UpBuffer) &&
      !SetIndexBuffer(1,DownBuffer))
      Print("cannot set indicator buffers!");
   IndicatorShortName("EMAAngle("+EMAPeriod+","+AngleTreshold+","+StartEMAShift+","+EndEMAShift+")");
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| The angle for EMA                                                |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   double fEndMA, fStartMA;
   double fAngle;
   int nLimit, i;
   int nCountedBars;
   if(EndEMAShift >= StartEMAShift)
   {
      Print("Error: EndEMAShift >= StartEMAShift");
      StartEMAShift = 6;
      EndEMAShift = 0;      
   }  
   nCountedBars = IndicatorCounted();
   if(nCountedBars<0) 
      return(-1);
   if(nCountedBars>0) 
      nCountedBars--;
   nLimit = Bars-nCountedBars;

   for(i=0; i<nLimit; i++)
   {
      fEndMA=iMA(NULL,0,EMAPeriod,0,MODE_EMA,PRICE_MEDIAN,i+EndEMAShift);
      fStartMA=iMA(NULL,0,EMAPeriod,0,MODE_EMA,PRICE_MEDIAN,i+StartEMAShift);
      fAngle = 10000.0 * (fEndMA - fStartMA)/(StartEMAShift-EndEMAShift);

      DownBuffer[i] = 0.0;
      UpBuffer[i] = 0.0;
      
      if(fAngle > AngleTreshold || fAngle < -AngleTreshold)
         DownBuffer[i] = fAngle;
      else
         UpBuffer[i] = fAngle;
   }
   return(rates_total);
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » 另类OsMA EMAAngle.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏