下载MetaTrader 5
要添加评论,请登录注册
您想知道如何使用小工具吗?阅读该文章!
johnsun888
653
johnsun888 2011.11.23 06:59 

从网上搜索的公式,做成带箭头的指标。代码如下:

//+------------------------------------------------------------------+
//| CDP.mq4 |
//| JOHNSUN YE |
//| https://www.mql5.com/go?link=http://www.sedofx.com/ |
//+------------------------------------------------------------------+
#property copyright "JOHNSUN YE"
#property link "https://www.mql5.com/go?link=http://www.sedofx.com/"

#property indicator_chart_window

#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Red

double ExtMapBuffer1[];
double ExtMapBuffer2[];
extern int PP22=1;
extern int mov=3;


//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators

SetIndexStyle(0,DRAW_ARROW,0,2);
SetIndexArrow(0,233);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);

SetIndexStyle(1,DRAW_ARROW,0,2);
SetIndexArrow(1,234);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{

//----
Comment("CDP Indicator with arrows");

if(Digits == 2 || Digits == 4) { PP22 = 1; }
else {
if(Digits == 3 || Digits == 5) {PP22 = 10;}
}

int limit;
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
limit = Bars - counted_bars;
for(int i = 0; i < limit; i++)

//----
double H,L,C,Hn,Ln;

//----

H=iMA(NULL,0,1,0,MODE_SMA,PRICE_HIGH,i-1);
L=iMA(NULL,0,1,0,MODE_SMA,PRICE_LOW,i-1);
C=iMA(NULL,0,1,0,MODE_SMA,PRICE_CLOSE,i);
Hn=iMA(NULL,0,1,0,MODE_SMA,PRICE_HIGH,i);
Ln=iMA(NULL,0,1,0,MODE_SMA,PRICE_LOW,i);

double cdp=(H+L+2*C)/4;
double PT=Hn-Ln;
double AH=cdp+PT;
double NH=cdp*2-L;
double AL=cdp-PT;
double NL=cdp*2-H;

ExtMapBuffer1[i]=NL;
ExtMapBuffer1[i]=NH;

ExtMapBuffer1[i]=Low[i] - mov*PP22 *Point;
ExtMapBuffer2[i]=High[i] + mov*PP22 *Point;


//----
return(0);
}
//+------------------------------------------------------------------+

/
要添加评论,请登录注册