User must understand his/her own code, was: Backtest runs WRONG condition

Dear @Tomasz
this morning i ran backtest , it gives some different yesterday results . I rechecked some position running with wrong condition.
my condition below:

MA200 = MA(C,200);

Sell = cross(ScoreS,26) OR Close <MA200  OR Close <TEMA480;

Backtest result
backtest
This VHC stock open long position until now
VHC%20chart
and this is explore result gives ScoreS = 35 and this stock price is below MA200 and TEMA480;
explore
this is first time i face with this problem. Please check it.
Thank you so much!

Remember: AmiBroker always produces CORRECT output.

Any "problem" is either:

  1. your data has changed
  2. the formula is incorrect
  3. your understanding of your own code is incorrect

In cases 2 and 3 see: How do I debug my formula?
If you trade the code, you must understand how it works. It is too risky to trade something that you don't fully understand.

Posting 2 lines from huge formula does not lead anywhere. Other portions of the code might reference Sell variable (like ExRem or Equity(1)) and modify it. You might forgot about it, and people on this forum can't guess what your other (unlisted) parts of the formula are like. Again - it is your code and your task it to debug it using techniques described here: How do I debug my formula?

In case 1 - obviously if your data changed you will get different output (when you use REAL TIME data "close" field represents LAST price which changes all the time for the duration of the day).

See also: http://www.amibroker.com/kb/2014/05/07/why-do-backtest-results-change/

3 Likes

Hi @Tomasz,
Many thanks to you for reply.
I found out this problem because of using both "Holdminbars" = 3 and "ExRem" in Sell variable in daily interval. In first 2 days of opening a position if any sell signal happens, "Holdminbars" will disable that Sell signal, and ExRem will ignore all sell signals until we have a NEW buy signal. In "Backtest", therefore, the LONG position will keep until the system have a new BUY. In my country, investors have to hold 3 minimum days in every trade. Do you have any suggests of using both "HoldMinBars" and "Exrem" in one system? for example, if Sell signal appears after first 2 days of position, that signal will be moved/shifted to day 3.
Thank you in advance!

SetOption("HoldMinBars", 3 ) is a backtester option. It is ONLY interpreted by backtester and ONLY at the time of the backtest (after your formula was executed).

ExRem however is a simple function that just acts like "first change detector until reset". It does care about any options you have set, specifically options for the backtester. Therefore you should avoid using ExRem, or filter out first 3 bars after buy using your code, for example using Hold function or using loop or using dozens of different ways.
Again, without posting the whole thing (formula) no one is able to help you.

1 Like