我正在创建一个简单的EA,以对SMA交叉交易进行交易。但是,我无法从checkEntry函数获得正确的信号。在大多数情况下都可以,但是当两条线几乎相交然后又分开时,我得到的信号是错误的。谁能找出错误所在?另外,我想在分频后给信号前引入一个小缓冲区,比如说1点。
string checkEntry()
{
double myFastMa = iMA(ChartSymbol(),Period(),varSma1,0,MODE_SMA,PRICE_CLOSE,0);
double mySlowMa = iMA(ChartSymbol(),Period(),varSma2,0,MODE_SMA,PRICE_CLOSE,0);
double myFastMaPrev = iMA(ChartSymbol(),Period(),varSma1,1,MODE_SMA,PRICE_CLOSE,1);
double mySlowMaPrev = iMA(ChartSymbol(),Period(),varSma2,1,MODE_SMA,PRICE_CLOSE,1);
double myTrendMa = iMA(ChartSymbol(),Period(),varSma3,0,MODE_SMA,PRICE_CLOSE,0);
if (myFastMa > mySlowMa && myFastMaPrev <= mySlowMaPrev) signal = "BUY";
if (myFastMa < mySlowMa && myFastMaPrev >= mySlowMaPrev) signal = "SELL";
// Alert ("myFastMa is ", myFastMa," and myFastMaPrev is ", myFastMaPrev);
// Alert ("mySlowMa is ", mySlowMa," and mySlowMaPrev is ", mySlowMaPrev);
// Alert ("This gives a ",signal," signal");
return signal;
} // End CheckEntry()