下载MetaTrader 5
要添加评论,请登录注册
开始使用市场获利。发布您的产品!
Игорь Бойко
43
Игорь Бойко 2007.03.17 09:41 
首先,我想感谢论坛管理员和网友们这段时间以来的不吝赐教。

int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
//Don't work in the first load, wait for the first cross!
static bool first_time = true;
if(first_time == true)
{
first_time = false;
return (0);
}
//----
if(line1 > line2)
current_direction = 1; //up
if(line1 < line2)
current_direction = 2; //down
//----
if(current_direction != last_direction) //changed
{
last_direction = current_direction;
return(last_direction);
}
else
{
return (0); //not changed
}
}
----------------------------------------------------
这是EMA_CROSS.mq4里判断两条均线是否穿越的函数,
可是我在测试时候看复盘显示,发现开仓方向是相反的。比如说5日均线向上穿越10日均线时,系统开的是空单。
我想问题是出在这个函数里,但是我看不出有什么问题。
请赐教。thank you.
Rashid Umarov
管理员
6602
Rashid Umarov 2007.03.17 14:50  
The better solution is that

int Crossed (double currline1 , double currline2, double prevline1 , double prevline2)
  {
    int current_direction=0;
//----
    if(currline1 > currline2 && prevline1 < prevline2)
        current_direction = 1;  //up
    if(currline1 < currline2 && prevline1 > prevline2)
        current_direction = -1;  //down
//----
    return (current_direction); 
  }
Игорь Бойко
43
Игорь Бойко 2007.03.18 07:19  
我按您的建议修改了代码,看起来工作正常一些了。
但是,在盘整行情中,两根均线很接近,就不可避免的让CROSSED函数发出过多的错误信号,
我想应该使用过滤器,使信号看上去更好一些。我让currline1与currline2的比较带上点差,如果小于N点就忽略。
您有什么更专业一些的建议吗?
THANKS
Rashid Umarov
管理员
6602
Rashid Umarov 2007.03.18 13:24  
Yes, this is good idea and next step in improving this function. For examle:

int Crossed (double currline1 , double currline2, double prevline1 , double prevline2, int minDifferenceInPoints)
  {
    int current_direction=0;
//----
    if (MathAbs(currline1-currline2)>minDifferenceInPoints*Point)
       {
       if(currline1 > currline2 && prevline1 < prevline2)
           current_direction = 1;  //up
       if(currline1 < currline2 && prevline1 > prevline2)
           current_direction = -1;  //down
       }
//----
    return (current_direction); 
  }
/
要添加评论,请登录注册