Edit Your Comment
Help with OrderSend( ) Function
Jan 04, 2011 at 01:50
Medlem sedan Jan 04, 2011
2 inlägg
New to mql4, I wrote the following code for practice, but can't figure out why I get an Error 130
I think it has to do with unNormalized numbers. I'm using IBFX broker and they use the 5th decimal on the price.
double Stoploss = 50;
double Takeprofit = 50;
int start()
{
int ticket = OrderSend(Symbol(),OP_BUY,1.0,Ask,3,Ask-Stoploss*Point,
Ask+Takeprofit*Point,'Order #1',1234,0,Red);
if(ticket == -1) Print('error-',GetLastError());
return(0);
}
I also tried setting SL and TP to 500 because of the 5th decimal but got the same error. Any suggestions? Thanks
I think it has to do with unNormalized numbers. I'm using IBFX broker and they use the 5th decimal on the price.
double Stoploss = 50;
double Takeprofit = 50;
int start()
{
int ticket = OrderSend(Symbol(),OP_BUY,1.0,Ask,3,Ask-Stoploss*Point,
Ask+Takeprofit*Point,'Order #1',1234,0,Red);
if(ticket == -1) Print('error-',GetLastError());
return(0);
}
I also tried setting SL and TP to 500 because of the 5th decimal but got the same error. Any suggestions? Thanks
Medlem sedan Aug 20, 2009
266 inlägg
Jan 04, 2011 at 02:58
(redigerad Jan 04, 2011 at 03:04)
Medlem sedan Aug 20, 2009
266 inlägg
double Stoploss = 50;
double Takeprofit = 50;
int start()
{
int ticket = OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,0,'Order #1',1234,0,Red);
if(ticket == -1) Print('error-',GetLastError());
else OrderModify(ticket,OrderOpenPrice(),Ask-50*Point*10,Ask+50*Point*10,CLR_NONE);
return(0);
}
You are probably dealing with a market execution broker(I don't use IBFX, so I am not sure). That means that you can only enter a stoploss & takeprofit AFTER they return a trade to you. This is simply because you do not know what price you will recieve from them......with market execution your slippage is unlimited.....you takes what you get.
As an en exercise try replacing your ordersend with this 'priceless' order........
int ticket = OrderSend(Symbol(),OP_BUY,1.0,0,0,0,0,'Order #1',1234,0,Red);
It still comes back with a price, meaning that asking price & slippage are ignored. The reason for this is simple, it is not used by the broker at all.....as I said, you take what you get. The reason it still exists is because metaquotes could not remove it from the code without causing massive incompatibilities with our instant execution bokers.
That said, I always still use the correct bid and ask prices for backwards compatibility with the instant execution brokers.
As far as normalising prices go, people tend to go overboard with this......stops do not need to be need to be normalised but I do it anyway as a good practice. When you have a problem caused by unnormalised doubles and price, you will get an error 129 which is invalid price rather than error 130 which is an incorrectly calculated stop. I don't think I have seen an error 129 since I gave up the instant execution brokers.
In terms of your 5 digit broker, you should use Point*10 since the code does not care about the 5 digits.....it simply has recalculated your stops as 5 pips instead of 50 pips. It is good practice to define your pips sizes in the init() function of your EA, so you would have variable 'Pip' declared at the start(global scope) of the EA and then assign it a value in your init() function like this :-
Pip = Point * 10;
Then when you want to turn your 'human pip' stops into 'computer pips' you simply say :-
double Stoploss = 50;
Stoploss = Stoploss * Pip;
Anyway, hope it helps.
double Takeprofit = 50;
int start()
{
int ticket = OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,0,'Order #1',1234,0,Red);
if(ticket == -1) Print('error-',GetLastError());
else OrderModify(ticket,OrderOpenPrice(),Ask-50*Point*10,Ask+50*Point*10,CLR_NONE);
return(0);
}
You are probably dealing with a market execution broker(I don't use IBFX, so I am not sure). That means that you can only enter a stoploss & takeprofit AFTER they return a trade to you. This is simply because you do not know what price you will recieve from them......with market execution your slippage is unlimited.....you takes what you get.
As an en exercise try replacing your ordersend with this 'priceless' order........
int ticket = OrderSend(Symbol(),OP_BUY,1.0,0,0,0,0,'Order #1',1234,0,Red);
It still comes back with a price, meaning that asking price & slippage are ignored. The reason for this is simple, it is not used by the broker at all.....as I said, you take what you get. The reason it still exists is because metaquotes could not remove it from the code without causing massive incompatibilities with our instant execution bokers.
That said, I always still use the correct bid and ask prices for backwards compatibility with the instant execution brokers.
As far as normalising prices go, people tend to go overboard with this......stops do not need to be need to be normalised but I do it anyway as a good practice. When you have a problem caused by unnormalised doubles and price, you will get an error 129 which is invalid price rather than error 130 which is an incorrectly calculated stop. I don't think I have seen an error 129 since I gave up the instant execution brokers.
In terms of your 5 digit broker, you should use Point*10 since the code does not care about the 5 digits.....it simply has recalculated your stops as 5 pips instead of 50 pips. It is good practice to define your pips sizes in the init() function of your EA, so you would have variable 'Pip' declared at the start(global scope) of the EA and then assign it a value in your init() function like this :-
Pip = Point * 10;
Then when you want to turn your 'human pip' stops into 'computer pips' you simply say :-
double Stoploss = 50;
Stoploss = Stoploss * Pip;
Anyway, hope it helps.
Wealth Creation Through Technology
Jan 04, 2011 at 03:29
Medlem sedan Jan 04, 2011
2 inlägg
Thanks for the input.. sounds like you know what you're doing.. I'll give it a try tonight
Just curious.. why did you give up on instant execution brokers?
Thanks again
Just curious.. why did you give up on instant execution brokers?
Thanks again
Medlem sedan Aug 20, 2009
266 inlägg
Jan 04, 2011 at 03:47
Medlem sedan Aug 20, 2009
266 inlägg
Hi John,
I do mainly asian scalping and I have found that the filtered price feed from instant execution brokers don't work so well. Maybe that has changed in the last year or so but I have found a couple of market execution brokers that work well and I have never felt the need to look back.
The price feed from STP/ECN brokers tend to be more 'raw' and scalpers like this. If you have any doubts about the levels of filtering, have a look at what happens to price feeds at rollover time(5pm EST) and you will get the picture. Compare that with a broker like Jade where you can experience rollover spikes of up to 160 pips(EURCHF once). MB Trading actually disconnect for up to 10 minutes over this period which used to piss me off no end until I eventually understood that this is in my best interest.
Anyway, bottomline is that the spikiness is the benefit and the rollover spikes are the risk. You don't get either at an instant execution broker and nor do you get the profits.
I do mainly asian scalping and I have found that the filtered price feed from instant execution brokers don't work so well. Maybe that has changed in the last year or so but I have found a couple of market execution brokers that work well and I have never felt the need to look back.
The price feed from STP/ECN brokers tend to be more 'raw' and scalpers like this. If you have any doubts about the levels of filtering, have a look at what happens to price feeds at rollover time(5pm EST) and you will get the picture. Compare that with a broker like Jade where you can experience rollover spikes of up to 160 pips(EURCHF once). MB Trading actually disconnect for up to 10 minutes over this period which used to piss me off no end until I eventually understood that this is in my best interest.
Anyway, bottomline is that the spikiness is the benefit and the rollover spikes are the risk. You don't get either at an instant execution broker and nor do you get the profits.
Wealth Creation Through Technology
*Kommersiell användning och skräppost tolereras inte och kan leda till att kontot avslutas.
Tips: Om du lägger upp en bild/youtube-adress bäddas den automatiskt in i ditt inlägg!
Tips: Skriv @-tecknet för att automatiskt komplettera ett användarnamn som deltar i den här diskussionen.