OrderSend Error: 130

 

double stopLossPrice = NormalizeDouble(High[2]-0.2*(High[2]-Low[2]),Digits);
double takeProfitPrice = NormalizeDouble(High[2]+0.8*(High[2]-Low[2]),Digits);
double lotSize = OptimalLotSize(riskPerTrade,NormalizeDouble(High[2]+0.1*(High[2]-Low[2]),Digits),stopLossPrice);
openOrderID = OrderSend(NULL,OP_BUYLIMIT,lotSize,NormalizeDouble(High[2]+0.1*(High[2]-Low[2]),Digits),10,stopLossPrice,takeProfitPrice,NULL,magicNB);
if(openOrderID < 0) Alert("order rejected. Order error: " + GetLastError());


i keep getting OrderSend Error: 130 with this code but I cant seem to find the problem. Im backtesting on USDJPY. Any help would be appreciated.


2020.01.26 10:53:33.920    2020.01.21 00:00:00  Inside Bar Momentum Strategy USDJPY,Daily: Entry Price = 110.314
2020.01.26 10:53:33.920    2020.01.21 00:00:00  Inside Bar Momentum Strategy USDJPY,Daily: Stop Loss Price = 110.242
2020.01.26 10:53:33.920    2020.01.21 00:00:00  Inside Bar Momentum Strategy USDJPY,Daily: Take Profit Price = 110.484
2020.01.26 10:53:33.920    2020.01.21 00:00:00  Inside Bar Momentum Strategy USDJPY,Daily: OrderSend error 130
2020.01.26 10:53:33.920    2020.01.21 00:00:00  Inside Bar Momentum Strategy USDJPY,Daily: Alert: order rejected. Order error: 130

I have checked if the stops are too close to the entry price but they are not.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The...
 
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. openOrderID = OrderSend(NULL,OP_BUYLIMIT,lotSize, …
    Don't use NULL.
    • You can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not. OrderSenddoes not.
    • Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
    • Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
    • MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
Reason: