找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 16|回复: 0

费雪变换_MT5(懂C++的进)

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-23 02:18:00 | 显示全部楼层 |阅读模式
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots   5

#property indicator_label1  "ift OB/OS zone"
#property indicator_type1   DRAW_FILLING
#property indicator_color1  C'209,243,209',C'255,230,183'
#property indicator_label2  "ift up level"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrLimeGreen
#property indicator_style2  STYLE_DOT
#property indicator_label3  "ift middle level"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrSilver
#property indicator_style3  STYLE_DOT
#property indicator_label4  "ift down level"
#property indicator_type4   DRAW_LINE
#property indicator_color4  clrOrange
#property indicator_style4  STYLE_DOT
#property indicator_label5  "ift"
#property indicator_type5   DRAW_COLOR_LINE
#property indicator_color5  clrSilver,clrLimeGreen,clrOrange
#property indicator_width5  2

enum enColorOn
{
   cc_onSlope,   // Change color on slope change
   cc_onMiddle,  // Change color on middle line cross
   cc_onLevels   // Change color on outer levels cross
};
input int                inpRsiPeriod     =  32;         // RSI period
input int                inpMaPeriod      =   9;         // Average period (<=1 for no average)
input ENUM_MA_METHOD     inpMaMethod      = MODE_EMA;    // Average method
input ENUM_APPLIED_PRICE inpPrice         = PRICE_CLOSE; // Price
input enColorOn          inpColorOn       = cc_onLevels; // Color change :
input int                inpMinMaxPeriod  = 50;          // Floating levels period (<= 1 for fixed levels)
input double             inpLevelUp       = 80.0;        // Up level %
input double             inpLevelDown     = 20.0;        // Down level %

double rsi[],rsic[],fill1[],fill2[],levelUp[],levelMi[],levelDn[];
int _maHandle,_rsiHandle,_maPeriod;


int OnInit()
{
SetIndexBuffer(0,fill1  ,INDICATOR_DATA);
   SetIndexBuffer(1,fill2  ,INDICATOR_DATA);
   SetIndexBuffer(2,levelUp,INDICATOR_DATA);
   SetIndexBuffer(3,levelMi,INDICATOR_DATA);
   SetIndexBuffer(4,levelDn,INDICATOR_DATA);
   SetIndexBuffer(5,rsi    ,INDICATOR_DATA);
   SetIndexBuffer(6,rsic   ,INDICATOR_COLOR_INDEX);
         for (int i=0; i<4; i++) PlotIndexSetInteger(i,PLOT_SHOW_DATA,false);

         _maPeriod  = MathMax(inpMaPeriod,1);
         _rsiHandle = iRSI(_Symbol,0,inpRsiPeriod,inpPrice);             if (!_checkHandle(_rsiHandle)) return(INIT_FAILED);
         _maHandle  = iMA(_Symbol,0,_maPeriod,0,inpMaMethod,_rsiHandle); if (!_checkHandle(_maHandle))  return(INIT_FAILED);

         IndicatorSetString(INDICATOR_SHORTNAME,"Ehlers ift of smoothed RSI ("+(string)inpRsiPeriod+","+(string)_maPeriod+")");
   return(0);
}

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[])
{
   if(BarsCalculated(_rsiHandle)<rates_total) return(prev_calculated);
   if(BarsCalculated(_maHandle)<rates_total)  return(prev_calculated);

      
      int _copyCount = MathMin(rates_total-prev_calculated+1,rates_total);
            if (CopyBuffer(_maHandle,0,0,_copyCount,rsi)!=_copyCount) return(prev_calculated);


   int i=(int)MathMax(prev_calculated-1,0); for (; i<rates_total && !_StopFlag; i++)
   {
      double trss = (rsi-50.0)*0.1;        
            rsi = (MathExp(2.0*trss)-1.0)/(MathExp(2.0*trss)+1.0);
            if (inpMinMaxPeriod<=1)
            {                    
               levelUp = 2.0*inpLevelUp  /100.0-1.0;
               levelDn = 2.0*inpLevelDown/100.0-1.0;
               levelMi = (levelUp+levelDn)/2;
            }
            else
            {              
               int    start = MathMax(i-inpMinMaxPeriod+1,0);
               double max   = rsi[ArrayMaximum(rsi,start,inpMinMaxPeriod)];            
               double min   = rsi[ArrayMinimum(rsi,start,inpMinMaxPeriod)];            
               double range  = (max-min)/100.0;
                  levelUp = min+inpLevelUp  *range;
                  levelDn = min+inpLevelDown*range;
                  levelMi = min+50.0        *range;
            }              
            switch(inpColorOn)
            {
               case cc_onLevels: rsic = (rsi>levelUp)  ? 1 : (rsi<levelDn)  ? 2 : (i>0) ? (rsi==rsi[i-1]) ? rsic[i-1] : 0 : 0; break;
               case cc_onMiddle: rsic = (rsi>levelMi)  ? 1 : (rsi<levelMi)  ? 2 : 0; break;
               default :         rsic = (i>0) ? (rsi>rsi[i-1]) ? 1 : (rsi<rsi[i-1]) ? 2 : (i>0) ? (rsi==rsi[i-1]) ? rsic[i-1] : 0 : 0 : 0;
            }                  
            fill1 = rsi;
            fill2 = (rsi>levelUp) ? levelUp : (rsi<levelDn) ? levelDn : rsi;
   }
   return(i);
}


bool _checkHandle(int _handle)
{
   static int  _handles[];
          int  _size   = ArraySize(_handles);
          bool _answer = (_handle!=INVALID_HANDLE);
          if  (_answer)
               { ArrayResize(_handles,_size+1); _handles[_size]=_handle; }
          else { for (int i=_size-1; i>=0; i--) IndicatorRelease(_handles); ArrayResize(_handles,0); }
   return(_answer);
}  复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-12 10:40 , Processed in 0.107021 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表