Backtesting Issue - THIS IS STRANGE!!
Backtesting Issue - THIS IS STRANGE!!
26 Nov 2016, 10:36
PLEASE PLEASE can someone tell me why this would happen in a backtest? Admin need you to pitch in here as well.
Replies
davidp13
27 Nov 2016, 19:07
tmc - thanks for getting back to me, however i'm not sure that is what caused it.
I have a piece of code that supposedly tracks any open position - like a trailing stop. I use the ModifyPosition call, but i then set the TakeProfit value to null . I changed the code to rather us position.TakeProfit and it stopped it, but the results are not as good as they were before. still profitable, but not pretty.
Here is the code. Anyone have a clue why this would cause such a problem? Strangely enough I have been running this in Live and Demo for a couple of months with good results.
var beATR = atr.Result.LastValue * ATRMultiP;
if (position.TradeType == TradeType.Buy && position.Label == label)
{
if (position.Pips >= TrailTrigger)
{
var newStopLoss = Symbol.Bid - beATR;
if (position.StopLoss < newStopLoss - Trail)
ModifyPosition(position, newStopLoss, null);
}
}
@davidp13
davidp13
29 Nov 2016, 21:22
RE:
I have tested it on Tick, 1m and 5m bars...sames story. As soon as I use Symbol.Bid (for Long tracking) or Symbol.Ask (for Short tracking) the backtesting engin does not work like it should. As an example, if I'm long and I want to trail my position there should be no reason why I cannot subtract a certain number form the last Bid price to move my stop closer. But, your backtest engin does not seem to be able to compute this effectively and thus creates not necesserily losing trades, but they stay open longer than what they should have and thus causing the system to go out of sequence.
I have furthermore printed some numbers and have also found that the backtest allows that a position (lets say long) can have a bigger SL than what the cirrent Bid price is. HOW IS THIS POSSIBLE???
Here is an extract from the backtest:
Bid - Bid price; CSL - Current StopLoss;
02/01/2015 15:02:00.000 Pos ID 2, Label L V3 USDJPY, Bid 120.482, CSL 120.519214285714
Spotware said:
We concur with tmc that this most likely caused by negative spread in the historical data. We suggest that you try to test on m1 trendbar data instead of tick data and let us know if the issue exists or not.
Many thanks,
@davidp13
davidp13
29 Nov 2016, 22:07
RE:
But what gets me the most is that when I change the code from ModifyPosition(position, newStopLoss, null); to ModifyPosition(position, newStopLoss, position.TakeProfit); then it seems to function fine. WHY IS THAT? It really really makes no sense. Is their something wrong with the backtest engin?
Spotware said:
We concur with tmc that this most likely caused by negative spread in the historical data. We suggest that you try to test on m1 trendbar data instead of tick data and let us know if the issue exists or not.
Many thanks,
@davidp13
whis.gg
26 Nov 2016, 11:35
/search?q=negative+spread
@whis.gg