Useful hints for the Championship participants
In the championship’s rules there were 4 important restrictions that have been applied:
These restrictions are configured on the trading server settings on which the Championship will be held. The trading server will not pass these trading operations that would breach the above Championship restrictions. Thus, information of such violations will be stored in the server’s log-file. Expert advisors that breach the above mentioned restrictions on a regular basis can be disqualified and removed from participation in the Championship. All these restrictions are related to the function OrderSend(). It is necessary to trace these restrictions and not to allow falsely call of this function. When the wrong value of volume is inputted (lots less than minimal value, or more than the maximal value, or an error of granulation) the function will return as an error. GetLastError() will return a code 131 (ERR_INVALID_TRADE_VOLUME). In most cases, a certain function for order volume calculation is used, that based on money management strategy. Usually in calculations used, the following are considered: balance, equity, free margin, and leverage and risk percent. This function may look as follows: //--- extern variables extern double ExtMaximumRisk=0.05; // 5% by default //--- calculate current volume double CalculateVolume() { double lot_min =MarketInfo(Symbol(),MODE_MINLOT); double lot_max =MarketInfo(Symbol(),MODE_MAXLOT); double lot_step=MarketInfo(Symbol(),MODE_LOTSTEP); double contract=MarketInfo(Symbol(),MODE_LOTSIZE); double vol; //--- check data if(lot_min<0 || lot_max<=0.0 || lot_step<=0.0) { Print("CalculateVolume: invalid MarketInfo() results [",lot_min,",",lot_max,",",lot_step,"]"); return(0); } if(AccountLeverage()<=0) { Print("CalculateVolume: invalid AccountLeverage() [",AccountLeverage(),"]"); return(0); } //--- basic formula vol=NormalizeDouble(AccountFreeMargin()*ExtMaximumRisk*AccountLeverage()/contract,2); //--- additional calculation // ... //--- check min, max and step vol=NormalizeDouble(vol/lot_step,0)*lot_step; if(vol<lot_min) vol=lot_min; if(vol>lot_max) vol=lot_max; //--- return(vol); } It is not recommended to store important market characteristics in the function init(), it is better to request market conditions in a place of use and it is obligatory to check them on empty/zero values. Otherwise, an attempt of starting a script on inactive accounts may result in receiving the wrong values. For example, in the function above it is possible to receive fatal "Zero divide" both at lot_step=0, and at AccountLeverage()=0. Now we shall discuss the total of open and pending orders. This value is returned by function OrdersTotal(). In case of restriction error of total open and pending orders the function OrderSend() will end with error, and the value returned by function GetLastError() will be equal to 148 (ERR_TRADE_TOO_MANY_ORDERS). To avoid this error, it is enough to check the total active orders before any operation SendOrder(): //--- extern variables int ExtMaxOrders=3; ... //--- check before SendOrder if(OrdersTotal() >= ExtMaxOrders) return(...); //--- send order int ticket=OrderSend(...); ... There are very serious dangers both to the trader and to the trading server by means of "scripts-killers" which without the realized control send set of trading transactions into the server. This often happens in the form of cyclic attempts to push the incorrect request into server over and over again. We shall examine some cases:
In the section of documentation "MQL4 Reference - Trading functions - Execution errors" the recommendations on trading errors processing are published. Created: 2006.08.14 Author: MetaQuotes
Yes
2006.09.18 16:55
So the expert can trade at most 3 X 5 = 15 lots, even it has made more profit? |
|





how to avoid this error? ordersend error 148 ordermodify error 1 ordersend error 130. thanks