指标: 三线KDJ - 页 3

 
ciciboy3 #:
您好楼主,第一次接触,现在933的kdj值算出来了之后我想再算一个1866的kdj值,然后通过两种周期的kdj值加一些判断条件,最终在货币主窗口预警,请问应该如何实现?

指标的参数在加载指标时在 参数窗口设置,你可以第二次加载指标并设置参数为18,6,6

依据特定条件判断做出预警,这样的功能需要编程实现。

建议发布需求到工作区:https://www.mql5.com/zh/job

 
array  out of range in kdj 阵列超出rsi的范围
 
从MT4 移植过来的指标,RSI KD 也同样出现了问题,  发生了数组越界, 技术员怀疑是数组遍历方式和MT5有差别造成   其他正规的MT5从左至右遍历指标没有发生越界!不知道对不对!因为加载后有时候指标会卸载!指标线会消失!
 
leida265 liao #:
从MT4 移植过来的指标,RSI KD 也同样出现了问题,  发生了数组越界, 技术员怀疑是数组遍历方式和MT5有差别造成   其他正规的MT5从左至右遍历指标没有发生越界!不知道对不对!因为加载后有时候指标会卸载!指标线会消失!

我发这个是给初学者学习用的,代码很规范,指标没有任何问题.

算了吧, 因为他很菜....水平不行...

导致你现在遇到很多问题.

 

楼主你好,我用你的三线RSI公式改的,但是编译后,除了‘ MA_C ’的值是对的,其他的‘ abs_C ’、 ‘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_C[];
double abs_MA[];
double MA_C[];


//double a,a1,b,b1,c,c1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,abs_C,INDICATOR_DATA);
   SetIndexBuffer(1,abs_MA,INDICATOR_DATA);
   SetIndexBuffer(2,MA_C,INDICATOR_DATA);

   //---
   ArraySetAsSeries(abs_C,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_C[i]=close[i]-MA_C[i];    
      }

   for(i=limit; i>=0; i--)
     {
      if(i>=rates_total-1)abs_MA[i]=0;
      else
      abs_MA[i] = MathAbs(abs_C[i])/MA_C[i];           //abs_MA:=ABS(CLOSE-MA(CLOSE,N))/MA(CLOSE,N);
     } 

     
  
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


Ziheng Zhuang
Ziheng Zhuang
  • 2024.01.29
  • www.mql5.com
交易者的个人资料
附加的文件:
3.png  95 kb
 

楼主,非常感谢您提供的kdj指标,但发现同一周期MT4和MT5的kdj走势是不同的,请问是什么原因呢?谢谢!


 
shenzhoucun #:

楼主你好,我用你的三线RSI公式改的,但是编译后,除了‘ MA_C ’的值是对的,其他的‘ abs_C ’、 ‘abs_MA ’ 值都是错的,不知道是哪个地方做错了,大神可以指导一下吗


  你的指标放在主图, 显示了一条进行MA_C, 与K线图表是一个数量级, 所以能正常显示

  你说 abs_C,abs_MA是错的?  你知道它们的取值范围大概是多少吗?  按你的给的公式,abs_C是价格差, 它的值很小甚至出现负数, abs_MA更小, 他们与K线本身在数值上不是一个数量级, K线图表上可能就看不到它们了

  代码中存在的问题, iMA()返回的是指标句柄,应该在初始化中创建指标句柄, 其次abs_MA[i] = MathAbs(abs_C[i])/MA_C[i] 必须先判断分母 MA_C[i] 不为零

  供参考:

#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_C[];
double abs_MA[];
double MA_C[];

int handle;
//double a,a1,b,b1,c,c1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
   SetIndexBuffer(0,abs_C,INDICATOR_DATA);
   SetIndexBuffer(1,abs_MA,INDICATOR_DATA);
   SetIndexBuffer(2,MA_C,INDICATOR_DATA);

//---
   ArraySetAsSeries(abs_C,true);
   ArraySetAsSeries(abs_MA,true);
   ArraySetAsSeries(MA_C,true);

//---
   string name = "test("+ (string)N+")";
   IndicatorSetString(INDICATOR_SHORTNAME,name);

   handle =  iMA(Symbol(),0,N,0,MODE_SMA,PRICE_CLOSE);

//---
   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);
   double v[1];
   for(i=limit; i>=0; i--)
   {
      MA_C[i]=0.0;
      if(i>rates_total-N) continue;
      CopyBuffer(handle,0,i,1,v);
      MA_C[i]=v[0];
   }

   for(i=limit; i>=0; i--)
   {
      abs_C[i]=close[i]-MA_C[i];
   }

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

      if(MA_C[i]!=0) abs_MA[i] = MathAbs(abs_C[i])/MA_C[i];           //abs_MA:=ABS(CLOSE-MA(CLOSE,N))/MA(CLOSE,N);
      else  abs_MA[i]=0;
   }

//--- return value of prev_calculated for next call
   return(rates_total);
}

  

    

 
CharlieZeng #:

楼主,非常感谢您提供的kdj指标,但发现同一周期MT4和MT5的kdj走势是不同的,请问是什么原因呢?谢谢!


  很正常, 因为MT4和MT5的数据源可能不同

 

楼主,您好!感谢您及时回复。

我把MT、MT5和文华的kdj作比较,绝大部分周期的kdj走势都是一致的,这是不是说明和平台提供的数据没关系呢?

但就是发现MT4和MT5有时候kdj走势又不同,如附图。不知道什么原因。

附加的文件:
MT4_kdj04.png  57 kb
MT5_kdj6h.png  49 kb
 
CharlieZeng #:

楼主,您好!感谢您及时回复。

我把MT、MT5和文华的kdj作比较,绝大部分周期的kdj走势都是一致的,这是不是说明和平台提供的数据没关系呢?

但就是发现MT4和MT5有时候kdj走势又不同,如附图。不知道什么原因。

算法一样, 结果不同, 原因就是"投喂"的数据不一样

你那个BTCUSD在 MT4上与MT5上的K线数据不一样,  不信你一一对比下H1的历史数据, 看看是否一致 ? 

不要眼睛看走势好像一样, 差之毫厘谬以千里 

我这个同一个平台上的BITCOIN 在MT4和MT5上的数据不一样, KDJ也不一样