//---- input parameters
extern int MovingPeriod=20;
extern int MovingShift=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
SetComment("MA_Miror");
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int Signal(int oldSignal)
{
return (SignalMA(oldSignal));
}
int SignalMA(int oldSignal)
{
int i=1;
int signal = oldSignal;
double ma1, ma2;
ma1=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,i)-iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_OPEN,i);
ma2=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_OPEN,i)-iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,i);
if (ma1 > ma2) signal = OP_BUY;
if (ma1 < ma2) signal = OP_SELL;
return (signal);
}
int SignalRandom(int oldSignal)
{
int signal = oldSignal;
if (GetNumTickets() == 0)
{
int rnd = MathRand();
if (rnd > 16358)
signal = OP_BUY;
else
signal = OP_SELL;
}
return (signal);
}
int start()
{
//----
int signal,oldSignal;
oldSignal = -1;
FindOrders(true);
if (GetNumTickets() != 0)
{
oldSignal = GetCommand(0);
}
else
oldSignal = 1;
signal = Signal(oldSignal);
if (signal != oldSignal)
{
if (GetNumTickets() != 0)
CloseOrder(GetTicket(0));
if (signal == OP_BUY)
Buy(GetLots());
if (signal == OP_SELL)
Sell(GetLots());
请EA编写高手帮看下问题出在哪?
测试不了,也加载不了. 且我改写过的策略都显示成灰色(如图)
本人做股指期货自动交易的,用的是文华平台,有好的策略,现在做MT4,但不懂MQL语言,\
寻求EA编写高手
//+------------------------------------------------------------------+
//| TTT.mq4 |
//| yingweijiang |
//| 20012-02-24 |
//+------------------------------------------------------------------+
#property copyright "yingweijiang"
#property link "20012-02-24"
//---- input parameters
extern int MovingPeriod=20;
extern int MovingShift=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
SetComment("MA_Miror");
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int Signal(int oldSignal)
{
return (SignalMA(oldSignal));
}
int SignalMA(int oldSignal)
{
int i=1;
int signal = oldSignal;
double ma1, ma2;
ma1=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,i)-iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_OPEN,i);
ma2=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_OPEN,i)-iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,i);
if (ma1 > ma2) signal = OP_BUY;
if (ma1 < ma2) signal = OP_SELL;
return (signal);
}
int SignalRandom(int oldSignal)
{
int signal = oldSignal;
if (GetNumTickets() == 0)
{
int rnd = MathRand();
if (rnd > 16358)
signal = OP_BUY;
else
signal = OP_SELL;
}
return (signal);
}
int start()
{
//----
int signal,oldSignal;
oldSignal = -1;
FindOrders(true);
if (GetNumTickets() != 0)
{
oldSignal = GetCommand(0);
}
else
oldSignal = 1;
signal = Signal(oldSignal);
if (signal != oldSignal)
{
if (GetNumTickets() != 0)
CloseOrder(GetTicket(0));
if (signal == OP_BUY)
Buy(GetLots());
if (signal == OP_SELL)
Sell(GetLots());
}
//----
return(0);
}
//+------------------------------------------------------------------+