OrderSend error 4051, can you help me?

 

Hi, my expert gives me the error 4051, so, there is some problem with the lot amount, but I could not fix it, can you help me out?

The expert was working fine until I put this function into the order send.

Thanks

ticket=OrderSend(Symbol(),
                          OP_SELL,
                          inteligent_Lot(),
                          Bid,
                          3,
                          0,
                          iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0),
                          "R",
                          Magic.Number,
                          0,
                          Red);

//--------------------------------------------------//


double inteligent_Lot()
   {
      double lot;
      double Last.Return[];
      double Last_2.Return[];
      double Last_3.Return[];
      for(int iPos=OrdersHistoryTotal()-1; iPos >= 0 ; iPos--) 
        {
            if 
            (OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)      // Only orders w/
            &&  OrderMagicNumber() == Magic.Number                  // my magic number
            &&  OrderSymbol()      == Symbol()                      // and my pair.
            &&  OrderType()        <= OP_SELL// Avoid cr/bal forum.mql4.com/32363#325360
            )
               {
               Last.Return[iPos]=OrderProfit();                 // my last trade result
               Last_2.Return[iPos-1]=OrderProfit();             // my penultimate result
               Last_3.Return[iPos-2]=OrderProfit();             // my ante penultimate result
                  if(Last.Return[iPos]>0 && Last_2.Return[iPos]>0)       // win in my last two trades
                  {
                     lot=NormalizeDouble(LotsOptimized()/3,2);
                  }
                  else
                  {
                     lot=LotsOptimized();
                  }
               }
               
               
        }
 
 
yes... I already read it.... it means Invalid function parameter value, but I'm using the same structure that the last function that I had into my OrderSend. For this reason I'm confused.
 

first your code cannot be compiled

second your function returns nothing so, inteligent_Lot() = 0

 
I don't see a return value for that function at all, so that maybe your problem. You need to use return(lots) at the end so that actually returns something. At the moment, I assumes it's just returning a null or something.
 
o, 1 more thing, the next error could be 130 so, check here & here
 
qjol:

first your code cannot be compiled

second your function returns nothing so, inteligent_Lot() = 0

Looking at the braces there seems to be some code missing from that function . . .
 
Please show the code for LotsOptimized()
 
RaptorUK:
Please show the code for LotsOptimized()
even with LotsOptimized() the function inteligent_Lot() = 0
 
double Last.Return[];
double Last_2.Return[];
double Last_3.Return[];
:
Last.Return[iPos]=OrderProfit();                 // my last trade result
Last_2.Return[iPos-1]=OrderProfit();             // my penultimate result
Last_3.Return[iPos-2]=OrderProfit();             // my ante penultimate result
  1. These arrays have no size and you never give them any with ArrayResize()
  2. Why are you setting the same value to 3 different arrays in 3 different positions?
 
qjol:
even with LotsOptimized() the function inteligent_Lot() = 0
You can't see the final brace, there may be a return value, just not posted in this thread.