English

## OrderSend, getting better price.

 6 HansHansen 2014.05.28 07:03   Hello,I am a C++ programmer and completely new to mql4 and I like it very much. There is a strange problem with all my Expert Advisors. I made this extremely simple EA to demonstrate the bug.```input double SL = 25.0; input double TP = 25.0; input double Lots = 1.0; int OnInit() {    return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } int start() {      int Total=OrdersTotal();       if (Total>0)       return(0);       int Ticket = OrderSend(Symbol(), OP_BUY ,Lots, Ask, 3 ,(Bid - SL * Point) ,(Ask + TP * Point), "", 0, 0, clrGreen);       if(Ticket>0)       Alert("BUY : ",Ticket);    else       Alert("BUY Error: ",GetLastError());        return(0); }```Normally I expect this one to do whether wins nor losses. But it does lose all Money it gets.The Reason for this is simple  Every loss is more than twice as big as each profit.As you see in the Code the TP and SL limits have the same size.  Why dont't have loss and profit the same size???
 Moderator3501 GumRai 2014.05.28 07:28 #   TP and SL are not the sameTP is 25 Points (Ask+25)SL is 25 Points plus the spread (Bid-25)
 6 HansHansen 2014.05.28 07:45 #   I tried:`   int Ticket = OrderSend(Symbol(), OP_BUY ,Lots, Ask, 3 ,(Ask - SL * Point) ,(Ask + TP * Point), "", 0, 0, clrGreen);` There is only a marginal difference.  The loss is still twice as big as the profit.
 Moderator3501 GumRai 2014.05.28 08:39 #   HansHansen: I tried: There is only a marginal difference.  The loss is still twice as big as the profit. I don't see how that is possible.If a buy trade with a sl at Ask -25 Points and tp of Ask+ 25 Points, losses should be  the same as wins, maybe a bit off because of marginal slippage.
 6 HansHansen 2014.05.28 08:52 #   Thank you guys for the fast help.The total code now: ```#property description "SimpleEA" #property version   "000.001" input double SL = 25.0; input double TP = 25.0; input double Lots = 1.0; int OnInit() {    return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } int start() {      int Total=OrdersTotal();       if (Total>0)       return(0);       int Ticket = OrderSend(Symbol(), OP_BUY ,Lots, Ask, 3 ,(Ask - SL * Point) ,(Ask + TP * Point), "", 0, 0, clrGreen);       if(Ticket>0)       Alert("BUY : ",Ticket);    else       Alert("BUY Error: ",GetLastError());        return(0); }```  That is what i get in when testing.  The bug still occurs. A slippage that is doubling the losses is quite unusual isn't it? Can someone maybe test my code? Maybe there is no bug in the code, maybe the bug is elsewhere?But there definitely is a bug?
 53 amir_avatar 2014.05.28 10:07 #   HansHansen: Thank you guys for the fast help.The total code now:   That is what i get in when testing.  The bug still occurs. A slippage that is doubling the losses is quite unusual isn't it? Can someone maybe test my code? Maybe there is no bug in the code, maybe the bug is elsewhere?But there definitely is a bug?   The bug is in your code:Ask is the higher price, and is the price that actually you get in when you buy. So, when you buy you already lost the spread. You need to change the code to - SL=ASK-SLTP=ASK+TP
 6 HansHansen 2014.05.28 10:29 #   Sorry, I don't get what you mean. Removing the Points Factor? This don't works as all.In my new code i am using: SL=ASK-SLTP=ASK+TP  `   int Ticket = OrderSend(Symbol(), OP_BUY ,Lots, Ask, 3 ,(Ask - SL * Point) ,(Ask + TP * Point), "", 0, 0, clrGreen);` Or i am not? The bug still occurs.
 53 amir_avatar 2014.05.28 10:51 #   sorry - you get in at buy on the bidPlease try this int Ticket = OrderSend(Symbol(), OP_BUY ,Lots, Ask, 3 ,(Bid - SL * Point) ,(Bid + TP * Point), "", 0, 0, clrGreen);
 6 HansHansen 2014.05.28 11:20 #   Hey, thanks.Its not helping. My complete code again:```#property description "SimpleEA" #property version   "000.001" input double SL = 25.0; input double TP = 25.0; input double Lots = 1.0; int OnInit() {    return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } int start() {      int Total=OrdersTotal();       if (Total>0)       return(0);       //int Ticket = OrderSend(Symbol(), OP_BUY ,Lots, Ask, 3 ,(Ask - SL * Point) ,(Ask + TP * Point), "", 0, 0, clrGreen);    int Ticket = OrderSend(Symbol(), OP_BUY ,Lots, Ask, 3 ,(Bid - SL * Point) ,(Bid + TP * Point), "", 0, 0, clrGreen);       if(Ticket>0)       Alert("BUY : ",Ticket);    else       Alert("BUY Error: ",GetLastError());        return(0); }``` Its even worse now.Profit 13, loss is 42 for each trade.Could you maybe test my code?
 16 d4v3 2014.05.28 11:57 #   I've tested your code with the TP and SL based on the Ask price and get profits and losses of the same value (as you would expect).Perhaps you should try a clean install of MT4?
 6 HansHansen 2014.05.28 13:31 #   Thanks, now it's working.I think maybe something with the trading server was wrong, or some other settings.