hi there, any one who really help me out regarding error code 4051 and invalid lot size during automization of my EA , as i am unable to publish
it
Syed Shanif Ahmed:
hi there, any one who really help me out regarding error code 4051 and invalid lot size during automization of my EA , as i am unable to publish it
hi there, any one who really help me out regarding error code 4051 and invalid lot size during automization of my EA , as i am unable to publish it
Check your lot sizes and make sure that whichever function parameter is invalid is valid.
Keith Watford:
Hello Keith, thanks for showing interest , lotsize is multipe of lotsfactor which i already normalizedouble to 2 digits.
Check your lot sizes and make sure that whichever function parameter is invalid is valid.
Syed Shanif Ahmed:
hi there, any one who really help me out regarding error code 4051 and invalid lot size during automization of my EA , as i am unable to publish it
you can share your code to get proper solution
hi there, any one who really help me out regarding error code 4051 and invalid lot size during automization of my EA , as i am unable to publish it
Please edit your post and use the code button (Alt+S) to paste the code.
Keith Watford:
Please edit your post and use the code button (Alt+S) to paste the code.
Please edit your post and use the code button (Alt+S) to paste the code.
//+---------------------------------------------------------------------+ //| GRID Trend EA| //| March 14, 2020 | //| Syed Shanif Ahmed | //| In no event will author be liable for any damages whatsoever. | //| Use at your own risk. | //| | //+---------------------------------------------------------------------+ #property copyright "Copyright by Syed Shanif Ahmed" #property version "1.00" #property script_show_inputs #property strict input string WARNING = "Using a robot carries risk, use on demo account FIRST"; enum TypeOfOrder {BUY=0,SELL=1}; enum SL {Enable=0,Disable=1}; extern int MagicNumber =1234; input TypeOfOrder TradeType; //Type Of Order extern double Take_Profit=0.01; input SL Stoploss=1; extern double Stop_Loss=0; extern double Initial_Lot=0.01; extern double Lots_Factor=2; extern int Grid_Size=100; extern int Max_Orders=10; double price=0; //+------------------------------------------------------------------+ //| MAIN FUNCTION START HERE | //+------------------------------------------------------------------+ void OnTick() { if(ProfitCheck()>=Take_Profit) {CloseSellPositions(); ClosebuyPositions(); } if(Stoploss==0 && ProfitCheck()<=-Stop_Loss) {CloseSellPositions(); ClosebuyPositions(); } if(TradeType==1) if(CountOrder()==0) //----EXECUTION OF SELL TYPE ORDER--------------------------------------------------------------------------------------------------- {OrderSend(Symbol(),OP_SELL,NormalizeDouble(Initial_Lot,2),Bid,3,0,0,NULL,MagicNumber,0,clrBlue);price=Bid;} if(CountOrder()<Max_Orders && Bid >= price+Grid_sell()*Point) {OrderSend(Symbol(),OP_SELL,NormalizeDouble(lot_size_total_sell()+lot_size_total_sell()*Lots_Factor,2),Bid,3,0,0,NULL,MagicNumber,0,clrBlue);price=Ask;} //----EXECUTION OF BUY TYPE ORDER----------------------------------------------------------------------------------------------------- if(TradeType==0) if(CountOrder()==0) {OrderSend(Symbol(),OP_BUY,NormalizeDouble(Initial_Lot,2),Ask,3,0,0,NULL,MagicNumber,0,clrBlue);price=Ask;} if(CountOrder()<Max_Orders && Ask <= price-Grid_buy()*Point) {OrderSend(Symbol(),OP_BUY,NormalizeDouble(lot_size_total_buy()+lot_size_total_buy()*Lots_Factor,2),Ask,3,0,0,NULL,MagicNumber,0,clrBlue);price=Ask;} //----EXECUTION OF CHARTCOMMENT FUNCTION---------------------------------------------------------------------------------------------- ChartComment(); } //+------------------------------------------------------------------+ //|MAIN FUNCTION ENDS HERE | //+------------------------------------------------------------------+ //--------------------------------------------------------------------------- // TO CLOSE ALL SELL POSITIONS FUNTIONS //--------------------------------------------------------------------------- void CloseSellPositions() { for(int b=OrdersTotal()-1; b >=0;b--) { OrderSelect(b,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) {OrderClose(OrderTicket(),OrderLots(),Ask,3,NULL);} } } //--------------------------------------------------------------------------- // CHART COMMENT FUNTION //--------------------------------------------------------------------------- void ChartComment() { Comment("\n GRID Trend EA ", "\nContact at +923152099871 / syedshanifahmed@gmail.com ", "\n___________________________________________ ", "\nCurrency Pair = ", Symbol(), "\nMagic Number = ", MagicNumber, "\nAccount info = ", AccountInfoString(ACCOUNT_SERVER), "\nServer Time = ", TimeToStr(TimeCurrent(), TIME_SECONDS), "\nAccount Balance = ", MathRound(AccountBalance()), "\nAccount Equuty = ", MathRound(AccountEquity()), "\nAccount Profit/Loss = ",(AccountEquity() - AccountBalance ()), "\nTotal Margin Used = ", AccountInfoDouble(ACCOUNT_MARGIN), "\nFree Margin = ", AccountInfoDouble(ACCOUNT_MARGIN_FREE), "\nOrders Total = ", OrdersTotal(), "\n____________________________________________ "); } //--------------------------------------------------------------------------- // PROFIT CHECK FUNTION //--------------------------------------------------------------------------- double ProfitCheck() { double profit=0; int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==MagicNumber) {profit+=OrderProfit()+OrderCommission()+OrderSwap();} } return(profit); } //--------------------------------------------------------------------------- // FUNCTION TO COUNT TOTAL NUMBER OF ORDERS BY EA //--------------------------------------------------------------------------- int CountOrder() { int orders=0; int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==MagicNumber) {orders++;} } return(orders); } //--------------------------------------------------------------------------- // FUNTION TO CALCULATE TOTAL LOT SIZE OF SELL TYPE ORDER BY EA //--------------------------------------------------------------------------- double lot_size_total_sell() { double lotsizetotal=0; int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==MagicNumber) if(OrderType()==OP_SELL) {lotsizetotal+=Initial_Lot;} } return(lotsizetotal); } //--------------------------------------------------------------------------- // FUNTION TO CALCULATE GRID SIZE FOR SELL TYPE ORDERS //--------------------------------------------------------------------------- double Grid_sell() { int gridsize=0; int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==MagicNumber) if(OrderType()==OP_SELL) {gridsize=Grid_Size;} } return(gridsize); } //--------------------------------------------------------------------------- // FUNTION TO CLOSE ALL BUY POSTIONS BY EA //--------------------------------------------------------------------------- void ClosebuyPositions() { for(int b=OrdersTotal()-1; b >=0;b--) { OrderSelect(b,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) {OrderClose(OrderTicket(),OrderLots(),Bid,3,NULL);} } } //--------------------------------------------------------------------------- // FUNTION TO CALCULATE TOTAL LOT SIZE OF BUY TYPE ORDER BY EA //--------------------------------------------------------------------------- double lot_size_total_buy() { double lotsizetotal=0; int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==MagicNumber) if(OrderType()==OP_BUY) {lotsizetotal+=Initial_Lot;} } return(lotsizetotal); } //--------------------------------------------------------------------------- // FUNTION TO CALCULATE GRID SIZE FOR BUY TYPE ORDERS //--------------------------------------------------------------------------- double Grid_buy() { int gridsize=0; int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==MagicNumber) if(OrderType()==OP_BUY) {gridsize=Grid_Size;} } return(gridsize); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register