调用参数的EA调试问题

 

//+------------------------------------------------------------------+
//| K.mq4 |
//| Copyright ?2008, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2008, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 MediumBlue
//---- input parameters
//---- buffers
double MaBuffer1[];
double MaBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MaBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,MaBuffer2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(Bars<=50) return(0);
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

//---- ma 1
for(int i=0; i<limit; i++)
{
MaBuffer1[i]=iMA(NULL,0,5,0,MODE_SMA, PRICE_MEDIAN, i) ;
}
//---- ma 2
for(i=0; i<limit; i++)
{
MaBuffer2[i]=iMA(NULL,0,15,0,MODE_SMA, PRICE_MEDIAN, i) ;
}
//----
return(0);
}

//+------------------------------------------------------------------+
//| ea模板.mq4 |
//| Copyright @2007, http://hexun.com/pckr |
//| |
//| | |
//+------------------------------------------------------------------+
#property copyright "Copyright @2006, pckr"
#property link "http://hexun.com/pckr"


#include <ubulib.mqh>

//********************************************************************
//********************************************************************
//+---------------------------------------------------+
//---- User Inputs |
//+---------------------------------------------------+
extern int Slippage =10; // 滑点
extern double TakeProfit = 12;// 最大止赢
extern double StopLoss = 30; // 最大止损
extern double TrailingStop = 0; // 移动止损

//---- Money Management

extern int mm =1; // 设为0不接受资金管理,
extern double Riskpercent =20; // 下单占资金的百分比
extern double DecreaseFactor =2; // 亏损减少下单手数
extern double Margincutoff =80; // 资金低于Margincutoff不交易
extern double Lots =5; // 设置期望的手数(如果忽略资金管理).
extern int tradeSymbolNum =3; // 交易笔数

//---- Account functions
extern int AccountIsMini =2; // 设为1使用迷你账户,设为2使用超迷你账户

//---- 用户自定义参数
double A;
double B;
double C;
//********************************************************************
//********************************************************************

//---- 系统变量

string OrderText =""; // 在函数中使用"Buy" or "Sell"为条件
double lotMM =0;
int TradesInThisSymbol =0; // 外汇交易数
datetime LastTime; // 最后订单时间
double Sl =0; // 止损
double Tr =0; // 止赢
int NumBuys =0;
int NumSells =0;
int MagicNumber;

//---- 用户变量

//********************************************************************
//********************************************************************
//+------------------------------------------------------------------+
//| 初始化函数 |
//+------------------------------------------------------------------+
int init()
{


return(0);
}

//********************************************************************
//********************************************************************
//+------------------------------------------------------------------+
//| 取消初始化函数 |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}

//********************************************************************
//********************************************************************
//+------------------------------------------------------------------+
//| 启动 start() |
//+------------------------------------------------------------------+
int start()
{
//---- Start functions variables

int donttrade = 0;
int allexit = 0;
int ExitCondition;

//int MagicNumber =20050610;
MagicNumber = 3000 + func_Symbol2Val(Symbol())*100;
string setup="hexun.com/pckr" + Symbol() + "_" + func_TimeFrame_Val2String(func_TimeFrame_Const2Val(Period()));
if(Bars<100 || IsTradeAllowed()==false) return;
//+------------------------------------------------------------------+
//| 这里输入需要的数据如指标等 |
//+------------------------------------------------------------------+

int limit;
int counted_bars=IndicatorCounted();
if(Bars<=50) return(0);
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=0; i<limit; i++)
{
A =iCustom(NULL,0,"k",13,0,i);
B =iCustom(NULL,0,"k",13,0,i-1);
C =iCustom(NULL,0,"k",13,1,i);
}

//+------------------------------------------------------------------+
//| 周五平仓 |
//+------------------------------------------------------------------+

if(DayOfWeek()==5 && Hour()>=21) donttrade=1; // 21时禁止交易
if(DayOfWeek()==5 && Hour()>=22) allexit=1; //22时平所有合约

//+------------------------------------------------------------------+
//| 检查未平仓合约 |
//+------------------------------------------------------------------+

NumBuys = CheckOpenBuyPositions(MagicNumber); // 如果有买合约,看看是否应该关闭。
if (NumBuys > 0) TryClosePositions("BUY",allexit);

NumSells = CheckOpenSellPositions(MagicNumber); // 如果有卖合约,看看是否应该关闭。
if (NumSells > 0) TryClosePositions("SELL",allexit);

TradesInThisSymbol = CheckOpenPositions(MagicNumber); // 更新TradesInThisSymbol值

//+------------------------------------------------------------------+
//| New Position Controls |
//+------------------------------------------------------------------+

if(AccountFreeMargin() < Margincutoff) // 检查,以确保账户有足够的资金。
{
return(0);
}
if(TradesInThisSymbol > tradeSymbolNum) // 只允许每个货币对有TradesInThisSymbol张合约
{
return(0);
}
if(CurTime() < LastTime)
{
return(0);
}



if(mm == 1) // 检查资金管理是否选定的。
lotMM = LotsOptimized(MagicNumber, Lots, Riskpercent, DecreaseFactor, AccountIsMini);
else
lotMM = Lots; // 如资金管理未选定,Lots为预设值

OrderText = "";

if((CheckBuyCondition() == 1)) // 如果买入的条件存在着,传递参数给doorder ( ) 。
{
OrderText = "BUY";
if (StopLoss>0)
{
Sl = Ask-StopLoss*Point;
}
else
{
Sl=0;
}
if (TakeProfit == 0)
Tr = 0;
else
Tr = Ask+TakeProfit*Point;
}

if (CheckSellCondition() == 1) // 如果卖出的条件存在着,传递参数给doorder ( ) 。
{
OrderText = "SELL";
if (StopLoss>0)
{
Sl = Bid+StopLoss*Point;
}
else
{
Sl = 0;
}
if (TakeProfit == 0)
Tr = 0;
else
Tr = Bid-TakeProfit*Point;
}
if(OrderText != "" && TradesInThisSymbol == 0 && donttrade == 0 )
{
LastTime = DoTrades(OrderText,setup,MagicNumber, lotMM, Sl, Tr, CurTime(), Slippage);
return(0);
}
Comment("更多信息请访问hexun.com/pckr");
return(0);
}

//********************************************************************
//********************************************************************
//+----------------------------------------------+
//| CheckExitCondition() |
//| |
//| 平仓条件 |
//| return 0 for 条件不满足 |
//| return 1 for 条件满足 |
//+----------------------------------------------+
int CheckExitCondition(string type)
{
if (type == "BUY")
{ if(A<=B && A<C || A<B && A<=C) return(1); //输入条件
else return(0);
}
if (type == "SELL") //输入条件
{ if(A>=B && A>C || A>B && A>=C) return (1);
else return(0);
}

}

//********************************************************************
//********************************************************************
//+------------------------------------------+
//| CheckBuyCondition() |
//| |
//| 定义买入条件 |
//| |
//| return 0 for 条件不满足 |
//| return 1 for 条件满足 |
//+------------------------------------------+
int CheckBuyCondition()
{
if(
A>=B && A>C || A>B && A>=C
)
return(1);
else return (0);
}

//********************************************************************
//********************************************************************
//+------------------------------------------+
//| CheckSellCondition |
//| |
//| 定义卖出条件 |
//| |
//| return 0 for 条件不满足 |
//| return 1 for 条件满足 |
//+------------------------------------------+
int CheckSellCondition()
{
if(
A<=B && A<C || A<B && A<=C
)
return(1);

else return (0);

}

//********************************************************************
//********************************************************************
//+--------------------------------------------------------+
//| TryClosePositions |
//+--------------------------------------------------------+
int TryClosePositions(string type,int exitall)
{
int ExitCondition;

// Print(type);
if (type == "BUY")
{
ExitCondition = CheckExitCondition("BUY"); // First check if indicators cause exit

if(exitall==1) ExitCondition = 1; // Then check if Friday
HandleBuys(ExitCondition,Slippage,TakeProfit,MagicNumber);
}
if (type == "SELL")
{
ExitCondition = CheckExitCondition("SELL"); // First check if indicators cause exit

if(exitall==1) ExitCondition = 1; // Then check if Friday
HandleSells(ExitCondition,Slippage,TakeProfit,MagicNumber);
}
return (0);
}

如此设置EA在调试运行中没有出现任何的结果是怎么回事呢?请高人指点一下。

 

//+------------------------------------------------------------------+
//| ea模板.mq4 |
//| Copyright @2007, http://hexun.com/pckr |
//| |
//| | |
//+------------------------------------------------------------------+
#property copyright "Copyright @2006, pckr"
#property link "http://hexun.com/pckr"


#include <ubulib.mqh>

//********************************************************************
//********************************************************************
//+---------------------------------------------------+
//---- User Inputs |
//+---------------------------------------------------+
extern int Slippage =10; // 滑点
extern double TakeProfit = 12;// 最大止赢
extern double StopLoss = 30; // 最大止损
extern double TrailingStop = 0; // 移动止损

//---- Money Management

extern int mm =1; // 设为0不接受资金管理,
extern double Riskpercent =20; // 下单占资金的百分比
extern double DecreaseFactor =2; // 亏损减少下单手数
extern double Margincutoff =80; // 资金低于Margincutoff不交易
extern double Lots =5; // 设置期望的手数(如果忽略资金管理).
extern int tradeSymbolNum =3; // 交易笔数

//---- Account functions
extern int AccountIsMini =2; // 设为1使用迷你账户,设为2使用超迷你账户

//---- 用户自定义参数
double A;
double B;
double C;
//********************************************************************
//********************************************************************

//---- 系统变量

string OrderText =""; // 在函数中使用"Buy" or "Sell"为条件
double lotMM =0;
int TradesInThisSymbol =0; // 外汇交易数
datetime LastTime; // 最后订单时间
double Sl =0; // 止损
double Tr =0; // 止赢
int NumBuys =0;
int NumSells =0;
int MagicNumber;

//---- 用户变量

//********************************************************************
//********************************************************************
//+------------------------------------------------------------------+
//| 初始化函数 |
//+------------------------------------------------------------------+
int init()
{


return(0);
}

//********************************************************************
//********************************************************************
//+------------------------------------------------------------------+
//| 取消初始化函数 |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}

//********************************************************************
//********************************************************************
//+------------------------------------------------------------------+
//| 启动 start() |
//+------------------------------------------------------------------+
int start()
{
//---- Start functions variables

int donttrade = 0;
int allexit = 0;
int ExitCondition;

//int MagicNumber =20050610;
MagicNumber = 3000 + func_Symbol2Val(Symbol())*100;
string setup="hexun.com/pckr" + Symbol() + "_" + func_TimeFrame_Val2String(func_TimeFrame_Const2Val(Period()));
if(Bars<100 || IsTradeAllowed()==false) return;
//+------------------------------------------------------------------+
//| 这里输入需要的数据如指标等 |
//+------------------------------------------------------------------+

int limit;
int counted_bars=IndicatorCounted();
if(Bars<=50) return(0);
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(int i=0; i<limit; i++)
{
A =iCustom(NULL,0,"k",13,0,i);
B =iCustom(NULL,0,"k",13,0,i-1);
C =iCustom(NULL,0,"k",13,1,i);
}

//+------------------------------------------------------------------+
//| 周五平仓 |
//+------------------------------------------------------------------+

if(DayOfWeek()==5 && Hour()>=21) donttrade=1; // 21时禁止交易
if(DayOfWeek()==5 && Hour()>=22) allexit=1; //22时平所有合约

//+------------------------------------------------------------------+
//| 检查未平仓合约 |
//+------------------------------------------------------------------+

NumBuys = CheckOpenBuyPositions(MagicNumber); // 如果有买合约,看看是否应该关闭。
if (NumBuys > 0) TryClosePositions("BUY",allexit);

NumSells = CheckOpenSellPositions(MagicNumber); // 如果有卖合约,看看是否应该关闭。
if (NumSells > 0) TryClosePositions("SELL",allexit);

TradesInThisSymbol = CheckOpenPositions(MagicNumber); // 更新TradesInThisSymbol值

//+------------------------------------------------------------------+
//| New Position Controls |
//+------------------------------------------------------------------+

if(AccountFreeMargin() < Margincutoff) // 检查,以确保账户有足够的资金。
{
return(0);
}
if(TradesInThisSymbol > tradeSymbolNum) // 只允许每个货币对有TradesInThisSymbol张合约
{
return(0);
}
if(CurTime() < LastTime)
{
return(0);
}



if(mm == 1) // 检查资金管理是否选定的。
lotMM = LotsOptimized(MagicNumber, Lots, Riskpercent, DecreaseFactor, AccountIsMini);
else
lotMM = Lots; // 如资金管理未选定,Lots为预设值

OrderText = "";

if((CheckBuyCondition() == 1)) // 如果买入的条件存在着,传递参数给doorder ( ) 。
{
OrderText = "BUY";
if (StopLoss>0)
{
Sl = Ask-StopLoss*Point;
}
else
{
Sl=0;
}
if (TakeProfit == 0)
Tr = 0;
else
Tr = Ask+TakeProfit*Point;
}

if (CheckSellCondition() == 1) // 如果卖出的条件存在着,传递参数给doorder ( ) 。
{
OrderText = "SELL";
if (StopLoss>0)
{
Sl = Bid+StopLoss*Point;
}
else
{
Sl = 0;
}
if (TakeProfit == 0)
Tr = 0;
else
Tr = Bid-TakeProfit*Point;
}
if(OrderText != "" && TradesInThisSymbol == 0 && donttrade == 0 )
{
LastTime = DoTrades(OrderText,setup,MagicNumber, lotMM, Sl, Tr, CurTime(), Slippage);
return(0);
}
Comment("更多信息请访问hexun.com/pckr");
return(0);
}

//********************************************************************
//********************************************************************
//+----------------------------------------------+
//| CheckExitCondition() |
//| |
//| 平仓条件 |
//| return 0 for 条件不满足 |
//| return 1 for 条件满足 |
//+----------------------------------------------+
int CheckExitCondition(string type)
{
if (type == "BUY")
{ if(A<=B && A<C || A<B && A<=C) return(1); //输入条件
else return(0);
}
if (type == "SELL") //输入条件
{ if(A>=B && A>C || A>B && A>=C) return (1);
else return(0);
}

}

//********************************************************************
//********************************************************************
//+------------------------------------------+
//| CheckBuyCondition() |
//| |
//| 定义买入条件 |
//| |
//| return 0 for 条件不满足 |
//| return 1 for 条件满足 |
//+------------------------------------------+
int CheckBuyCondition()
{
if(
A>=B && A>C || A>B && A>=C
)
return(1);
else return (0);
}

//********************************************************************
//********************************************************************
//+------------------------------------------+
//| CheckSellCondition |
//| |
//| 定义卖出条件 |
//| |
//| return 0 for 条件不满足 |
//| return 1 for 条件满足 |
//+------------------------------------------+
int CheckSellCondition()
{
if(
A<=B && A<C || A<B && A<=C
)
return(1);

else return (0);

}

//********************************************************************
//********************************************************************
//+--------------------------------------------------------+
//| TryClosePositions |
//+--------------------------------------------------------+
int TryClosePositions(string type,int exitall)
{
int ExitCondition;

// Print(type);
if (type == "BUY")
{
ExitCondition = CheckExitCondition("BUY"); // First check if indicators cause exit

if(exitall==1) ExitCondition = 1; // Then check if Friday
HandleBuys(ExitCondition,Slippage,TakeProfit,MagicNumber);
}
if (type == "SELL")
{
ExitCondition = CheckExitCondition("SELL"); // First check if indicators cause exit

if(exitall==1) ExitCondition = 1; // Then check if Friday
HandleSells(ExitCondition,Slippage,TakeProfit,MagicNumber);
}
return (0);
}

原因: