Problem With Back testing

 
Hello all expert coders,

I wrote an ea to move away from spending countless hours on the monitors. I am doing some back testing but whenever I run a back test i get the following error:
Warning : Can not execute new OP_SELL order for Symbol EURUSD. Maximum number of 1 open positions reached.

Now the strange thing is that if i run it on demo/live account, it works fine and does what is meant for. So you may ask what is the problem? Well I would like to add some more logic such as a trade manager and few more things, and guess i need to do the back testing to reach confidence to go live trading.

i have attached the code, thanks in advance for any help provided
Files:
 
is because of
extern int        MaxNumberofPositions = 1;          // max open positions
 

Hello Marco,

 

but that what i should have, one open position at the time.

 

it only says that when it tries to open an order but it detects there is already one order open what is the problem exactly?

if you want to change it you need to swap the flow so it first detects open orders and then places an order if 

 < MaxNumberofPositions 
 

thanks enlighten, i thought i added the correct function to take care of that, guess it is not implemented 

four eyes better than two 

 
Marco vd Heijden:

it only says that when it tries to open an order but it detects there is already one order open what is the problem exactly?

if you want to change it you need to swap the flow so it first detects open orders and then places an order if 

Marco,

 well i think i fixed the issue of opening more than one position at the time. but i actually notice that the TDI condition is not working properly, as you can see the 3rd and 4th red line should not have triggered a trade, could you advice, please?

I have attached the revised code. 

 

Files:
 
maybe like so
Files:
 
sorry didnt work
Reason: