Missing money ...

 

Hi guys i observed a difference of profit when using a close order vs using a take profit.Let me explain how i did:

I constructed an ea with 2 types of settings:

1) STOPLOSS at 100 pips and closing orders with orderclose() function at 100 pips (profit)

2) STOPLOSS at 100 pips and closing orders at the classical TAKEPROFIT level of 100 pips (profit)


And there was a difference between the results.The entry sign was just a normal EMA period 2 and EMA period 4 cross in both cases so basically it should have the same results,but it didnt.Now i would like to point out that the backtest was done with 10 pip (i have a 5 decimal broker) fixed spread in both cases, so no spread fluctuation was present.

The other issue should have been the slippage with the orderclose, but i figured out the slippage of the Orderclose() function was set to like 9999 because it doesnt really matter, if i set it too tight like to 5 it will cause orderclosing errors because the price is more volatile than that, so its just better to keep a very high value there.

While the slippage value of the OrderSend() was set from 1 pip to 20 pips and basically not much difference was neither here, because the OrderSend() max slippage was the same in both experiments, so not this is the problem.

So this being said, lets recap, we ruled out the ordersend slipapge because it was the same in both cases, and the orderclose slippage because it's irrelevant in this.And we also used fixed spread of 10 pipettes =1 pip, so there was no spread fluctuation.Yet i had different results, here are them:


WITH ORDERCLOSE() AT 100 PIPS
WITH TAKEPROFIT AT 100 PIPS
Bars in test 375192
Bars in test 375192
Ticks modelled 41344089
Ticks modelled 41344089
Modelling quality 25.00%
Modelling quality 25.00%
Mismatched charts errors 0
Mismatched charts errors 0
Initial deposit 10000
Initial deposit 10000
Total net profit -1034.97
Total net profit -1030
Gross profit 4263.03
Gross profit 4485
Gross loss -5298
Gross loss -5515
Profit factor 0.8
Profit factor 0.81
Expected payoff -0.1
Expected payoff -0.1
Absolute drawdown 1035.54
Absolute drawdown 1030
Maximal drawdown 1038.91 (10.39%)
Maximal drawdown 1035.57 (10.35%)
Relative drawdown 10.39% (1038.91)
Relative drawdown 10.35% (1035.57)
Total trades 10000
Total trades 10000
Short positions (won %) 5028 (48.03%)
Short positions (won %) 5028 (45.84%)
Long positions (won %) 4972 (46.00%)
Long positions (won %) 4972 (43.85%)
Profit trades (% of total) 4702 (47.02%)
Profit trades (% of total) 4485 (44.85%)
Loss trades (% of total) 5298 (52.98%)
Loss trades (% of total) 5515 (55.15%)

Largest

Largest
profit trade 1.14
profit trade 1
loss trade -1
loss trade -1

Average

Average
profit trade 0.91
profit trade 1
loss trade -1
loss trade -1

Maximum

Maximum
consecutive wins (profit in money) 15 (13.97)
consecutive wins (profit in money) 14 (14.00)
consecutive losses (loss in money) 16 (-16.00)
consecutive losses (loss in money) 21 (-21.00)

Maximal

Maximal
consecutive profit (count of wins) 13.97 (15)
consecutive profit (count of wins) 14.00 (14)
consecutive loss (count of losses) -16.00 (16)
consecutive loss (count of losses) -21.00 (21)

Average

Average
consecutive wins 2
consecutive wins 2
consecutive losses 2
consecutive losses 3



The question is where did that 9-10 cents of money went (in the average profit) from the 1st table, why is 9 cents missing when using orderclose insead of takeprofit ?

Arent they both entering in the trade at the BID & ASK levels like are they supposed to, not the market price level ? Because the fix spread was 10 pips so they substract the spread again, because it seems that the one with OrderClose() enters at the market price level and it substracts the spread at the end twice?

So when and how is the spread payed in both cases?

 

As far as I understand about the strategy tester....

When you have an order with a set TP or SL, the ST will close the order at that exact price.

Without a set TP or SL, the ST may not create a pseudo- tick at that exact price and so will close the order at the nearest tick that breaks the level calculated by the code.

 
GumRai:

As far as I understand about the strategy tester....

When you have an order with a set TP or SL, the ST will close the order at that exact price.

Without a set TP or SL, the ST may not create a pseudo- tick at that exact price and so will close the order at the nearest tick that breaks the level calculated by the code.

So you say that this problem is because of the inaccuracy of the OrderClose() or that if the price is very volatile it will quickly change value and therefore until the OrderClose order is sent to the broker the price will change.So in short, it can be said that is because of the lag,since a TP or SL level is actually known and registered at the broker,therefore he can react to it much quicker than a close order which comes from my pc and until it gets to the broker, that few miliseconds do actually this damage.

However this would mean that the average price should be at a random deviation from the target of 1$ with the deviation of +- 10 cents, which at the end should be 50% of the time i get 1.1$ on average and 50% of the time i get 0.9$ on the average.But this is not what happens, what happens it is that it will ALWAYS be less than the target.I ran the program many times and the average way always less than the target close value?


Why?

Here is the if which closes the BUY and SELL orders, to see whats really going on

Closing BUY

if(Ask-OrderOpenPrice()>=CLOSEPROFITPIPS*Point)

////////////////////////////////////////////////////////////

Closing SELL

if(OrderOpenPrice()-Bid>=CLOSEPROFITPIPS*Point)

Also note that i use a sample of 10.000 trades so that gives this more accuracy so the set of data is ok to draw a conclusion.

 

That code is your problem. Buy orders close at the bid price, you should do close buys if( Bid-OrderOpenPrice() >= TakeProfitInPips*Point)

Your code would close the order the spread short of the TP you wanted. Your sell close code needs to be modified too for the same reason.

 
SDC:

That code is your problem. Buy orders close at the bid price, you should do close buys if( Bid-OrderOpenPrice() >= TakeProfitInPips*Point)

Your code would close the order the spread short of the TP you wanted. Your sell close code needs to be modified too for the same reason.

Hmm interesting, i didnt know that they close at the opposite side.Now i have to modify all my EA's.Thanks for the info, so to clear it out:

BUY order OrderSend() at ASK price

SELL order OrderSend() at BID price

BUY order OrderClose) at BID price

SELL order OrderClose() at ASK price

Right? :D

 

yes they close at the opposite side like that

 
  1. You can also use OrderClosePrice() instead of Bid/Ask in OrderClose()
  2. The tester does not simulate slippage, or gaps so your orders were closed exactly at TP while you closed order when the market ticked above the TP.
 
WHRoeder:
  1. You can also use OrderClosePrice() instead of Bid/Ask in OrderClose()
  2. The tester does not simulate slippage, or gaps so your orders were closed exactly at TP while you closed order when the market ticked above the TP.

Ok the OrderClosePrice() is the simplest, i hope it will be accurate.
 
Proximus:

Ok the OrderClosePrice() is the simplest, i hope it will be accurate.
Of course it will but you must OrderSelect() first . . .
 
Simon Gniadkowski:
Of course it will but you must OrderSelect() first

i tried to close a trade in 0.10 cents profit..bt my account balance is still minus...thou the trade successfully closed in 10 cents profit..the account balance is in loss...??...wht is the perfect way to close in  10 cents profit..is any professonal coder here to explain me

Reason: