思迷思 2008-5-5 11:16
MT4中的突破指标
[code]/+------------------------------------------------------------------+
//| channel_breakout_entry.mq4 |
//| with ATR Stop Loss calculation |
//| use this one for drawing channel |
//| and the place for placing initial SL |
//| as described the turtle trading rules |
//+------------------------------------------------------------------+
#property copyright "darmasdt"
#property link "http://indotraders.org"
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 DarkGray
#property indicator_color2 DarkGray
#property indicator_color3 DodgerBlue
#property indicator_color4 DodgerBlue
#property indicator_color5 Tomato
#property indicator_color6 Tomato
#property indicator_color7 LightSkyBlue
#property indicator_color8 Plum
//---- input parameters
extern int Range1=10;
extern int Range2=20;
extern int Range3=55;
extern double atr_factor=2;
extern int atr_range=14;
//---- buffers
double UpBuffer1[];
double DnBuffer1[];
double UpBuffer2[];
double DnBuffer2[];
double UpBuffer3[];
double DnBuffer3[];
double atr_b2[];
double atr_b3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
//SetIndexStyle(6,DRAW_ARROW,STYLE_DOT,1);
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,249);
//SetIndexStyle(7,DRAW_ARROW,STYLE_DOT,1);
SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(7,249);
SetIndexBuffer(0,UpBuffer1);
SetIndexBuffer(1,DnBuffer1);
SetIndexLabel(0,"trailing_Up");
SetIndexLabel(1,"trailing_Dn");
SetIndexBuffer(2,UpBuffer2);
SetIndexBuffer(3,DnBuffer2);
SetIndexLabel(2,"sys1_Up");
SetIndexLabel(3,"sys1_Dn");
SetIndexBuffer(4,UpBuffer3);
SetIndexBuffer(5,DnBuffer3);
SetIndexLabel(4,"failsafe_Up");
SetIndexLabel(5,"failsafe_Dn");
SetIndexBuffer(6,atr_b2);
SetIndexBuffer(7,atr_b3);
SetIndexLabel(6,"Sys 1 Stp");
SetIndexLabel(7,"Sys 2 Stp");
//---- name for DataWindow and indicator subwindow label
short_name="CBO_entry("+Range1+","+Range2+","+Range3+")";
IndicatorShortName(short_name);
//----
SetIndexDrawBegin(0,0);
SetIndexDrawBegin(1,0);
SetIndexDrawBegin(2,0);
SetIndexDrawBegin(3,0);
SetIndexDrawBegin(4,0);
SetIndexDrawBegin(5,0);
SetIndexDrawBegin(6,0);
SetIndexDrawBegin(7,0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Channel Trend System |
//+------------------------------------------------------------------+
int start()
{
int i;
//----
for(i=Bars-1;i>=0;i--)
{
//Calculating Channel
//-------------------
UpBuffer1[i]=High[Highest(NULL,0,MODE_HIGH,Range1,i+1)];
DnBuffer1[i]=Low[Lowest(NULL,0,MODE_LOW,Range1,i+1)];
UpBuffer2[i]=High[Highest(NULL,0,MODE_HIGH,Range2,i+1)];
DnBuffer2[i]=Low[Lowest(NULL,0,MODE_LOW,Range2,i+1)];
UpBuffer3[i]=High[Highest(NULL,0,MODE_HIGH,Range3,i+1)];
DnBuffer3[i]=Low[Lowest(NULL,0,MODE_LOW,Range3,i+1)];
//Calculating ATR Stops
//---------------------
if(High[i+1]<=UpBuffer2[i+1] && High[i]>UpBuffer2[i])
{
atr_b2[i]= UpBuffer2[i] - (iATR(NULL,0,atr_range,i+1)*atr_factor);
}
if(High[i+1]<=UpBuffer3[i+1] && High[i]>UpBuffer3[i])
{
atr_b3[i]= UpBuffer3[i] - (iATR(NULL,0,atr_range,i+1)*atr_factor);
}
if(Low[i+1]>=DnBuffer2[i+1] && Low[i]<DnBuffer2[i])
{
atr_b2[i]= DnBuffer2[i] + (iATR(NULL,0,atr_range,i+1)*atr_factor);
}
if(Low[i+1]>=DnBuffer3[i+1] && Low[i]<DnBuffer3[i])
{
atr_b3[i]= DnBuffer3[i] + (iATR(NULL,0,atr_range,i+1)*atr_factor);
}
}
return(0);
}
//+------------------------------------------------------------------+[/code]如何分析它呢?我想注释掉指标线,从哪里下手啊.谢谢!
xfxyldj 2008-5-5 13:31
不可以注释掉。后面的箭头标记需要用到,如果不向显示出来。可以修改
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
将DRAW_LINE改为DRAW_NONE
就可以了。
思迷思 2008-5-5 16:10
OK,先谢了啊,回去试试看
思迷思 2008-5-5 21:31
[quote]原帖由 [i]思迷思[/i] 于 2008-5-5 16:10 发表 [url=http://www.onefx.net/bbs/redirect.php?goto=findpost&pid=217780&ptid=43695][img]http://www.onefx.net/bbs/images/common/back.gif[/img][/url]
OK,先谢了啊,回去试试看 [/quote]
作了如下修改[code] SetIndexStyle(0,DRAW_NONE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_NONE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_NONE,STYLE_SOLID,1);
SetIndexStyle(3,DRAW_NONE,STYLE_SOLID,1);
SetIndexStyle(4,DRAW_NONE,STYLE_SOLID,1);
SetIndexStyle(5,DRAW_NONE,STYLE_SOLID,1);
[/code]图象上的曲线未见少啊,还有哪里要改呢?谢谢
[attach]22972[/attach]
xfxyldj 2008-5-6 00:53
编译后,删除原来指标,重新加载!
你看到的应该是旧的曲线。
短线客 2008-5-6 08:21
又学了一手
多谢
思迷思 2008-5-6 08:36
这样啊,看来与FXJ等软件相比,确有不方便之处耶.
谢谢了,回去再试试,再问一句,如何加载啊
思迷思 2008-5-6 08:48
[code]//---- buffers
double UpBuffer1[];
double DnBuffer1[];
double UpBuffer2[];
double DnBuffer2[];
double UpBuffer3[];
double DnBuffer3[]; [/code]从作用上看,这些象是存放曲线的数组,不要其中的一些了,曲线应该少些了吧.
xfxyldj 2008-5-6 08:50
就是重现添加指标
思迷思 2008-5-6 09:19
[quote]原帖由 [i]xfxyldj[/i] 于 2008-5-6 08:50 发表 [url=http://www.onefx.net/bbs/redirect.php?goto=findpost&pid=218342&ptid=43695][img]http://www.onefx.net/bbs/images/common/back.gif[/img][/url]
就是重现添加指标 [/quote]
再问问,有无改对或改错的测试功能呢?
思迷思 2008-5-6 20:28
[quote]原帖由 [i]xfxyldj[/i] 于 2008-5-5 13:31 发表 [url=http://www.onefx.net/bbs/redirect.php?goto=findpost&pid=217644&ptid=43695][img]http://www.onefx.net/bbs/images/common/back.gif[/img][/url]
不可以注释掉。后面的箭头标记需要用到,如果不向显示出来。可以修改
[/quote]
向版主报告,可用//或/*-----*/进行注释掉一些语句,进行类似的测试。
只是每次都要重新启动或关闭打开,较麻烦些。
[attach]23052[/attach][code]/---- indicator line
//SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
//SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
//SetIndexStyle(6,DRAW_ARROW,STYLE_DOT,1);
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,249);
//SetIndexStyle(7,DRAW_ARROW,STYLE_DOT,1);
SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(7,249);
//SetIndexBuffer(0,UpBuffer1);
//SetIndexBuffer(1,DnBuffer1);
SetIndexLabel(0,"trailing_Up");
SetIndexLabel(1,"trailing_Dn");
SetIndexBuffer(2,UpBuffer2);
SetIndexBuffer(3,DnBuffer2);
SetIndexLabel(2,"sys1_Up");
SetIndexLabel(3,"sys1_Dn");
SetIndexBuffer(4,UpBuffer3);
SetIndexBuffer(5,DnBuffer3);
SetIndexLabel(4,"failsafe_Up");
SetIndexLabel(5,"failsafe_Dn");
SetIndexBuffer(6,atr_b2);
SetIndexBuffer(7,atr_b3);
SetIndexLabel(6,"Sys 1 Stp");
SetIndexLabel(7,"Sys 2 Stp");
//---- name for DataWindow and indicator subwindow label
short_name="CBO_entry("+Range1+","+Range2+","+Range3+")";
IndicatorShortName(short_name);
//----
//SetIndexDrawBegin(0,0);
// SetIndexDrawBegin(1,0);
SetIndexDrawBegin(2,0);
SetIndexDrawBegin(3,0);
SetIndexDrawBegin(4,0);
SetIndexDrawBegin(5,0);
SetIndexDrawBegin(6,0);
SetIndexDrawBegin(7,0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Channel Trend System |
//+------------------------------------------------------------------+
int start()
{
int i;
//----
for(i=Bars-1;i>=0;i--)
{
//Calculating Channel
//-------------------
UpBuffer1[i]=High[Highest(NULL,0,MODE_HIGH,Range1,i+1)];
DnBuffer1[i]=Low[Lowest(NULL,0,MODE_LOW,Range1,i+1)];
UpBuffer2[i]=High[Highest(NULL,0,MODE_HIGH,Range2,i+1)];
DnBuffer2[i]=Low[Lowest(NULL,0,MODE_LOW,Range2,i+1)];
UpBuffer3[i]=High[Highest(NULL,0,MODE_HIGH,Range3,i+1)];
DnBuffer3[i]=Low[Lowest(NULL,0,MODE_LOW,Range3,i+1)];
//Calculating ATR Stops
//---------------------
/*
if(High[i+1]<=UpBuffer2[i+1] && High[i]>UpBuffer2[i])
{
atr_b2[i]= UpBuffer2[i] - (iATR(NULL,0,atr_range,i+1)*atr_factor);
}
if(High[i+1]<=UpBuffer3[i+1] && High[i]>UpBuffer3[i])
{
atr_b3[i]= UpBuffer3[i] - (iATR(NULL,0,atr_range,i+1)*atr_factor);
}
if(Low[i+1]>=DnBuffer2[i+1] && Low[i]<DnBuffer2[i])
{
atr_b2[i]= DnBuffer2[i] + (iATR(NULL,0,atr_range,i+1)*atr_factor);
}
if(Low[i+1]>=DnBuffer3[i+1] && Low[i]<DnBuffer3[i])
{
atr_b3[i]= DnBuffer3[i] + (iATR(NULL,0,atr_range,i+1)*atr_factor);
}
*/[/code]
[[i] 本帖最后由 思迷思 于 2008-5-6 20:34 编辑 [/i]]
页:
[1]