Strategy Tester changing value of Indicator for previous candle?

 

My EA is designed to make a trading decision right at the start of the new daily candle based on the value of certain indicators from the previous candle that just closed. The EA will run the trade function at a certain time on the new candle as seen below:

void OnTick()
{
if (Hour()==00 && Minute()==1)
   {
   dpobuy();
   }

I normally have the Minute value at 1 because I want the trade to execute close to the closing price of the previous candle. I have changed the value of the Minute function to different numbers (5, 10, 15 etc.) for data purposes and ran it through strategy tester and noticed that I get extremely different results in the amount of trades taken.

I understand that price will be different based on that time so that will of course affect your end profit/loss. But my main concern is the number of trades taken which is always very different. 

Once a candle closes, the value of the indicator tested for that previous candle should be "locked" in, unless of course the indicator repaints and I am confident the indicators I've tested do not repaint. I am having this issue on multiple different indicators. And yes the value is shifted to test the previous candle:

double dpo=iCustom(Symbol(),0,"DPO",x_prd,0,1);

All other variables remain constant (i.e spread, timeframe tested, etc.). I only change the value of the minute function.

When looking through the journal results of the strategy tester, there are trades that are either not taken that should have been or new trades that are when the value of the indicator says otherwise when you look at it for the previous candle that gave the signal.

Knowing that the indicators I'm testing don't repaint, why am I getting a different amount of trades taken for my results? Is the strategy tester known to change the value of the indicator tested and "make it" repaint or is it something else?

What am I missing here?


Thanks in advance for your help.

 

Print the values of the indicator so that you can check them.

What time frame are you using for the test?

 
Keith Watford:

Print the values of the indicator so that you can check them.

What time frame are you using for the test?

Thanks for the reply.

I'm testing the daily timeframe.

I almost always print values to double check my code and test issues. No idea why I didn't do that for this 🤦‍♂️


I did as you suggested and had the code print the value of the indicator for each day at the time the EA is supposed to execute a trade. I then ran the tester twice with the code taking trades at the 1 minute mark and the other at the 10 min. mark. I then compared the two reports side by side to see what extra trades were taken or what trades were missed.

The difference is by a few trades so I went to those days and the indicator is giving the correct value and the EA acts accordingly. The issue seems to be the strategy tester as it looks like it just completely misses even going over the day/candle that the trade was taken/missed (if that makes sense). 

First screenshot (1 minute after daily close) of the strategy tester journal doesn't show data for March 6, 2017 as if the tester didn't run through it, therefore no trade was taken, when it was supposed to, when the DPO indicator crossed over the zero line. The second screenshot (10 minutes after daily close) shows data for that day, and the trades were opened as intended.

The strategy tester is completely not "running through" the day/candle. Is this normal or is there something I can do to fix this? 

Files:
1_minute.png  24 kb
10_minute.png  37 kb
 
Using hour and minute are untrustable, specially in low liquidity periods like the beginning of the day.
You are pretending that in 00:01 a tick will come in, but it's not an obvious thing, sometime no tick is received for more than 1 minute.
 
Fabio Cavalloni:
Using hour and minute are untrustable, specially in low liquidity periods like the beginning of the day.
You are pretending that in 00:01 a tick will come in, but it's not an obvious thing, sometime no tick is received for more than 1 minute.

Ah duh, that makes sense.

Considering implementing the following code to resolve the issue. Do you have any recommendations outside of what I suggested below?

if (Hour()==00 && Minute()>=00 && Minute()<=10)
   {
   dpobuy();
   }
 

You will alleviate the issue but not solving it.

Do not use Hour or Minute, use a function to check a new bar and attach the EA on Daily timeframe.

Reason: