ozzyapeman wrote:
Hello, hoping someone can help out with this code. Aron was kind
enough to post a version of some code that is meant to inject some
slippage when using ApplyStop(). However, I can't seem to get it to
work. All I want it to do is reduce Long exits by 2 pips (I'm
backtesting Forex) and increase Short exits by 2 pips, when using
ApplyStop.
Here is the code. At present, it only ends up blanking out my backtest
report - no trades taken. Without the code, dozens or hundreds of
trades taken, depending on which system I test. As far as I can tell,
this code should work, but doesn't. Any input appreciated:
Good Idea to move this in a separate thread.
I do not know why the following ways accessing TickSize are not working.
method 1
-------------------------------------------
|slippage = *TickSize*;
spread = 2 * *TickSize*;
||*for* ( bar = 0; bar < *BarCount*; bar++ )
{
*for* ( sig = bo.GetFirstSignal(bar); sig; sig =
bo.GetNextSignal(bar) )
{
|method 2
-------------------------------------------|
||*for* ( sig = bo.GetFirstSignal(bar); sig; sig = bo.GetNextSignal(bar) )
{
|| slippage = *sig.TickSize*;
spread = 2 * *sig.TickSize*;
}
*
the followng code returns correctly slippage and spread but the trades
are not stopped out at exactly stop distance
I'm having this problem with ApplyStop() generally.
*|//------------------------------------------------
// Settings for ( BID+ASK) /2
//------------------------------------------------
|SetCustomBacktestProc("");|
|*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");
*if*( StrFind(symbol, "JPY"))
{
slippage = 0.01;
spread = 2 * 0.01;
}
*else*
{
slippage = 0.0001;
spread = 2 * 0.0001;
}
*if*(sig.isEntry()) ||// Contract Specifications |||
| {
sig.pointvalue = 1; ||// allows trading in units ie. 1234
EURUSD|
| sig.margindeposit = sig.price / 100; ||// Leverage used 1:100 |
| }
*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)
{
sig.price = TrueExit;
}
*else*
sig.price = -1; ||// Ignore signal|
| }
*else* // Exit short
{
TrueExit = sig.price + slippage;
*if* (TrueExit >= lo[bar]+ 0.5*spread && TrueExit <=
hi[bar]+0.5*spread)
{
sig.price = TrueExit;
}
*else*
sig.price = -1; ||// Ignore signal|
| }
}
}
bo.ProcessTradeSignals( bar );
}
bo.PostProcess();
}|
|
|