Discrepancy between Strategy Tester and Live Demo

 
I have recently created an EA that works great in the strategy tester but is behaving very oddly in the live demo.
The program is coded to close all open orders if the Account Equity is greater than the Account Balance. In the strategy tester, this means that when it closes my open orders I always end up with a profit. However, in the live demo it is closing open orders at a loss! How can the exchange net a loss if the Account Equity is greater than the Account Balance? A swift response would be greatly appreciated!
 
For some reason I could not make the initial post show up, so I wrote this in the reply...:

Hi,
I have recently created an EA that works great in the strategy tester but is behaving very oddly in the live demo.
The program is coded to close all open orders if the Account Equity is greater than the Account Balance. In the strategy tester, this means that when it closes my open orders I always end up with a profit. However, in the live demo it is closing open orders at a loss! How can the exchange net a loss if the Account Equity is greater than the Account Balance? A swift response would be greatly appreciated!
 
mfurlender:
I have recently created an EA that works great in the strategy tester but is behaving very oddly in the live demo.
The program is coded to close all open orders if the Account Equity is greater than the Account Balance. In the strategy tester, this means that when it closes my open orders I always end up with a profit. However, in the live demo it is closing open orders at a loss! How can the exchange net a loss if the Account Equity is greater than the Account Balance? A swift response would be greatly appreciated!

In the Tester it takes zero time to close the orders (everything is done instantaneously within a single tick), there is no slippage and the spread is fixed. In live/demo it takes time to close the orders (during which prices change), close prices might be slipped and spread is variable (with most brokers). Those are the main reasons...


p.s. u can delete the previous bad post if u want... when u hover over the post u have the option to edit or delete it in the top right hand corner...

 
But it is not possible that, say, in the strategy tester it registers a profit when in fact due to the bid/ask spread it would be a loss? If the account equity is greater than the account balance and the orders are closed, it should truly yield a net gain, right?
 
mfurlender:
But it is not possible that, say, in the strategy tester it registers a profit when in fact due to the bid/ask spread it would be a loss?

In the Tester, just as in live/demo, the spread is factored in when calculating the profit. But again - the spread is fixed in the Tester, there is no slippage, time is discrete and there are no delays or errors. All these account for the differences.


If the account equity is greater than the account balance and the orders are closed, it should truly yield a net gain, right?

Yes. But in live/demo u should give a margin for all the phenomenons I mentioned.
 
So you are basically saying that I should close the orders when Account Equity > Previous Balance + Margin for slippage ?
My take profit was 5 and my slippage was 3, so I could totally see how that could have caused the discrepancy. I changed it to 0, so it should probably work now...
 
I'd be saying that you should close your orders based on your original criteria, assume that you will have a certain amount of slippage with each transaction and calculate your projected profit and loss accordingly.

CB
 
mfurlender:
So you are basically saying that I should close the orders when Account Equity > Previous Balance + Margin for slippage ?

There are 2 factors in affect here - the first is the trading strategy and the second is the technical aspects of trading. The first suggests the theoretical criteria for closing the orders. But the second suggests that because of technical reasons, u have to give a margin over your original closing criteria so as to overcome a possible deviation in the result.

MT4 is a relatively 'slow' platform, latency wise. Closing several orders takes a few seconds. Each and every one of them might be slipped, they might have errors or experience various delays, spread and price might change during that time... So u must add a margin to your criteria to overcome these.


My take profit was 5 and my slippage was 3, so I could totally see how that could have caused the discrepancy. I changed it to 0, so it should probably work now...

That depends on many factors. Some brokers ignore the slippage parameter... With the ones that don't u r likely to get re-quotes once u set the slippage to zero. Remember that u won't experience slippage or re-quotes in the Tester.

Reason: