通达信 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);
}
//+------------------------------------------------------------------+ |