I think you can do this:

SetTradeDelays(1,1,1,1);
slippage = ...
SellPrice = Open - slippage;
CoverPrice = Open + slippage;

However, this may not reflect the way you will actually trade. The
backtested system has a 1 bar trade delay. How are you planning to
trade this in real life? If the profit target or stop level is
detected in real-time will you exit the trade immediately or wait
until the next bar?

-Steve

--- In [email protected], "ozzyapeman" <[EMAIL PROTECTED]> wrote:
>
> 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;
>


Reply via email to