MT4 Strategy tester odd behavior

Mata Nui

Well-known member
Messages
341
Likes
22
Is there anyone who knows exactly how the strategy tester processes each bar/tick? I ask because i am developing a custom indicator that uses 3 stock indicators. When i drop the indicator on a chart it looks like i expect but when i run it with a trading simulator through the MT4 strategy tester it is nothing like the charts i dropped it on.

This may be a bit to do with my code but i know its not all my fault. An example:
One of the indicators it uses is RSI (9). Part of the criteria is a cross of 50, so it has the following:

double RSINow = iRSI(NULL,0,RSI,PRICE_CLOSE,i);
double RSILast = iRSI(NULL,0,RSI,PRICE_CLOSE,i+1);

then we compare

if(RSINow < 50 && RSILast > 50) RSICrossDown=true;

(you get the idea, so if the current bar RSI is below 50 but the prev bar RSI is above 50 we have a cross down). Now the RSI cross is only one of the criteria so you wont get an arrow on every RSI cross but obviously if there is no cross you Cant get an arrow (well that is what i thought). After seeing the difference in the charts i added the RSI and watched. There are serveral examples where it has painted the arrow but the RSI never crossed the 50 line.

Can anyone give me some explainations?
 
This may be a bit to do with my code but i know its not all my fault.

It could well be all to do with your code. Without it, nobody is really going to be able to help you.

I would suggest you test things live, and then you'll be able to narrow down where the problem is.
 
I'm assuming you only want to check for the cross at the close of a bar.
Using "PRICE_CLOSE" on the current bar makes no sense. The current bar is always in flux until the next bar opens. You are essentially checking each tick on the current bar. You want to check the previous bar & the previous bar+1. i=0 refers to the current bar, so try this:

double RSINow = iRSI(NULL,0,RSI,PRICE_CLOSE,i+1);
double RSILast = iRSI(NULL,0,RSI,PRICE_CLOSE,i+2);

Peter
 
Top