error 4051

don lindsey
51
don lindsey  
I’m trying to write an ea based on a change in direction of the Awesome Oscillator.
I am using the “MACD Sample” ea that is comes with the MT4 platform and changing the indicators from MACD to iAO.
When I back-test it fails to trade and gives the error as 4051
ERR_INVALID_FUNCTION_PARAMETER_VALUE 4051 Invalid function parameter value.
and says it’s an invalid lots amount for OrderSend function
My OrderSend function is
Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,”eaname”,magic.0,Red);
With Lots previously defined as
Lots=NormalizeDouble(AccountFreeMargin()/10000,1):
Can someone please give me a clue as to how to fix this?
Also, it seems to want to trade every few seconds, even when I’m back-testing on a 4H chart.
William Roeder
25313
William Roeder  
Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"eaname",magic.0,Red);
You have volume=Lots, slippage=3, TP=TakeProfit*Point.
  1. Is Lots at least MarketInfo(Symbol(), MODE_MINLOT )
  2. Are you adjusting for a 5 digit broker TP, SL, and slippage. TP must be at least MathMax( MarketInfo(Symbol(), MODE_STOPLEVEL)*Point (usually 3 pips) away from the open and the open can be up to slippage away from Bid
    //++++ These are adjusted for 5 digit brokers.
    double  pips2points,    // slippage  3 pips    3=points    30=points
            pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    

  3. Lots=NormalizeDouble(AccountFreeMargin()/10000,1):
    This only works if MarketInfo(Symbol(), MODE_LOTSTEP) = 0.1 exactly. On IBFX lot step is 0.01;
    double lots    = AccountFreeMargin()/10000,
           minLot  = MarketInfo(Symbol(), MODE_MINLOT),
           LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
           lots    =  MathFloor(lots/LotStep)*LotStep;
           if (lots < minLot){ ...// Insufficient margin.
    

don lindsey
51
don lindsey  
WHRoeder:
You have volume=Lots, slippage=3, TP=TakeProfit*Point.
  1. Is Lots at least MarketInfo(Symbol(), MODE_MINLOT )
  2. Are you adjusting for a 5 digit broker TP, SL, and slippage. TP must be at least MathMax( MarketInfo(Symbol(), MODE_STOPLEVEL)*Point (usually 3 pips) away from the open and the open can be up to slippage away from Bid

  3. This only works if MarketInfo(Symbol(), MODE_LOTSTEP) = 0.1 exactly. On IBFX lot step is 0.01;


Thanks for your help. I'm not quite sure how to incorporate your suggestions, but I think I can figure it out. Thanks again.