搜档网
当前位置:搜档网 › mt4 随笔

mt4 随笔

void SetIndexStyle( int index, int type, void style, void width, void clr)
void SetIndexStyle( int 索引线, int 样式风格, void 画线风格, void 宽度, void 颜色)
设置新型、样式、宽度和颜色为一条指定的显示线。
参量:
index - 索引线。必须在0至7之间。
type - 样式风格。可以是划线风格列表其中一个。
style - 画线风格。可以应用单线。可以是划线风格列表其中一个。 EMPTY 值表示风格不变。
width - 线的宽度。线的宽度可以是1,2,3,4,5。 EMPTY 值表示着风格不变。
clr - 线的颜色。.现存的参量表示颜色将不会改变。

示例:
SetIndexStyle(3, DRAW_LINE, EMPTY, 2, Red);

SetIndexStyle()函数画线风格的列举。
DRAW_LINE 0 画线
DRAW_SECTION 1 线条
DRAW_HISTOGRAM 2 画柱状图
DRAW_ARROW 3 画箭头(货币对)。
DRAW_ZIGZAG 4 在添加的缓冲器之间画线条
DRAW_NONE 12 没有画线

STYLE_SOLID 0 实线
STYLE_DASH 1 断线
STYLE_DOT 2 点线
STYLE_DASHDOT 3 断线与点线交替.
STYLE_DASHDOTDOT 4 断线与双点线交替


void SetIndexDrawBegin( int index, int begin)
从给出指标线画出必须开始设置柱数字(从数据开始) 。指标线会从左到右画出所给出指标数组值左边部分不会显示在图表或数据窗口中。设置0作为默认值, 随后,所有数据将得出。
参量:
index - 索引线。必须在0至7之间。
begin - 第一个画出柱的数字位置。

示例:
int init()
{
//----使用计算2个添加缓冲
IndicatorBuffers(3);
//----画出设定
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 绘制3个添加缓冲位置
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
//---- DataWindow 和自定义子窗口标签名称
IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//---- 初始化完成
return(0);
}




RSV赋值:(收盘价-9日内最低价的最低值)/(9日内最高价的最高值-9日内最低价的最低值)*100
RSV:=(CLOSE-LLV(LOW,9))/(HHV(HIGH,9)-LLV(LOW,9))*100;
rsv=(Open[i])-*100


K:=SMA(RSV,3,1)
K赋值:RSV的3日[1日权重]移动平均
Ksma(RSV,3,2);

D:=SMA(K,3,1)
D赋值:K的3日[1日权重]移动平均
Dsma(K,M2,3);

J赋值:3*K-2*D

K:=SMA(RSV,3,1);//K:=平均数(RSV,3,1); //3分之一?
D:=SMA(K,3,1); //3分之一?
J:=3*K-2*D;

gao=High[iHighest(NULL,0,MODE_HIGH,9,i)];
di=Low[iLowest(NULL,0,MODE_LOW,9,i)];
RSV[i]=(Close[i]-gao)/(gao-di)*100;


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//+------------------------------------------------------------------+
//| KDJ.mq4 |
//|

senlin ge |
//| https://www.sodocs.net/doc/dc8794968.html, |
//+------------------------------------------------------------------+
#property copyright "senlin ge 20080219"
#property link "mailto:yyy999@https://www.sodocs.net/doc/dc8794968.html,"
#property indicator_separate_window //在指定窗口显示指标
#property indicator_minimum 0 //在指标窗口下端
#property indicator_maximum 100 //在指标窗口的上端
#property indicator_buffers 8 //对于指标计算的数字,最大为 8

#property indicator_color1 LightSlateGray //水平线颜色
#property indicator_color2 0x00ff00 //颜色
#property indicator_color3 Red //颜色
#property indicator_color4 Yellow //颜色
#property indicator_color5 0Xffccff //颜色
#property indicator_color6 MediumSlateBlue//颜色

//---- input parameters
extern int M1=3; //设定的值
extern int M2=6; //设定的值
extern int KdjPeriod=30; //设定的值
//---- buffers
double RsvBuffer[],RSV[],K[],D[],J[],KDC[];//要化的线声明是有小数
double MaxHigh=0,MinLow=0; //声明是有小数的并赋值为0
//+------------------------------------------------------------------+
//|自定义指标初始化函数 |
//+------------------------------------------------------------------+
int init()
{
//---- 数据窗口的子窗口标签名称和指标
string short_name;
short_name="KDJ("+KdjPeriod+","+M1+","+M2+") "+"Author:Senlin Ge";
IndicatorShortName(short_name);
SetIndexLabel(0,NULL); //线的描述
SetIndexLabel(1,"RSV:"); //线的描述
SetIndexLabel(2,"K"); //线的描述
SetIndexLabel(3,"D:"); //线的描述
SetIndexLabel(4,"J"); //线的描述
SetIndexLabel(5,"KDC"); //线的描述
//----
//---- indicators指标
//---- drawing settings绘图设置
IndicatorDigits(Digits-2); //
//SetIndexStyle(0,DRAW_NONE);
//SetIndexLabel(0,NULL);
SetIndexShift(0,100);
SetIndexStyle(0,DRAW_LINE,2,0);//初始化线
SetIndexBuffer(0,RsvBuffer); //初始化线
//----
SetIndexStyle(1,DRAW_LINE); //初始化线
SetIndexBuffer(1,RSV); //初始化线
SetIndexStyle(2,DRAW_LINE); //初始化线
SetIndexBuffer(2,K); //初始化线
SetIndexStyle(3,DRAW_LINE); //初始化线
SetIndexBuffer(3,D); //初始化线
SetIndexStyle(4,DRAW_LINE); //初始化线
SetIndexBuffer(4,J); //初始化线
SetIndexStyle(5,DRAW_HISTOGRAM);//初始化线
SetIndexBuffer(5,KDC); //初始化线
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+--------------------------------------------------

----------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
int i;
if(Bars<=KdjPeriod) return(0); //Bars柱数,KdjPeriod=30,return(0)返回值
//----
i=Bars-counted_bars-1; //i=Bars-counted_bars-1,当前柱数,减去IndicatorCounted()函数会返回的前一个柱,再-1,所以i应该等0
while(i>=0) //循环语句当1大于等于0时进行循环
{
MaxHigh=High[iHighest(NULL,0,MODE_HIGH,KdjPeriod,i)]; //High当前图表每个柱的最高价格,
//iHighest根据类型返回最大值转移的一个具体数字
MinLow=Low[iLowest(NULL,0,MODE_LOW,KdjPeriod,i)]; //Low 系列数组包含当前图表每个柱的最低价格。

RSV[i]=(Close[i]-MinLow)/(MaxHigh-MinLow)*100; //Close[] 列数组包含当前图表每个柱的收盘价格。

if(i/2==true) //没明白
RsvBuffer[i]=50.0; //赋值
i--;
}
Ksma(RSV,M1,2); //get K value
Dsma(K,M2,3); //get D value
//---- //
if(counted_bars>0) counted_bars--;
for(i=Bars-counted_bars-1;i>=0;i--)
{
RsvBuffer[i]=50.0;
J[i]=3*K[i]-2*D[i];
if(J[i]<0) J[i]=0;
if(J[i]>100) J[i]=100;
KDC[i]=K[i]-D[i];
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| 简单移动平均 |
//+------------------------------------------------------------------+
double Dsma(double ArrPara[],int MA_Period,int flag)
{
double sum=0;
int ExtCountedBars=IndicatorCounted();//IndicatorCounted()函数会返回的前一个柱
int i; //
int pos=Bars-IndicatorCounted()-1;
//---- initial accumulation
if(posfor(i=1;isum+=K[pos];
//---- main calculation loop
while(pos>=0)
{
sum+=K[pos]; //
switch(flag)
{
case 3: D[pos]=sum/MA_Period;break;
}
sum-=K[pos+MA_Period-1];
pos--;
}
}
//+------------------------------------------------------------------+
//| 简单移动平均 |
//+------------------------------------------------------------------+
double Ksma(double ArrPara[],int MA_Period,int flag)
{
double sum=0;
int ExtCountedBars=IndicatorCounted();
int i,pos=Bars-IndicatorCounted()-1;
//---- initial accumulati

on
if(posfor(i=1;isum+=RSV[pos];
//---- main calculation loop
while(pos>=0)
{
sum+=RSV[pos]; //
switch(flag)
{
case 2: K[pos]=sum/MA_Period;break;
}
sum-=RSV[pos+MA_Period-1];
pos--;
}
}
//+------------------------------------------------------------------+





相关主题