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

指标编写求助2

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-24 03:28:00 | 显示全部楼层 |阅读模式
通达信    abs_MA :=ABS(CLOSE-MA(CLOSE,N))/MA(CLOSE,N);各位大神好,我用的mql5里的三线RSI公式改的,但是编译后,除了‘ MA_C ’的值是对的,其他的‘ abs_CBuffer ’、 ‘abs_MA ’ 值都是错的,不知道是哪个地方做错了,大神可以指导一下吗



#property copyright "Copyright 2020,fxMeter"

#property link      "https://www.mql5.com/zh/users/fxmeter"

#property version   "1.00"

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_plots   3


#property indicator_label1  "abs_C"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrGold

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1


#property indicator_label2  "abs_MA"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrWhite

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1


#property indicator_label3  "MA_C"

#property indicator_type3   DRAW_LINE

#property indicator_color3  clrGold

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1


//--- input parameters

input int      N=30;

//--- indicator buffers


//--- 辅助计算 buffer

double abs_CBuffer[],abs_MA[],MA_C[];


//double a,a1,b,b1,c,c1;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,abs_CBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,abs_MA,INDICATOR_DATA);

   SetIndexBuffer(2,MA_C,INDICATOR_DATA);


   //---

   ArraySetAsSeries(abs_CBuffer,true);   

   ArraySetAsSeries(abs_MA,true);

   ArraySetAsSeries(MA_C,true);


   //---

   string name = "test("+ (string)N+")";

   IndicatorSetString(INDICATOR_SHORTNAME,name);


//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

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[])

  {

//---

   int i,limit=0;

   if(rates_total<=0)return(0);

   if(prev_calculated<=0)limit=rates_total-1;

   else

      limit = rates_total - prev_calculated +1;


     ArraySetAsSeries(close,true);

     ArraySetAsSeries(high,true);

     ArraySetAsSeries(low,true);


for(i=limit; i>=0; i--)

     {

         if(i>rates_total-N) continue;

         //int ma_c1;

         int ma_c1 = iMA(Symbol(),0,N,0,MODE_SMA,PRICE_CLOSE); //

          CopyBuffer(ma_c1,0,0,500,MA_C);

     }


   for(i=limit; i>=0; i--)

     {

     abs_CBuffer=close-MA_C;   

      }


   for(i=limit; i>=0; i--)

     {

      if(i>=rates_total-1)abs_MA=0;

      else

      abs_MA = MathAbs(abs_CBuffer)/MA_C;           //abs_MA:=ABS(CLOSE-MA(CLOSE,N))/MA(CLOSE,N);

     }


//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-10-12 13:35 , Processed in 0.100883 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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