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.
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.
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
- You can also use OrderClosePrice() instead of Bid/Ask in OrderClose()
- 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.
- You can also use OrderClosePrice() instead of Bid/Ask in OrderClose()
- 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.
Ok the OrderClosePrice() is the simplest, i hope it will be accurate.
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

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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:
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:
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?