[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Custom Backtester Code for Forex Slippage



PureBytes Links

Trading Reference Links

One thing to note is that (by default?) AmiBroker does price bounds 
checking such that it will not let you specify a price outside the 
range of the actual price action (e.g. cannot set buy price below 
actual low).

If the offset that you apply to the price will take you outside of 
those bounds, then you will need to disable price bounds checking as 
follows:

SetOption("PriceBoundChecking", false);

http://www.amibroker.com/guide/afl/afl_view.php?id=201

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@xxx> wrote:
>
> Thanks Steve. I will try that. For some reason I was under the
> impression that SellPrice, CoverPrice etc could only be set to one 
of
> four *conditions* (Open, High, Low, Close), and that we could not 
add
> or subtract actual numbers from "SellPrice" in real time in the AFL.
> 
> In real life, I would exit the trade immediately on the same bar, 
if I
> could. In the backtester, I set a one-bar trade delay, as I thought
> that would be more realistic to the way signals are handled in live
> trading. But maybe that assumption is incorrect. 
> 
> Over the next month, I plan to play around with a live virtual 
account
> at a broker to get a better understanding of this.
> 
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "_sdavis" <_sdavis@> wrote:
> >
> > 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 amibroker@xxxxxxxxxxxxxxx, "ozzyapeman" <zoopfree@> 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;
> > >
> >
>



------------------------------------

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
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/