PureBytes Links
Trading Reference Links
|
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();
}
__._,_.___
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
__,_._,___
|
|