请给改个显示箭头的
原码如下,想把KDJ的显示符号改成箭头,谢谢了。
//+------------------------------------------------------------------+
//| 4_signals.mq4 Ver. 1.0 |
//| KDJ(5,3,3)、RSI(14)、MACD(12,26,9),及EMA10&EMA20交叉信号。 |
//| 偶然帅 |
//| [email protected] |
//| Feb. 2, 2007 |
//| |
//|Feb. 19, 2007 将取某个bar的函数iHigh等改成High,语句变得更简洁。|
//|Feb. 26, 2007 增加语音报警功能。 |
//+------------------------------------------------------------------+
#property copyright "偶然帅"
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Aqua // 四组信号的颜色;看多为蓝色,看空为红色
#property indicator_color2 Aqua
#property indicator_color3 Aqua
#property indicator_color4 Aqua
#property indicator_color5 Aqua
#property indicator_color6 Aqua
#property indicator_color7 Aqua
#property indicator_color8 Aqua
extern bool show_RSI = true; // 可以选择显示四种信号中的一种或几种
extern bool show_MACD = true;
extern bool show_EMA = false;
extern bool show_KDJ = true;
extern bool sound_alert = true; // 语音报警开关;默认为开
//---- buffers
double ExtMapBuffer1; // 显示箭头用的缓冲区
double ExtMapBuffer2;
double ExtMapBuffer3;
double ExtMapBuffer4;
double ExtMapBuffer5;
double ExtMapBuffer6;
double ExtMapBuffer7;
double ExtMapBuffer8;
int mark_RSI=0;
int mark_MACD=0;
int mark_EMA=0;
int mark_KDJ=0;
//+------------------------------------------------------------------+
//| 箭头初始化代码 |
//+------------------------------------------------------------------+
int init(){
SetIndexStyle(0,DRAW_ARROW); // RSI信号用圆圈表示
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexArrow(0,162);
SetIndexStyle(1,DRAW_ARROW);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexArrow(1,162);
SetIndexStyle(2,DRAW_ARROW); // MACD信号用圆点表示
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexArrow(2,108);
SetIndexStyle(3,DRAW_ARROW);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexArrow(3,108);
SetIndexStyle(4,DRAW_ARROW); // EMA交叉信号用箭头表示
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexArrow(4,233);
SetIndexStyle(5,DRAW_ARROW);
SetIndexBuffer(5,ExtMapBuffer6);
SetIndexArrow(5,234);
SetIndexStyle(6,DRAW_ARROW); // KDJ交叉信号用炸弹表示
SetIndexBuffer(6,ExtMapBuffer7);
SetIndexArrow(6,77);
SetIndexStyle(7,DRAW_ARROW);
SetIndexBuffer(7,ExtMapBuffer8);
SetIndexArrow(7,77);
return(0);
}
//+------------------------------------------------------------------+
//| 箭头反初始化代码 |
//+------------------------------------------------------------------+
int deinit(){
return(0);
}
//+------------------------------------------------------------------+
//| 计算显示箭头的条件 |
//+------------------------------------------------------------------+
int start(){
datetime t;
int i, j;
int shift;
double ema10, ema20, ema_diff, prv_ema_diff, pos, pos_adjust;
// 10均线 20均线 均线差 前一bar的均线差 箭头位置 箭头位置调节值
double macd_diff, prv_macd_diff, rsi, prv_rsi, kdj, kdj_diff, prv_kdj_diff;
pos_adjust = 100*Point; // 根据不同的时间框架确定信号显示的位置。主要是为了美观
if(Period()==1) pos_adjust = 1*Point;
if(Period()==5) pos_adjust = 3*Point;
if(Period()==15) pos_adjust = 8*Point;
if(Period()==30) pos_adjust = 10*Point;
if(Period()==60) pos_adjust = 13*Point;
if(Period()==240) pos_adjust = 20*Point;
if(Period()==1440) pos_adjust = 50*Point;
shift=Bars;
prv_rsi = -1;
prv_macd_diff = -1;
prv_ema_diff = -1;
prv_kdj_diff = -1;
for(j=shift-1;j>=0;j--){ // 从缓冲区中左起第二个bar开始显示,一直显示到右起第一个bar。
// 右起第一个bar的信号出现后,可能会消失;右起第二个bar以前的信号不变
ExtMapBuffer1[j]=0;
ExtMapBuffer2[j]=0;
ExtMapBuffer3[j]=0;
ExtMapBuffer4[j]=0;
ExtMapBuffer5[j]=0;
ExtMapBuffer6[j]=0;
ExtMapBuffer7[j]=0;
ExtMapBuffer8[j]=0;
rsi = iRSI( NULL, 0, 14, PRICE_CLOSE, j); // 计算各信号的值
macd_diff = iMACD( NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, j)
- iMACD( NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, j);
ema10 = iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,j);
ema20 = iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,j);
ema_diff = ema10 - ema20;
kdj = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, j);
kdj_diff = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, j)
- iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, j);
if(prv_ema_diff != -1){ // 如果不是负一,则说明是左起第二个bar
if(prv_rsi <= 30 && rsi >= 30 && show_RSI){ // RSI上穿30
ExtMapBuffer1[j] = Low[j] - pos_adjust; // 将信号显示在价格Bar下方
if(j==0 && mark_RSI!=1) {PlaySound("alert");mark_RSI=1;}
}
if(prv_rsi >= 70 && rsi <= 70 && show_RSI){ // RSI下穿70
ExtMapBuffer2[j] = High[j] + pos_adjust; // 将信号显示在价格Bar上方
if(j==0 && mark_RSI!=2) {PlaySound("alert");mark_RSI=2;}
}
if(macd_diff >= 0 && prv_macd_diff <=0 && show_MACD){ // MACD均线差值上穿 均线差值的均线
ExtMapBuffer3[j] = Low[j] - pos_adjust*0.8;
if(j==0 && mark_MACD!=1) {PlaySound("alert");mark_MACD=1;}
}
if(macd_diff <= 0 && prv_macd_diff >=0 && show_MACD){ // MACD均线差值下穿 均线差值的均线
ExtMapBuffer4[j] = High[j] + pos_adjust*0.8;
if(j==0 && mark_MACD!=2) {PlaySound("alert");mark_MACD=2;}
}
if(ema_diff >= 0 && prv_ema_diff <= 0 && show_EMA){ // 10EMA上叉20EMA
ExtMapBuffer5[j] = Low[j] - pos_adjust*0.5;
if(j==0 && mark_EMA!=1) {PlaySound("alert");mark_EMA=1;}
}
if(ema_diff <= 0 && prv_ema_diff >= 0 && show_EMA){ // 10EMA下叉20EMA
ExtMapBuffer6[j] = High[j] + pos_adjust*0.5;
if(j==0 && mark_EMA!=2) {PlaySound("alert");mark_EMA=2;}
}
if(kdj_diff >= 0 && prv_kdj_diff <= 0 && kdj<25 && show_KDJ){ // KDJ快线向慢线上方交叉
ExtMapBuffer7[j] = Low[j] - pos_adjust*0.2;
if(j==0 && mark_KDJ!=1) {PlaySound("alert");mark_KDJ=1;}
}
if(kdj_diff <= 0 && prv_kdj_diff >= 0 && kdj>75 && show_KDJ){ // KDJ快线向慢线下方交叉
ExtMapBuffer8[j] = High[j] + pos_adjust*0.2;
if(j==0 && mark_KDJ!=2) {PlaySound("alert");mark_KDJ=2;}
}
} // end of if(prv_ema
prv_rsi = rsi;
prv_macd_diff = macd_diff;
prv_ema_diff = ema_diff;
prv_kdj_diff = kdj_diff;
} // end of for(i=0
return(0);
}
//+------------------------------------------------------------------+