But I need "ExitAtStop" to be set at "1" in order for it to exit between the Low and High of each bar, as opposed to exiting on, say, the Close.
I am trading intraday. And in order to model the profitstop I use in the real world, ApplyStop needs to exit with ExitAtStop = 1. Therein lies the problem. --- In [email protected], "Tomasz Janeczko" <gro...@...> wrote: > > You don't need custom backtester to do such things. > BuyPrice = BuyPrice + Slippage: > SellPrice = SellPrice - Slippage; > CoverPrice = CoverPrice + Slippage: > ShortPrice = ShortPrice - Slippage. > > When using ApplyStop make sure to switch "ExitAtStop" argument to false > and it will use prices defined above. > > Best regards, > Tomasz Janeczko > amibroker.com > ----- Original Message ----- > From: Aron > To: [email protected] > Sent: Thursday, March 19, 2009 8:08 AM > Subject: Re: [amibroker] Re: Simple slippage implemented in CBT generates > COM error > > > Tomasz Janeczko wrote: > Hello, > > You need to call ProcessTradeSignals. > > BTW: it is easier to just define custom commission table (AA->Settings > "Commission table: Define...") > that includes slippage than wresting with code. > > Best regards, > Tomasz Janeczko > amibroker.com > Hello Tomasz, > > I would deeply appreciate if you provided an example on how to adjust Exits > in CBT in order to account for spread and slippage. > > For FX scalping systems backtesting (takeProfit = 2-3 pips. ) , I think it > is crucial to be able to do this since all depends on spread and slippage (if > commissions ==0). > > Unfortunately, the code I have come up with is not quite working : > > // EURUSD example > // price = (bid+ask)/2 > > if ( Status( "action" ) == actionPortfolio ) > { > bo = GetBacktesterObject(); > bo.PreProcess(); > > for ( bar = 0; bar < BarCount; bar++ ) > { > for ( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( > bar ) ) > { > symbol = sig.symbol; > hi = Foreign( symbol, "High" ); > lo = Foreign( symbol, "Low" ); > > > slippage = 0.0001; > spread = 2 * 0.0001; > > > > > if ( sig.IsExit() ) > { > if ( sig.isLong ) // Exit Long > { > TrueExit = sig.price - slippage; > > if ( TrueExit >= lo[bar] - 0.5*spread && TrueExit <= > hi[bar] - 0.5*spread ) // bid pricebound check > { > sig.price = TrueExit; > // bo.ExitTrade( BAR, sig.Symbol, sig.Price ); > } > else > sig.price = -1; > > > > } > else // Exit short > { > TrueExit = sig.price + slippage; > > if ( TrueExit >= lo[bar] + 0.5*spread && TrueExit <= > hi[bar] + 0.5*spread ) // ask pricebound check > { > sig.price = TrueExit; > //bo.ExitTrade( BAR, sig.Symbol, sig.Price ); > } > else > sig.price = -1; > > } > } > } > > bo.ProcessTradeSignals( bar ); > > bo.handlestops( bar ); > > } > > for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) > { > trade.addcustommetric( "numPips", ( trade.exitprice - > trade.entryprice ) / trade.ticksize ); > } > > bo.PostProcess(); > } >
