# OrderSend, getting better price.

19

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)
else

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

Moderator
9958

TP and SL are not the same

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

19

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.

Moderator
9958

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.

19

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);

if(Ticket>0)
else

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?

1193

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:

You need to change the code to -

19

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:

`   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.

1193

sorry - you get in at buy on the bid

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

19

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 ,(Bid - SL * Point) ,(Bid + TP * Point), "", 0, 0, clrGreen);

if(Ticket>0)
else

return(0);
}```

Its even worse now.

Profit 13, loss is 42 for each trade.

Could you maybe test my code?

35

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?

19

Thanks, now it's working.

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