提示手数无效,你代码中要对品种的最小手数,最大手数做个验证。
提示手数无效,你代码中要对品种的最小手数,最大手数做个验证。
您好! 我还是不太明白 “验证” ,能具体些么 。 还有 Invalid stops这个错误 也是需要验证?
//+------------------------------------------------------------------+ //| 检查订单交易量的正确性 | //+------------------------------------------------------------------+ bool CheckVolumeValue(double volume,string &description) { //--- 交易操作允许的最小交易量 double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN); if(volume<min_volume) { description=StringFormat("交易量小于允许的最小交易量,SYMBOL_VOLUME_MIN=%.2f",min_volume); return(false); } //--- 交易操作允许的最大交易量 double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX); if(volume>max_volume) { description=StringFormat("交易量大于允许的最大交易量,SYMBOL_VOLUME_MAX=%.2f",max_volume); return(false); } //--- 取得交易量变化的最小步长 double volume_step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP); int ratio=(int)MathRound(volume/volume_step); if(MathAbs(ratio*volume_step-volume)>0.0000001) { description=StringFormat("交易量不是最小交易步长的整数倍,SYMBOL_VOLUME_STEP=%.2f, 最接近的正确交易量是 %.2f", volume_step,ratio*volume_step); return(false); } description="正确的交易量数值"; return(true); }
除此之外,还需要验证当前账号资金是否够开仓等等,具体阅读这篇文章:
- www.mql5.com
//----check SL of buy/sell order meet SYMBOL_TRADE_STOPS_LEVEL slptValue is target SL or PT double AskPrice = GetAsk(symbol); double BidPrice = GetBid(symbol); int stops_level=(int)SymbolInfoInteger(symbol,SYMBOL_TRADE_STOPS_LEVEL)+2; int freeze_level=(int)SymbolInfoInteger(symbol,SYMBOL_TRADE_FREEZE_LEVEL)+2; double point=SymbolInfoDouble(symbol,SYMBOL_POINT); //----check SL of buy/sell order meet SYMBOL_TRADE_STOPS_LEVEL if(orderType == ORDER_TYPE_BUY ) { double minSLofBuy=BidPrice-stops_level*point; slptValue = MathMin(slptValue, minSLofBuy); } if(orderType == ORDER_TYPE_SELL ) { double minSLofSell=AskPrice+stops_level*point; slptValue = MathMax(slptValue, minSLofSell); } if(orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_BUY_LIMIT) { double minSLofBuy=price-stops_level*point; slptValue = MathMin(slptValue, minSLofBuy); } if(orderType == ORDER_TYPE_SELL_STOP || orderType == ORDER_TYPE_SELL_LIMIT) { double minSLofSell=price+stops_level*point; slptValue = MathMax(slptValue, minSLofSell); } //----check PT of buy/sell meet SYMBOL_TRADE_STOPS_LEVEL if(orderType == ORDER_TYPE_BUY) { double minPTofBuy=BidPrice+stops_level*point; slptValue = MathMax(slptValue, minPTofBuy); } if(orderType == ORDER_TYPE_SELL) { double minPTofSell=AskPrice-stops_level*point; slptValue = MathMin(slptValue, minPTofSell); } if(orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_BUY_LIMIT) { double minPTofBuy=price+stops_level*point; slptValue = MathMax(slptValue, minPTofBuy); } if(orderType == ORDER_TYPE_SELL_STOP || orderType == ORDER_TYPE_SELL_LIMIT) { double minPTofSell=price-stops_level*point; slptValue = MathMin(slptValue, minPTofSell); }
你好 不知道我哪理解不对。 我对SYMBOL_TRADE_STOPS_LEVEL 验证的代码修改如上一条评论,还是会Invalid stops。 注意到都是在 Modification failed之后,我对SYMBOL_TRADE_FREEZE_LEVEL的验证又做了 如下一条评论。
//在更改挂单 止盈 止损的函数中,增加了SYMBOL_TRADE_FREEZE_LEVEL的现在
//----Block setting PT or SL of buy/sell pending order to meet SYMBOL_TRADE_FREEZE_LEVEL
//删除挂单的函数中,增加了不满足SYMBOL_TRADE_FREEZE_LEVEL要求不删除订单的代码
bool OrderDelete(ulong ticket)
{
ZeroMemory(mrequest);
ZeroMemory(mresult);
mrequest.action = TRADE_ACTION_REMOVE;
//mrequest.magic = magicNumber;
mrequest.order = ticket;
//----block OrderDelete to meet SYMBOL_TRADE_FREEZE_LEVEL
string orderSymbol = OrderGetString(ORDER_SYMBOL);
ENUM_ORDER_TYPE orderType = (ENUM_ORDER_TYPE) OrderGetInteger(ORDER_TYPE);
int freeze_level=(int)SymbolInfoInteger(orderSymbol,SYMBOL_TRADE_FREEZE_LEVEL)+2;
double price=OrderGetDouble(ORDER_PRICE_OPEN);
double AskPrice = GetAsk(orderSymbol);
double BidPrice = GetBid(orderSymbol);
double point=SymbolInfoDouble(orderSymbol,SYMBOL_POINT);
if(orderType == ORDER_TYPE_BUY_LIMIT)
{
bool check;
check=((AskPrice-price)>freeze_level*point);
if(!check) return false;
}
if(orderType == ORDER_TYPE_SELL_LIMIT)
{
bool check;
check=((price-BidPrice)>freeze_level*point);
if(!check) return false;
}
if(orderType == ORDER_TYPE_BUY_STOP)
{
bool check;
check=((price-AskPrice)>freeze_level*point);
if(!check) return false;
}
if(orderType == ORDER_TYPE_SELL_STOP)
{
bool check;
check=((BidPrice-price)>freeze_level*point);
if(!check) return false;
}
//--- action and return the result
return(OrderSend(mrequest, mresult));
}
//+------------------------------------------------------------------+
//开挂单的时候,调整挂单价格
//Adjust pending price in open pengding order function to meet SYMBOL_TRADE_FREEZE_LEVEL curPrice is pending price
int freeze_level=(int)SymbolInfoInteger(correctedSymbol,SYMBOL_TRADE_FREEZE_LEVEL)+2;
double point=SymbolInfoDouble(correctedSymbol,SYMBOL_POINT);
double ask=GetAsk(correctedSymbol);
double bid=GetBid(correctedSymbol);
if(type==ORDER_TYPE_BUY_LIMIT) curPrice=MathMin(ask-freeze_level*point,curPrice);
if(type==ORDER_TYPE_BUY_STOP) curPrice=MathMax(ask+freeze_level*point,curPrice);
if(type==ORDER_TYPE_SELL_LIMIT) curPrice=MathMax(bid+freeze_level*point,curPrice);
if(type==ORDER_TYPE_SELL_STOP) curPrice=MathMin(bid-freeze_level*point,curPrice);
//在仓位修改、关闭的函数中 加上以下block,满足SYMBOL_TRADE_FREEZE_LEVEL对仓位的要求
//block modify buy position to meet SYMBOL_TRADE_FREEZE_LEVEL
bool check;
check=((PositionGetDouble(POSITION_TP)-bid>freeze_level*point)&&(bid-PositionGetDouble(POSITION_SL)>freeze_level*point));
if(!check) return false;//block modify buy position
//block modify sell position to meet SYMBOL_TRADE_FREEZE_LEVEL
bool check;
check=((ask-PositionGetDouble(POSITION_TP)>freeze_level*point)&&(PositionGetDouble(POSITION_SL)-ask>freeze_level*point));
if(!check) return false;//block modify sell position
可以试试把单量规范一下!
您好!单量更改没问题了 stop_level 和freeze_level的更改你觉得还差什么? 谢谢
我在MT5上测试是没有这样的问题,怎么解决呀?谢谢!