What is the best way to filter out trades from a backtest

Hi,

From the backtest report I found that many of my trades taken place at a particular time period range seems to be loss making. How should I go about if I should remove these trades using AFL ?

Also, an additional question. Is what I am trying to do come under curve fitting ?

You exclude particular days by making a conditional statement along wiht other Buy conditions using the DateNum() fuction:

https://www.amibroker.com/guide/afl/datenum.html

i.e:

Buy = .... and !(DateNum () == 1170620) 

or create ranges

Buy = ... and !(DateNum() > xxxxxx and xxxxxx < DateNum() ) 
1 Like

Hemanth66,

If your system makes the trades according to your rules, then you will have to figure out what additional information you can use to have your system not trade in that time frame.

It could be something like:

or:

C > MA(C,20);

As to if this is curve fitting - YES. BUT, if you still have Out of Sample data, then you can walk forward with the New Rules and see how your system does. If no new data, then you have to let it walk forward in Real Time to see how it does.

Hope this Helps.

1 Like

Thanks @teyano. Got things working.

Thanks @snoopy.pa30; I’m still trying to get head around curve fitting bias. So, I have 4 years worth of data. So I should be splitting them into 2 two year sets (in sample and out sample) right and run backtest twice on both sets and see if the variance is minimal right.

At least split it in two. Maybe even 4-8 depending on how your rules work.

If you are using a few days of daily data to figure out when to buy or sell, then you can split it into smaller sections of data (i.e. 30 trading days). Then you may find that you have a problem due to overall market direction (i.e. 90 day MA). When you try to add in this extra rule, you might need data sets larger to get realistic analysis (i.e. 120 day).

But as soon as you “learn” something from your IN SAMPLE data run, you CAN NOT use that data again, as it has generated your rule, so of course it will do better. You have to test it on OUT OF SAMPLE data and see how it does.

I would suggest you Google Dr. Howard Bandy and Blue Owl Press to check out his books. I can’t remember off the top of my head if his first book - now available free online - covers the Curve Fitting concept. I am sure there will be tons of other references on Google for Curve Fitting as well.

Hope this Helps.

But as soon as you “learn” something from your IN SAMPLE data run, you CAN NOT use that data again, as it has generated your rule, so of course it will do better. You have to test it on OUT OF SAMPLE data and see how it does.

Thanks for that. Makes a lot of sense.