}
这个错误码一直返回 4753 这个错误码
查了一下 错误码
ERR_TRADE_POSITION_NOT_FOUND | 4753 | 未找到位置 |
在账户栏里 这个未找到位置是什么意思。。。??
- www.mql5.com
MT5实在对新手太不友好了,教程少 出问题没人能帮助解决
return value of 'OrderSend' should be checked
编译后提示这个 感觉是ordersend这个函数的问题 请问这个是什么问题啊
return value of 'OrderSend' should be checked
编译后提示这个 感觉是ordersend这个函数的问题 请问这个是什么问题啊
我按照 教程 针对初学者以 MQL5 编写“EA 交易”的分步指南 - MQL5文章 输入完了所有代码,但是用历史数据回测的时候却没有一笔交易?? 请问大佬是什么原因 代码如下
//+------------------------------------------------------------------+
//| 20210610_EA01.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
input int StopLoss=30;
input int TakeProfit=100;
input int ADX_Period=8;
input int MA_period=8;
input int EA_magic=12345;
input double Adx_Min=22.0;
input double Lot=0.1;
int adxHandle;
int maHandle;
double plsDI[],minDI[],adxVal[];
double maVal[];
double p_close;
int STP,TKP;
int OnInit()
{
adxHandle=iADX(NULL,0,ADX_Period);
maHandle=iMA(_Symbol,_Period,MA_period,0,MODE_EMA,PRICE_CLOSE);
if(adxHandle<0 || maHandle<0)
{
Alert("创建指标句柄出错 - 错误:",GetLastError(),"!!");
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
IndicatorRelease(adxHandle);
IndicatorRelease(maHandle);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Bars(_Symbol,_Period) < 60)
{
Alert("不足60根柱子,EA退出");
return;
}
static datetime Old_time;
datetime New_time[1];
bool IsNewBar=false;
int copied=CopyTime(_Symbol,_Period,0,1,New_time);
if(copied>0)
{
if(Old_time!=New_time[0])
{
IsNewBar=true;
if(MQLInfoInteger(MQL_DEBUG)) Print("我们在此时有了新柱 ",New_time[0]," 旧的时间是 ",Old_time);
Old_time=New_time[0];
}
}
else
{
Alert("复制历史时间数据出错, 错误 =",GetLastError() );
ResetLastError();
return;
}
if(IsNewBar==false)
{
return;
}
int Mybars=Bars(_Symbol,_Period);
if(Mybars<60)
{
Alert("不到60");
return;
}
MqlTick latest_price;
MqlTradeRequest mrequest;
MqlTradeResult mresult;
MqlRates mrate[];
ZeroMemory(mrequest);
ArraySetAsSeries(mrate,true);
ArraySetAsSeries(plsDI,true);
ArraySetAsSeries(minDI,true);
ArraySetAsSeries(adxVal,true);
ArraySetAsSeries(maVal,true);
if(!SymbolInfoTick(_Symbol,latest_price))
{
Alert("error",GetLastError(),"!");
return;
}
if(CopyRates(_Symbol,_Period,0,3,mrate)<0)
{
Alert("复制出错",GetLastError(),"!");
return;
}
//mrate[1].time;
if(CopyBuffer(adxHandle,0,0,3,adxVal)<0 || CopyBuffer(adxHandle,1,0,3,plsDI)<0 || CopyBuffer(adxHandle,2,0,3,minDI)<0 )
{
Alert("复制错误",GetLastError(),"!");
return;
}
if(CopyBuffer(maHandle,0,0,3,maVal)<0)
{
Alert("复制错误",GetLastError(),"!");
return;
}
bool Buy_opened=false;
bool Sell_opened=false;
if(PositionSelect(_Symbol) == true)
{
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY )
{
Buy_opened = true;
}
else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL )
{
Sell_opened = true;
}
}
p_close=mrate[1].close;
bool buy_condition_1 = (maVal[0]>maVal[1]) && (maVal[1]>maVal[2]);
bool buy_condition_2 = (p_close > maVal[1]);
bool buy_condition_3 = (adxVal[0]>Adx_Min );
bool buy_condition_4 = (plsDI[0]>minDI[0]);
if(buy_condition_1 && buy_condition_2)
{
if(buy_condition_3 && buy_condition_4)
{
if(Buy_opened)
{
Alert("已经有买入仓位");
return;
}
mrequest.action = TRADE_ACTION_DEAL;
mrequest.price = NormalizeDouble(latest_price.ask,_Digits);
mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits);
mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits);
mrequest.symbol = _Symbol;
mrequest.volume = Lot;
mrequest.magic = EA_magic;
mrequest.type_filling = ORDER_FILLING_FOK;
mrequest.deviation = 100;
OrderSend(mrequest,mresult);
}
}
if(mresult.retcode==10009 || mresult.retcode==10008)
{
Alert("买入如已经成功下单,订单",mresult.order,"!!");
}
else
{
Alert("错误号:",GetLastError());
return;
}
bool sell_condition_1 = (maVal[0]<maVal[1]) && (maVal[1]<maVal[2]);
bool sell_condition_2 = (p_close < maVal[1]);
bool sell_condition_3 = (adxVal[0] > Adx_Min );
bool sell_condition_4 = (plsDI[0] < minDI[0]);
if(sell_condition_1 && sell_condition_2)
{
if(sell_condition_3 && sell_condition_4)
{
if(Sell_opened)
{
Alert("已有卖出仓位");
return;
}
mrequest.action = TRADE_ACTION_DEAL;
mrequest.price = NormalizeDouble(latest_price.bid,_Digits);
mrequest.sl = NormalizeDouble(latest_price.bid + STP * _Point,_Digits);
mrequest.tp = NormalizeDouble(latest_price.bid - TKP * _Point,_Digits);
mrequest.symbol = _Symbol;
mrequest.volume = Lot;
mrequest.magic = EA_magic;
mrequest.type = ORDER_TYPE_SELL;
mrequest.type_filling = ORDER_FILLING_FOK;
mrequest.deviation = 100;
OrderSend(mrequest,mresult);
if(mresult.retcode == 10009 || mresult.retcode ==10008)
{
Alert("订单号",mrequest.order);
}
else
{
Alert("错误号",GetLastError() );
return;
}
}
}
}
//+------------------------------------------------------------------+
咨询问题,尽量不要发这种长长的东西,没人看的,要言简意赅,直奔主题,这样你才能得到最快的回复
咨询问题,尽量不要发这种长长的东西,没人看的,要言简意赅,直奔主题,这样你才能得到最快的回复
我按照 教程 针对初学者以 MQL5 编写“EA 交易”的分步指南 - MQL5文章 输入完了所有代码,但是用历史数据回测的时候却没有一笔交易?? 请问大佬是什么原因 代码如下
//+------------------------------------------------------------------+
//| 20210610_EA01.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
input int StopLoss=30;
input int TakeProfit=100;
input int ADX_Period=8;
input int MA_period=8;
input int EA_magic=12345;
input double Adx_Min=22.0;
input double Lot=0.1;
int adxHandle;
int maHandle;
double plsDI[],minDI[],adxVal[];
double maVal[];
double p_close;
int STP,TKP;
int OnInit()
{
adxHandle=iADX(NULL,0,ADX_Period);
maHandle=iMA(_Symbol,_Period,MA_period,0,MODE_EMA,PRICE_CLOSE);
if(adxHandle<0 || maHandle<0)
{
Alert("创建指标句柄出错 - 错误:",GetLastError(),"!!");
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
IndicatorRelease(adxHandle);
IndicatorRelease(maHandle);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Bars(_Symbol,_Period) < 60)
{
Alert("不足60根柱子,EA退出");
return;
}
static datetime Old_time;
datetime New_time[1];
bool IsNewBar=false;
int copied=CopyTime(_Symbol,_Period,0,1,New_time);
if(copied>0)
{
if(Old_time!=New_time[0])
{
IsNewBar=true;
if(MQLInfoInteger(MQL_DEBUG)) Print("我们在此时有了新柱 ",New_time[0]," 旧的时间是 ",Old_time);
Old_time=New_time[0];
}
}
else
{
Alert("复制历史时间数据出错, 错误 =",GetLastError() );
ResetLastError();
return;
}
if(IsNewBar==false)
{
return;
}
int Mybars=Bars(_Symbol,_Period);
if(Mybars<60)
{
Alert("不到60");
return;
}
MqlTick latest_price;
MqlTradeRequest mrequest;
MqlTradeResult mresult;
MqlRates mrate[];
ZeroMemory(mrequest);
ArraySetAsSeries(mrate,true);
ArraySetAsSeries(plsDI,true);
ArraySetAsSeries(minDI,true);
ArraySetAsSeries(adxVal,true);
ArraySetAsSeries(maVal,true);
if(!SymbolInfoTick(_Symbol,latest_price))
{
Alert("error",GetLastError(),"!");
return;
}
if(CopyRates(_Symbol,_Period,0,3,mrate)<0)
{
Alert("复制出错",GetLastError(),"!");
return;
}
//mrate[1].time;
if(CopyBuffer(adxHandle,0,0,3,adxVal)<0 || CopyBuffer(adxHandle,1,0,3,plsDI)<0 || CopyBuffer(adxHandle,2,0,3,minDI)<0 )
{
Alert("复制错误",GetLastError(),"!");
return;
}
if(CopyBuffer(maHandle,0,0,3,maVal)<0)
{
Alert("复制错误",GetLastError(),"!");
return;
}
bool Buy_opened=false;
bool Sell_opened=false;
if(PositionSelect(_Symbol) == true)
{
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY )
{
Buy_opened = true;
}
else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL )
{
Sell_opened = true;
}
}
p_close=mrate[1].close;
bool buy_condition_1 = (maVal[0]>maVal[1]) && (maVal[1]>maVal[2]);
bool buy_condition_2 = (p_close > maVal[1]);
bool buy_condition_3 = (adxVal[0]>Adx_Min );
bool buy_condition_4 = (plsDI[0]>minDI[0]);
if(buy_condition_1 && buy_condition_2)
{
if(buy_condition_3 && buy_condition_4)
{
if(Buy_opened)
{
Alert("已经有买入仓位");
return;
}
mrequest.action = TRADE_ACTION_DEAL;
mrequest.price = NormalizeDouble(latest_price.ask,_Digits);
mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits);
mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits);
mrequest.symbol = _Symbol;
mrequest.volume = Lot;
mrequest.magic = EA_magic;
mrequest.type_filling = ORDER_FILLING_FOK;
mrequest.deviation = 100;
OrderSend(mrequest,mresult);
}
}
if(mresult.retcode==10009 || mresult.retcode==10008)
{
Alert("买入如已经成功下单,订单",mresult.order,"!!");
}
else
{
Alert("错误号:",GetLastError());
return;
}
bool sell_condition_1 = (maVal[0]<maVal[1]) && (maVal[1]<maVal[2]);
bool sell_condition_2 = (p_close < maVal[1]);
bool sell_condition_3 = (adxVal[0] > Adx_Min );
bool sell_condition_4 = (plsDI[0] < minDI[0]);
if(sell_condition_1 && sell_condition_2)
{
if(sell_condition_3 && sell_condition_4)
{
if(Sell_opened)
{
Alert("已有卖出仓位");
return;
}
mrequest.action = TRADE_ACTION_DEAL;
mrequest.price = NormalizeDouble(latest_price.bid,_Digits);
mrequest.sl = NormalizeDouble(latest_price.bid + STP * _Point,_Digits);
mrequest.tp = NormalizeDouble(latest_price.bid - TKP * _Point,_Digits);
mrequest.symbol = _Symbol;
mrequest.volume = Lot;
mrequest.magic = EA_magic;
mrequest.type = ORDER_TYPE_SELL;
mrequest.type_filling = ORDER_FILLING_FOK;
mrequest.deviation = 100;
OrderSend(mrequest,mresult);
if(mresult.retcode == 10009 || mresult.retcode ==10008)
{
Alert("订单号",mrequest.order);
}
else
{
Alert("错误号",GetLastError() );
return;
}
}
}
}
//+------------------------------------------------------------------+