I'm trying to insert a takeprofit
and stoploss
argument in my SendOrder()
function, but I'm getting the following error:
Order Sent Failed with Error #130
This is my code:
extern double takeprofit = 30.0;
extern double stoploss = 20.0;
stoploss = NormalizeDouble( stoploss, 5 ); // SET stop loss
Print( "stoploss", stoploss );
takeprofit = NormalizeDouble( takeprofit, 5 ); // SET take profit
ticket = OrderSend( Symbol(),
OP_SELL,
lotsize,
Ask,
100,
stoploss,
takeprofit,
0,
0,
0,
CLR_NONE
);
if ( ticket < 0 ) {
Print( "Order send failed with error #", GetLastError() );
}
else Print( "Order send sucesso!!" );
I already checked documentation for the function NormalizeDouble()
, but I'm still getting the error.
What should I do?
A ) Fully comply with the MQL4
OrderSend()
syntax requirementsYour code fails at setting a correct SHORT trade Entry-Price, as it shall read rather
Bid
, notAsk
( this error is hidden as it is effectively masked-out by a rather cosmic distance of 100 points in a tolerable slippage distance from the said price ).Your code fails at assigning
int
(0
) in place, wherestring
is expected.B) Error 130: == "invalid stops"
You shall verify with your Broker a few details:
OrderSend()
one-stop-instruction, incl, TP & SL, or does the Broker T&C require to first open a trade-position & only after that happens to allow anOrderModify()
instruction to setup TP & SL price-levels?STOPLEVEL
&FREEZELEVEL
distances, within which Broker rejects any TP & SL setup(s) or modification(s) thereof.C) A good practice is not to assign into
extern
iterator-variablesWhile this is not a root-cause for your trouble, do get accustomed with an industry best practices, one of which is not to assign any value to a declared
extern
. Rather declare your own variable, that you control scope & assignments thereof, but leaveextern
(s) un-touched from your code side.