Download MetaTrader 5

OrderSend, getting better price.

To add comments, please log in or register
HansHansen
19
HansHansen 2014.05.28 05: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 

The Bug

 

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??? 

Keith Watford
Moderator
9640
Keith Watford 2014.05.28 05:28  

TP and SL are not the same

TP is 25 Points (Ask+25)

SL is 25 Points plus the spread (Bid-25)

HansHansen
19
HansHansen 2014.05.28 05: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.

Keith Watford
Moderator
9640
Keith Watford 2014.05.28 06: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.

HansHansen
19
HansHansen 2014.05.28 06: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.

Still bug 

 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? 

Amir Yacoby
1195
Amir Yacoby 2014.05.28 08: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-SL
TP=ASK+TP 

HansHansen
19
HansHansen 2014.05.28 08: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-SL

TP=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.

Amir Yacoby
1195
Amir Yacoby 2014.05.28 08:51  

sorry - you get in at buy on the bid

Please try this
int Ticket = OrderSend(Symbol(), OP_BUY ,Lots, Ask, 3 ,(Bid - SL * Point) ,(Bid + TP * Point), "", 0, 0, clrGreen); 

HansHansen
19
HansHansen 2014.05.28 09: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? 

d4v3
35
d4v3 2014.05.28 09: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?

HansHansen
19
HansHansen 2014.05.28 11:31  

Thanks, now it's working.

I think maybe something with the trading server was wrong, or some other settings.

To add comments, please log in or register