t/p is not working properly

 
ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,Ask+0.01,"BFS_Orders",0,0,Green);

 

ticket=OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,Bid-0.01,"Second_Orders",0,0,Green);

Hi,

  I'm running strategy tester.  I'm placing orders using above code in EURUSD.  Here I am fixing target of 100 pips for each and every trade. But I'm not getting it. Some times I get 102, -10, 78 etc...

232 2009.12.08 13:20 t/p 120 0.10 1.4762 0.0000 1.4762 98.96 21356.75

233 2009.12.11 14:30 t/p 113 0.10 1.4662 0.0000 1.4662 59.44 21416.19

234 2009.12.15 08:29 t/p 109 0.10 1.4562 0.0000 1.4562 26.16 21442.35

235 2009.12.17 02:02 t/p 104 0.10 1.4460 0.0000 1.4460 -5.04 21437.31

236 2009.12.17 09:46 t/p 103 0.10 1.4360 0.0000 1.4360 -6.08 21431.23

237 2009.12.22 15:47 t/p 102 0.10 1.4258 0.0000 1.4258 -10.24 21420.99

239 2010.01.04 01:44 t/p 121 0.10 1.4257 0.0000 1.4257 87.52 21508.51

301 2010.08.02 13:45 t/p 155 0.10 1.3130 0.0000 1.3130 129.70 23807.02

302 2010.08.03 08:14 t/p 154 0.10 1.3230 0.0000 1.3230 130.03 23937.05

304 2010.08.05 12:42 t/p 156 0.10 1.3230 0.0000 1.3230 100.00 24037.05

305 2010.08.06 14:08 t/p 153 0.10 1.3330 0.0000 1.3330 132.01 24169.06

Why is it happening? Thanks in advance. 

-Krishna. 


 

I can't explain the -10 but for the others...hmmm, maybe this? I'm not sure..: 

The OP_BUY seems right since you pay the spread immedately by buying at the Ask price,  but your OP_SELL isn't considering the the spread. You 'sell' at the bid price, bid price drops to Bid-0.1 (down 100 pips), then you 'buy back' at the ask price so the spread eats some of those 100 pips. If the broker is fixed spread, you can set the TP as    Bid-0.1-MarketInfo(Symbol(),MODE_SPREAD)

Besides that, the small errors like 102 etc. can be explained by:

1. slippage on the initial order (since the TP price is calculated from the price you are requesting the order with, not the actual price the order fills with)

2. the price might shoot past your TP in 1 tick

3. the price might move again while your close order is being filled 

 
alladir:

I can't explain the -10 but for the others...hmmm, maybe this? I'm not sure..: 

The OP_BUY seems right since you pay the spread immedately by buying at the Ask price,  but your OP_SELL isn't considering the the spread. You 'sell' at the bid price, bid price drops to Bid-0.1 (down 100 pips), then you 'buy back' at the ask price so the spread eats some of those 100 pips. If the broker is fixed spread, you can set the TP as    Bid-0.1-MarketInfo(Symbol(),MODE_SPREAD)

Besides that, the small errors like 102 etc. can be explained by:

1. slippage on the initial order (since the TP price is calculated from the price you are requesting the order with, not the actual price the order fills with)

2. the price might shoot past your TP in 1 tick

3. the price might move again while your close order is being filled 


Fine. But why the -ve(Loss) values are there.
 
krishna_gopal_2:

 

Hi,

  I'm running strategy tester.  I'm placing orders using above code in EURUSD.  Here I am fixing target of 100 pips for each and every trade. But I'm not getting it. Some times I get 102, -10, 78 etc...

232 2009.12.08 13:20 t/p 120 0.10 1.4762 0.0000 1.4762 98.96 21356.75

233 2009.12.11 14:30 t/p 113 0.10 1.4662 0.0000 1.4662 59.44 21416.19

234 2009.12.15 08:29 t/p 109 0.10 1.4562 0.0000 1.4562 26.16 21442.35

235 2009.12.17 02:02 t/p 104 0.10 1.4460 0.0000 1.4460 -5.04 21437.31

236 2009.12.17 09:46 t/p 103 0.10 1.4360 0.0000 1.4360 -6.08 21431.23

237 2009.12.22 15:47 t/p 102 0.10 1.4258 0.0000 1.4258 -10.24 21420.99

239 2010.01.04 01:44 t/p 121 0.10 1.4257 0.0000 1.4257 87.52 21508.51

301 2010.08.02 13:45 t/p 155 0.10 1.3130 0.0000 1.3130 129.70 23807.02

302 2010.08.03 08:14 t/p 154 0.10 1.3230 0.0000 1.3230 130.03 23937.05

304 2010.08.05 12:42 t/p 156 0.10 1.3230 0.0000 1.3230 100.00 24037.05

305 2010.08.06 14:08 t/p 153 0.10 1.3330 0.0000 1.3330 132.01 24169.06

Why is it happening? Thanks in advance. 

-Krishna. 


Where are these numbers come from ? It is you who are calculating it ? How ?
 

No idea :/  I have some questions though:

 It might just be my broker, but I can't set TP with OrderSent, I have to open the order then set SL and SP with OrderModify afterwards

 Also what happens with the losing traders? they just stay open forever?

 
alladir:

 Also what happens with the losing traders? they just stay open forever?


I'll be waiting till the trade closes with profit.
 
angevoyageur:
Where are these numbers come from ? It is you who are calculating it ? How ?

krishna_gopal_2:

I'll be waiting till the trade closes with profit.

So you don't need an explanation as you don't reply.
 
alladir:

I can't explain the -10 but for the others...hmmm, maybe this? I'm not sure..: 

The OP_BUY seems right since you pay the spread immedately by buying at the Ask price,  but your OP_SELL isn't considering the the spread. You 'sell' at the bid price, bid price drops to Bid-0.1 (down 100 pips), then you 'buy back' at the ask price so the spread eats some of those 100 pips. If the broker is fixed spread, you can set the TP as    Bid-0.1-MarketInfo(Symbol(),MODE_SPREAD)

Besides that, the small errors like 102 etc. can be explained by:

1. slippage on the initial order (since the TP price is calculated from the price you are requesting the order with, not the actual price the order fills with)

2. the price might shoot past your TP in 1 tick

3. the price might move again while your close order is being filled 

The Spread is effectively paid when the trade is exited.  There is no slippage in the Strategy Tester unless using a 3rd party tool to make it happen.  Price cannot move while a order is being processed . . .  it's the Strategy Tester.
 
krishna_gopal_2:

 

Hi,

  I'm running strategy tester.  I'm placing orders using above code in EURUSD.  Here I am fixing target of 100 pips for each and every trade. But I'm not getting it. Some times I get 102, -10, 78 etc...

232 2009.12.08 13:20 t/p 120 0.10 1.4762 0.0000 1.4762 98.96 21356.75

233 2009.12.11 14:30 t/p 113 0.10 1.4662 0.0000 1.4662 59.44 21416.19 


Where are you factoring in the Spread to your calculations ?  you understand that an OP_BUY is closed with a SELL ?  and that a SELL happens at Bid ?
 
RaptorUK:
The Spread is effectively paid when the trade is exited.  There is no slippage in the Strategy Tester unless using a 3rd party tool to make it happen.  Price cannot move while a order is being processed . . .  it's the Strategy Tester.

That's my point, with the OP_SELL he takes 100 pips and THEN pays the spread, so the final profit won't be 100 expected.

The OP_BUY is fine since he starts calculating from the initial Ask price. 

 

 

RaptorUK:
There is no slippage in the Strategy Tester unless using a 3rd party tool to make it happen.  Price cannot move while a order is being processed . . .  it's the Strategy Tester.

Ah yeh I forgot about that, I haven't actually used back testing yet :o
 
Fine. Now what should I do to get more or less 100pips. Is there any formula to calculate Spread? 
Reason: