Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,238 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Significant difference calculated bids & logged long exit prices #469117
11/05/17 22:26
11/05/17 22:26
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline OP
Member
Grant  Offline OP
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
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

Last edited by Grant; 11/06/17 00:05.
Re: Significant difference calculated bids & logged long exit prices [Re: Grant] #469118
11/05/17 22:29
11/05/17 22:29
Joined: Aug 2017
Posts: 58
P
pascalx Offline
Junior Member
pascalx  Offline
Junior Member
P

Joined: Aug 2017
Posts: 58
I would suggest to attach your test script.

Re: Significant difference calculated bids & logged long exit prices [Re: pascalx] #469120
11/05/17 23:07
11/05/17 23:07
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline OP
Member
Grant  Offline OP
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
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;
	}
    }
}


Re: Significant difference calculated bids & logged long exit prices [Re: Grant] #469126
11/06/17 08:49
11/06/17 08:49
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
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.

Re: Significant difference calculated bids & logged long exit prices [Re: jcl] #469140
11/06/17 10:26
11/06/17 10:26
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline OP
Member
Grant  Offline OP
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
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?

Re: Significant difference calculated bids & logged long exit prices [Re: Grant] #469146
11/06/17 11:26
11/06/17 11:26
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
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.


Re: Significant difference calculated bids & logged long exit prices [Re: jcl] #469243
11/09/17 15:20
11/09/17 15:20
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline OP
Member
Grant  Offline OP
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
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.

Last edited by Grant; 11/09/17 15:22.
Re: Significant difference calculated bids & logged long exit prices [Re: Grant] #469245
11/09/17 16:03
11/09/17 16:03
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Bid price = priceClose()-Spread.

Re: Significant difference calculated bids & logged long exit prices [Re: jcl] #469257
11/09/17 20:15
11/09/17 20:15
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline OP
Member
Grant  Offline OP
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
I understand, but this is pretty inaccurate when a fixed spread is used in a simulation.

Re: Significant difference calculated bids & logged long exit prices [Re: Grant] #469281
11/10/17 08:38
11/10/17 08:38
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
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();


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1