Backtest Forex

Questions about MultiCharts and user contributed studies.
tradingest
Posts: 283
Joined: 05 Dec 2014
Location: Italy
Has thanked: 53 times
Been thanked: 3 times

Backtest Forex

Postby tradingest » 11 Jun 2016

Hi all,

why for the code below entry and exit position are the same? I don't know.

Code: Select all

var: N(50000);

inputs: FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ;
variables: var0( 0 ), var1( 0 ), var2( 0 ) ;

var0 = MACD( Close, FastLength, SlowLength ) ;
var1 = XAverage( var0, MACDLength ) ;
var2 = var0 - var1 ;

If var0 cross above 0 and time >= 0800 and time <= 1800
Then begin
Buy("Entry") N contract next bar market;
End;


setbreakeven(50);
setdollartrailing(150);
setprofittarget(60);
Can you help me?

Thanks,
tradingest

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Backtest Forex

Postby evdl » 12 Jun 2016

The exit is probably caused by

setbreakeven(50);
setdollartrailing(150);
setprofittarget(60);

The values you set are in dollar and not points. If you buy 50000 (which is the N contracts in your example). Then a breakeven of 50 dollars is easily reached and will cause a immediately exit after the entry.

tradingest
Posts: 283
Joined: 05 Dec 2014
Location: Italy
Has thanked: 53 times
Been thanked: 3 times

Re: Backtest Forex

Postby tradingest » 12 Jun 2016

no I don't know because 50$ on 50000 the contracts are 10 pips.

What do you think about it?

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Backtest Forex

Postby evdl » 12 Jun 2016

What chartresolution do you use? And do you use IOG?

Can it be that the Breakeven is triggered in the entry bar (reaching the 10pip). The strategy performance report does not show intrabar times, so maybe the trade is not closed immediately but the 10 pip is reached somewhere in the bar.

If you don't use any other exit code, then it can only be the three exits you have, that is causing the exit. You could try to pinpoint where the exit takes place with plot statements.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Backtest Forex

Postby tony » 12 Jun 2016

Looks like you are buying 5,000 contracts. Setbreakeven will result in entry price equal to exit price. Setprofittarget(50) is for 5,000 contracts as well (it's for the whole position) so that too will essentially result in exit and entry price being equal. I don't use setprofittarget, but a quick study appears you need to specify per contract or position. I'm not sure what the default is. Visit this link to learn more - https://www.multicharts.com/trading-sof ... ofitTarget

tradingest
Posts: 283
Joined: 05 Dec 2014
Location: Italy
Has thanked: 53 times
Been thanked: 3 times

Re: Backtest Forex

Postby tradingest » 14 Jun 2016

What chartresolution do you use? And do you use IOG?
Which resolution is for default? I don't set anything.

tradingest
Posts: 283
Joined: 05 Dec 2014
Location: Italy
Has thanked: 53 times
Been thanked: 3 times

Re: Backtest Forex

Postby tradingest » 15 Jun 2016

kindly can you help me?

For this problem I can't make backtest for forex market

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Backtest Forex

Postby tony » 15 Jun 2016

You have to find the answer yourself. I believe you've been given a few suggestions already that would explain the behavior your results are demonstrating.

tradingest
Posts: 283
Joined: 05 Dec 2014
Location: Italy
Has thanked: 53 times
Been thanked: 3 times

Re: Backtest Forex

Postby tradingest » 15 Jun 2016

Tony could you help me?
I can not fix the problem

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: Backtest Forex

Postby tony » 15 Jun 2016

I don't use setprofittarget or settrailingstop, but it looks like you need to specify whether it is for the position or per contract, which you are not doing for either. So that right there may be part of the problem. Also, setbreakeven will exit at entryprice, which too is the problem. I posted a link above for setprofittarget and here is one for settrailingstop, try adding the additional line for each:

SetStopContract;

to specify per contract for each and see if that fixes your problem. https://www.multicharts.com/trading-sof ... arTrailing

Code: Select all

setbreakeven(50);
SetStopContract;
setdollartrailing(150);
SetStopContract;
setprofittarget(60);
You have to just try a few things. First try what I wrote above. If that doesn't work, then remove two of the three exit statements to test each one. SetBreakEven though will always produce the same exit price as the entry.


Return to “MultiCharts”