Significant difference calculated bids & logged long exit prices

Posted By: Grant

Significant difference calculated bids & logged long exit prices - 11/05/17 22:26

Greetings all,

Using the original EURUSD data, I made a comparison between the calculated ask and bid price with the logged entry and exit price from 327 long trades, written in the testtrades.csv using the 'set(LOGFILE + TICKS)' mode.
The average relative difference between the calculated ask and the logged entry price is close to 0% (-0.0000002%), but there is a significant difference between the calculated bid (i.e. 'BidPrice = AskPrice - Spread' as double) and the logged exit price, namely 0.14%(!)
How can this strong deviation be explained?

Thanks for any help laugh

Grant
Posted By: pascalx

Re: Significant difference calculated bids & logged long exit prices - 11/05/17 22:29

I would suggest to attach your test script.
Posted By: Grant

Re: Significant difference calculated bids & logged long exit prices - 11/05/17 23:07

You're right about that Pascal laugh

Here's my simplified code:

Code:
byte PositionTrade;
double PriceTradeEntry, PriceTradeExit;

function run()
  {
  BarPeriod = 1;
  StartDate = 20140107;
  EndDate = 20150106;
	
  set(BALANCE + OPENEND + LOGFILE + TICKS);

  switch(PositionTrade)
    {
    case 0: //Long Entry
      if(random() > 0)
	{
	enterLong();
	PriceTradeEntry = AskPrice;
	PositionTrade = 1;
	}
      break;
    case 1: //Long Exit
      if(random() < 0)
	{
	exitLong();
	PriceTradeExit = AskPrice - Spread;
	print(TO_CSV, "Entry, %.6f, Exit, %.6fn", PriceTradeEntry, PriceTradeExit);
	PositionTrade = 0;
	}
    }
}

Posted By: jcl

Re: Significant difference calculated bids & logged long exit prices - 11/06/17 08:49

The prices in the .csv file are AFAIK not ask prices, but the real entry and exit prices. The entry and exit prices in the .log file are the ask prices. So there should be a difference in the range of spread for long exit and short entry prices.
Posted By: Grant

Re: Significant difference calculated bids & logged long exit prices - 11/06/17 10:26

Well, the difference between the AskPrice function and the long entry price in testtrades.csv are almost the same, so this part is working fine. The suggested bid price calculation 'AskPrice - Spread' however leads to the wrong bid price, OR(!) the logged long exit price is wrong. I understand that there are minor differences, but that's not the case, compared to the ask/entry price. I haven't tried it myself yet, but is this Spread function a constant or a variable?
Posted By: jcl

Re: Significant difference calculated bids & logged long exit prices - 11/06/17 11:26

Spread is normally constant in the backtest, unless you use historical spreads. The long exit price stored in the .csv file is simply TradePriceClose - Spread. Since Spread is the same, the difference that you observe means that you are logging a slightly wrong exit price. Store the current trade pointer, print out its TradePriceClose after exiting it, and compare. Somewhere there lies the problem.

Posted By: Grant

Re: Significant difference calculated bids & logged long exit prices - 11/09/17 15:20

Can you explain why there's no direct bid price function? In order to approach the long exit execution price, I've added an extra factor (i.e. AskPrice - Spread - 'factor'). This has decreased the average difference, but it remains significantly higher than the average difference between the ask-long entry execution price. The right bid price is vital for my model when controlling the risk and due to it's high trade frequency.
Posted By: jcl

Re: Significant difference calculated bids & logged long exit prices - 11/09/17 16:03

Bid price = priceClose()-Spread.
Posted By: Grant

Re: Significant difference calculated bids & logged long exit prices - 11/09/17 20:15

I understand, but this is pretty inaccurate when a fixed spread is used in a simulation.
Posted By: jcl

Re: Significant difference calculated bids & logged long exit prices - 11/10/17 08:38

Using variable spread for 'accuracy' in the backtest is not recommended, for the reasons mentioned in the manual. But if you want to still do it, use historical data with spread and modify the Spread variable. To my knowledge, FXCM historical data has spread in the marketVal parameter.

if(is(TESTMODE)) Spread = marketVal();
© 2024 lite-C Forums