stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Simple Shelley Backtester
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=606
Page 6 of 6
Author:  NeoTrader [ Tue Jul 10, 2012 5:35 am ]
Post subject:  Re: Simple Shelley Backtester

garyfritz wrote:I'd say an external script. You could do a simple text find&replace, or it would be very simple to do it in Perl or something like that. Ideally it would be best to use something that actually parsed the code so you only changed the things you were really supposed to change -- e.g. if the EA had a string that said "The High value is:", you wouldn't want to change it to "The BT_High value is:" :D -- but I think a Perl parser would be good enough.
hmmm...I don't think that we should involve a third tool that most of the people don't have installed on their computer...I will try to do it as a MQL Script or a Windows shellscript.
Why don't we use a Parameter "backtester" that can be set to true/false. In the library I just make a simple check with "if (backtester) { function override } else { original function }". This way we only need to rename the functions once for every EA and then use only the BT_XXX functions in the Indicator and in the EA. I think this would be a much easier and cleaner solution then renaming the functions every time we want to add or change something. Just a thought.
garyfritz wrote:I don't think it's that hard. e.g. iClose() has a "shift" parameter. So BT_iClose() will also take a "shift" parameter, and we'll just add the current Backtest_Bar to Shift before passing it to iClose(). So if the EA wants the Close of 1 bar ago, it would pass a value of 1 to iClose(). If we're currently backtesting on bar 100, we'll just pass a value of 100+1 to iClose(). High and Time &etc would be similar, but BT_High() and BT_Time() &etc would just pass Backtest_Bar to the corresponding iHigh() or whatever function.
Yep, that sounds plausible, clean and easy to implement... me likey.. ;)
garyfritz wrote:Well, we're starting already, figuring out some of these issues... and I'm sure we'll run into more!
Yeah ...they will sure come up...especially with Empty4..;)
garyfritz wrote:No, and I really should. I've got Tortoise SVN on my system but I never started using it. A shared repository like that bitbucket.org is probably a good idea for a shared project
hehe...yes you really should...I'm used to subversion but I think that I will jump on the Git train this time. Bitbucket seems to be ok...I will setup an account with them.
I found also a nice client for it at http://code.google.com/p/gitextensions/ . This has also a explorer shell extension...like tortoise svn.
garyfritz wrote:Unfortunately my time is extremely limited -- I'm already spending too much time here and falling far behind on my paying job -- and it looks like it's about to get much worse. :( I might have to let you run with this, and I just act as a sounding board for design ideas.
Aaaargh...but I thought so already... ok... the I will see how far I get.. ;)

thanks for your comments and insights...

happy trading,

NeoTrader

-
Author:  garyfritz [ Tue Jul 10, 2012 12:54 pm ]
Post subject:  Re: Simple Shelley Backtester

NeoTrader wrote:Why don't we use a Parameter "backtester" that can be set to true/false. In the library I just make a simple check with "if (backtester) { function override } else { original function }". This way we only need to rename the functions once for every EA and then use only the BT_XXX functions in the Indicator and in the EA. I think this would be a much easier and cleaner solution then renaming the functions every time we want to add or change something. Just a thought.
Oh yes, I would make the change once (or write it that way originally) and leave it that way. I had thought we would have two different libraries, one with "wrapper pass-through" functions for the EA, and one that implemented the backtester logic. Then you'd just change the #include when you wanted to run the backtester. That way you're not carrying around the backtester code when you're just running the EA.
Author:  NeoTrader [ Tue Jul 10, 2012 3:05 pm ]
Post subject:  Re: Simple Shelley Backtester

garyfritz wrote:Oh yes, I would make the change once (or write it that way originally) and leave it that way. I had thought we would have two different libraries, one with "wrapper pass-through" functions for the EA, and one that implemented the backtester logic. Then you'd just change the #include when you wanted to run the backtester. That way you're not carrying around the backtester code when you're just running the EA.
yep...this is actually more elegant...I will do it that way...thanks for your input...

I will also try to do a visualization of the trades like the zigzag demo in the Article I send before.
Maybe as a optional parameter in the EATestIndicator.

I'm also thinking to write a MQL Script that could collect all the relevant Account Informations on the local Empty4 and write it to a file as if they where external Parameters so we can copy and paste or read this Information in the EATestIndicator and can use them also in the BT_Functions.
If we would copy&paste them as external Parameter the user also would have the possibility to change some of it to his needs.

what do you think about this features?


happy trading,

NeoTrader

-
Author:  garyfritz [ Tue Jul 10, 2012 3:12 pm ]
Post subject:  Re: Simple Shelley Backtester

NeoTrader wrote:I will also try to do a visualization of the trades like the zigzag demo in the Article I send before.
That would be fabulous. I find that to be an invaluable debugging aid with TS.
I'm also thinking to write a MQL Script that could collect all the relevant Account Informations on the local Empty4 and write it to a file as if they where external Parameters so we can copy and paste or read this Information in the EATestIndicator and can use them also in the BT_Functions.
Meaning, you'd read the current account value, and use that actual account value in the backtest?

Personally I wouldn't bother. When I backtest a system I don't care what my current actual account value is. I just want to know how the EA performas. Just let the user specify a reasonable starting value, and simulate it from there.
Author:  NeoTrader [ Tue Jul 10, 2012 4:02 pm ]
Post subject:  Re: Simple Shelley Backtester

garyfritz wrote:That would be fabulous. I find that to be an invaluable debugging aid with TS.
I also thought so... ;)
garyfritz wrote:Meaning, you'd read the current account value, and use that actual account value in the backtest?
Personally I wouldn't bother. When I backtest a system I don't care what my current actual account value is. I just want to know how the EA performas. Just let the user specify a reasonable starting value, and simulate it from there.
It is not about the Account Value...that is something we can put any value in but we have following Functions that needs to be accurate for the EAs.
  • AccountBalance
    AccountCredit
    AccountCompany
    AccountCurrency
    AccountEquity
    AccountFreeMargin
    AccountFreeMarginCheck
    AccountFreeMarginMode
    AccountLeverage
    AccountMargin
    AccountName
    AccountNumber
    AccountProfit
    AccountServer
    AccountStopoutLevel
    AccountStopoutMode
I thought why not use the local Account infos for this so anybody has always proper values in the test as he would have in live trading..

The Script just would call every function and write it in a file as
extern *type* BTfunctionVariableName = ResultOfFunctionCall;

We then just open the generated File and could have all parameters that we just copy and paste in a reserved Area of the external Parameters in our EATesterIndicator.
You would still have the possibility to change certain values manually and our BT_AccountFunctions could gather and work with realistic Data.

This is nothing you need to do every time...only the first time with a new account...put it in the EATesterIndicator and use this as Template for all your following EA Tests.

Do you think that this is reasonable? Or am I thinking to complex again...;)

happy trading,

NeoTrader

-
Author:  garyfritz [ Tue Jul 10, 2012 6:44 pm ]
Post subject:  Re: Simple Shelley Backtester

I see what you mean. I have no idea how much those get used. But yes, it would probably be a good idea to provide reasonable values for those vars.
Author:  MadCow [ Thu Jul 12, 2012 5:59 pm ]
Post subject:  Re: Simple Shelley Backtester

Hi guys. You seem to be taking on a pretty daunting task. It is sorely needed, and I am surprised it has not been done, given the Strategy Tester limitations. Hope you are successful. :!:

You can simplify it a little, since the Empty4 indicators respond correctly to all the accountxxx() calls. In fact the indicators respond correctly to all the calls I have used, except the trading functions. (But I don't use some of the calls).

You might consider writing a DLL that would have two classes. A Trades class that held all the trades, and their parameters, and an Accounts class that kept track of the profit/loss. Although many EA's don't really use the accounts info, some calculate the position size based on the account balance and desired risk. The balance will not change in the account called directly from the indicator, so you need to track it in an array.

The problem I have found with DLLs is the way that Empty4 handles them. I'm not a pro like you guys, so maybe I am just having an amateur problem, but it seems that Empty4 must do all the static memory allocation, and pass the address to the DLL, since if allocation is done in the DLL it is lost between DLL calls. That makes it tough to write a DLL with arrays that change size, but it can be done in simple cases, so probably can be done for your app.

The community will really appreciate a multi-symbol backtester. :D
Author:  garyfritz [ Thu Jul 12, 2012 6:27 pm ]
Post subject:  Re: Simple Shelley Backtester

MadCow wrote:You can simplify it a little, since the Empty4 indicators respond correctly to all the accountxxx() calls.
Yes -- but those would be the REAL Accountxxx() calls, corresponding to the REAL account -- not the simulated account in your backtest! If somebody's accessing e.g. AccountEquity(), he probably wants to know the equity resulting from the current EA execution -- which means we have to simulate it and report he simulated account balance.

Nice try though. :D
Author:  MadCow [ Sat Jul 14, 2012 6:31 pm ]
Post subject:  Re: Simple Shelley Backtester

Of course. That's why you would need either an Accounts class or an Accounts array in case the EA accessed a variable that changed due to virtual trading. I should have been clearer. :oops:
All times are UTC Page 6 of 6