Help with error in Code

 

I tried to place an run my EA last night during London Market on the EURJPY pair but I get an error4051 (invalid parameters in Ordersend). It shows that my lot size is 0. Is there something wrong on how I calculate my lots in my code.


 RiskAmount = AccountEquity()*(EquityPercent / 100);
              TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
              if(Point == 0.001 || Point == 0.00001)TickValue *= 10;
              
              CalcLots = (RiskAmount/StopLoss) / TickValue;
              LotSize = CalcLots;
      
      SL = Bid + (StopLoss*PipPoint(Symbol()));
      TP = (R3 + R2)/2;
     // TP = MarketInfo("EURUSD",MODE_ASK) + (TakeProfit*PipPoint("EURUSD"));
      Ticket1 = OpenSellOrder(Symbol(), LotSize, GetSlippage(Symbol(),Slippage),SL,TP, MagicNumber,  "Buy Order");
      Ticket2 = OpenSellOrder(Symbol(), LotSize, GetSlippage(Symbol(),Slippage),SL,0, MagicNumber,  "Buy Order");
 
Are CalcLots and LotSize both declared as double ? or int ?
 
RaptorUK:
Are CalcLots and LotSize both declared as double ? or int ?

Both are doubles
 
What about in the definition of the OpenSellOrder function ?
 
RaptorUK:
What about in the definition of the OpenSellOrder function ?


int OpenSellOrder(string argSymbol, double argLotSize, double argSlippage,double argSL,double argTP ,int argMagicNumber, string argComment = "Sell Order")
        {
                while(IsTradeContextBusy()) Sleep(10);

                // Place Sell Order
                int Ticket = OrderSend(argSymbol,OP_SELL,argLotSize,MarketInfo(argSymbol,MODE_BID),argSlippage,argSL,argTP,argComment,argMagicNumber,0,Red);

                // Error Handling
                if(Ticket == -1)
                        {
                                int ErrorCode = GetLastError();
                                string ErrDesc = ErrorDescription(ErrorCode);

                                string ErrAlert = StringConcatenate("Open Sell Order - Error ",ErrorCode,": ",ErrDesc);
                                Alert(ErrAlert);

                                string ErrLog = StringConcatenate("Bid: ",MarketInfo(argSymbol,MODE_BID)," Ask: ",MarketInfo(argSymbol,MODE_ASK)," Lots: ",argLotSize);
                                Print(ErrLog);
                        }

                return(Ticket);
        } 
 
Sorry, I don't see what is causing your problem . . . what I would suggest is ad a Print() statement after LotSize = CalcLots; to print all the variables involved in calculating CalcLots then see if all the values are what you expect.
 

Replace

LotSize = CalcLots;

to

LotSize = NormalizeDouble(CalcLots,2);
if(LotSize<0.01)LotSize=0.01;

and remember - TP in sell-order should be less then open-price.

 
RaptorUK:
Sorry, I don't see what is causing your problem . . . what I would suggest is ad a Print() statement after LotSize = CalcLots; to print all the variables involved in calculating CalcLots then see if all the values are what you expect.

I think I see where the problem is. My entry is based on the pivots but for some reason my pivot values are wrong. Can you see where my code is err. I used the pivots from https://www.mql5.com/en/code/8685

the input is -2 since my server is GMT+2.

I am trying make the pivots from London open to London open. for some reason it does not work. I am trying to run it on July 26, 2011 on strategy tester but no results

Reason: