PureBytes Links
Trading Reference Links
|
Hi. I am hoping anyone out there can check this code and perhaps give me some pointers on how to do the actual scaling up and down of the exit prices?
To mimic a more realistic backtesting model for trading Forex, I want to scale the backtester's exit prices down 2 pips if a Sell and up 2 pips if a Cover. My actual trade system has a 1-bar trade delay so not sure how that affects the below code. I added a generic trade system to the below code for the sake of simplicity.
Is this the correct approach? Or do I need to add some custom metrics? I'm not too sure if this approach is the right way. And I'm still missing the meat and potatoes - in the two "ADD CODE HERE" sections:
// Custom Backtester Code to add Slippage to Forex trades // // We Sell and Cover on Open. // But we want actual Sell prices to be slipped down by 2 pips and // actual Cover prices to be slipped up by 2 pips.
// First we need to enable custom backtest procedure AND // tell AmiBroker to use current formula
SetCustomBacktestProc("");
// Now custom-backtest procedure follows
if( Status("action") == actionPortfolio ) { bo = GetBacktesterObject();
bo.Backtest(1); // run default backtest procedure
// iterate through closed trades first
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) { if( sig.IsLong() AND sig.IsExit() ) //check if the signal is a Sell of a Long position { // ADD CODE HERE: NEED TO REDUCE THE SELL EXIT PRICE BY 0.0002 }
if( NOT sig.IsLong() AND sig.IsExit() ) //check if the signal is a Cover of a Short position { // ADD CODE HERE: NEED TO INCREASE THE COVER EXIT PRICE BY 0.0002 } } }
// your trading system here
fast = Optimize( "fast", 12, 5, 20, 1 ); slow = Optimize( "slow", 26, 10, 25, 1 ); Buy=Cross( MACD( fast,slow ),Signal( fast,slow ) ); Sell=Cross( Signal( fast,slow ),MACD( fast,slow ) ); BuyPrice = SellPrice = ShortPrice = CoverPrice = Open;
__._,_.___
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
__,_._,___
|