客服热线:18391752892

请教各位大师!

   日期:2019-01-12     浏览:357    
马上注册,结交更多好友,下载更多资源

您需要 登录 才可以下载或查看,没有帐号?注册 试着套用网上的源码编写了一个自定义指标,但是指标线并没有显示出来,望诸位大师赐教! 源码如下:
//+------------------------------------------------------------------+
//|                                             |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 FireBrick
double g_ibuf_144[];
double g_ibuf_148[];
extern int fastEMA = 12;
extern int slowEMA = 26;
extern int signal = 9;
extern double positiveSensitivity = 0.0001;
extern double negativeSensitivity = -0.0001;
double OsMA(int ai_0){
 double MacdMain,MacdSignal,OsMA;
 MacdMain= iMACD(NULL,0,fastEMA,slowEMA,signal,PRICE_CLOSE,MODE_MAIN,ai_0);
 MacdSignal= iMACD(NULL,0,fastEMA,slowEMA,signal,PRICE_CLOSE,MODE_SIGNAL,ai_0);
 OsMA=MacdMain-MacdSignal;
 return(OsMA);
}
int init() {
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexBuffer(0, g_ibuf_144);
   SetIndexBuffer(1, g_ibuf_148);
   SetIndexArrow(0, 233);
   SetIndexArrow(1, 234);
   IndicatorDigits(Digits + 2);
   return (0);
}
int start(){
 
    int firstPeakOrTroughShift = GetFirstPeakOrTrough(0);
    double firstPeakOrTroughOsMA = OsMA(firstPeakOrTroughShift);
   
    if(firstPeakOrTroughOsMA 0)
       {
       int peak_0   = GetIndicatorLastPeak(0);
       int trough_0 = GetIndicatorLastTrough(peak_0);
       int peak_1   = GetIndicatorLastPeak(trough_0);
       int trough_1 = GetIndicatorLastTrough(peak_1);
       }
      else
       {     
       trough_0 = GetIndicatorLastTrough(0);
       peak_0   = GetIndicatorLastPeak(trough_0);
       trough_1 = GetIndicatorLastTrough(peak_0);       
       peak_1   = GetIndicatorLastPeak(trough_1);               
       }
      //---- 
      if(peak_0 == -1 || peak_1 == -1 || trough_0 == -1 ||
        trough_1 == -1)
       return(0);
      //----       
      double indicatorLastPeak = OsMA(peak_0);
      double indicatorThePeakBefore = OsMA(peak_1);
      double indicatorLastTrough = OsMA(trough_0);
      double indicatorTheTroughBefore = OsMA(trough_1);
      int pricePeak_0 = peak_0;
      int pricePeak_1 = peak_1;
      int priceTrough_0 = trough_0;
      int priceTrough_1 = trough_1;
      //----
      double priceLastPeak = High[pricePeak_0];
      double priceThePeakBefore = High[pricePeak_1];
      double priceLastTrough = Low[priceTrough_0];
      double priceTheTroughBefore = Low[priceTrough_1];
     
      if(peak_0==2 priceLastPeak priceThePeakBefore indicatorLastPeak indicatorThePeakBefore ){
       
      g_ibuf_144[peak_0]=iOsMA(NULL, 0, fastEMA, slowEMA, signal, PRICE_CLOSE, peak_0);       
      return(-1);
      }     
      if(trough_0==2 priceLastTrough priceTheTroughBefore indicatorLastTrough indicatorTheTroughBefore )
      {     
      g_ibuf_148[trough_0]=iOsMA(NULL, 0, fastEMA, slowEMA, signal, PRICE_CLOSE, trough_0);
      return(1);
      }     
   return(0);
}
int GetFirstPeakOrTrough(int index)
 {
   for(int i = index + 1; i Bars; i++)
   {
      if((OsMA(i) = OsMA(i-1) OsMA(i) = OsMA(i+1)
        OsMA(i) = OsMA(i+2) OsMA(i) positiveSensitivity) ||
        (OsMA(i) = OsMA(i-1) OsMA(i) = OsMA(i+1)
        OsMA(i) = OsMA(i+2) OsMA(i) negativeSensitivity))
       return(i);
   }
   return(-1);
 }
//+------------------------------------------------------------------+
//|                                             |
//+------------------------------------------------------------------+
int GetIndicatorLastPeak(int index){//查找最高点的位置
   int regionStart = GetPositiveRegionStart(index);
   if(regionStart == -1)
      return(-1);
//----   
   int peakShift = 0;
   double peakValue = 0;
//----
   for(int i = regionStart; i Bars; i++)
   {
      if(OsMA(i) peakValue OsMA(i) = OsMA(i-1)
        OsMA(i) = OsMA(i+1) OsMA(i) = OsMA(i+2)
        OsMA(i) positiveSensitivity)
       {
       peakValue = OsMA(i);
       peakShift = i;
       }
      if(OsMA(i) 0)
       break; 
   }
   return(peakShift);
}
 
//+------------------------------------------------------------------+
//|                                             |
//+------------------------------------------------------------------+
int GetIndicatorLastTrough(int index){//查找之前最低点的位置
   int regionStart = GetNegativeRegionStart(index);
   if(regionStart == -1)
      return(-1);
//----       
   int troughShift = 0;
   double troughValue = 0;
//----   
   for(int i = regionStart; i Bars; i++)
   {
      if(OsMA(i) troughValue OsMA(i) = OsMA(i-1)
        OsMA(i) = OsMA(i+1) OsMA(i) = OsMA(i+2)
        OsMA(i) negativeSensitivity)
       {
       troughValue = OsMA(i);
       troughShift = i;
       }   
      if(OsMA(i) 0)
       break; 
   } 
   return(troughShift);
 }
//+------------------------------------------------------------------+
//|                                             |
//+------------------------------------------------------------------+
int GetPositiveRegionStart(int index)//计算上一次高点的位置。
 {
   int regionStart;
   for(int i = index + 1; i Bars; i++)
   {
      if(OsMA(i) = OsMA(i-1) OsMA(i) = OsMA(i+1)
        OsMA(i) = OsMA(i+2) OsMA(i) positiveSensitivity)
       return(i);   
   }
   return(-1);
}
int GetNegativeRegionStart(int index){//计算上一次地点的位置
   for(int i = index + 1; i Bars; i++)
   {
      if(OsMA(i) = OsMA(i-1) OsMA(i) = OsMA(i+1)
        OsMA(i) = OsMA(i+2) OsMA(i) negativeSensitivity)
       return(i);   
   }
   return(-1);
}

外汇交易有很大的风险性,本站所有资源均来自网络,请选择使用,如若出现亏损,本站不承担任何责任!


特别提示:本信息由相关企业自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


0相关评论
相关行情快递
推荐行情快递
点击排行