Problem with CFDs: Series are running even when market is closed

Posted By: molloy

Problem with CFDs: Series are running even when market is closed - 06/15/14 12:39

Hi,

I experienced very big difference in behavior of my scripts in live trading and backtesting the same period later. Unfortunately the difference caused loss, not profit. frown

I think that the problem is with CFD market open hours: Zorro knows nothing about this, so bars are opened during night while the market is closed. Series get filled with the same data and this gap causes problems, e.g. lowpass filters change direction too early.

Although my script does nothing when the market is closed, I must fill the series because this is needed by Zorro.

Interestingly, when I download the data from fxcm with the download script and run a backtest, there are no bars during the night.

I have no idea what to do except that I have to stop using series.

Thank you for your help in advance!

Krisztián

-------

Some more detail:

Log from live (removed some lines logged by other components):
[Fri 13.06. 02:58] 1080 -113 +5 /\\
[Fri 13.06. 03:58] 1080 -113 +5 /\\
[Fri 13.06. 04:58] 578 -113 +5 /\\
[Fri 13.06. 05:58] 581 -113 +5 /\\
[Fri 13.06. 06:58] 516 -174 +4 /
[Fri 13.06. 07:58] 532 -174 +29 /
[Fri 13.06. 08:58] 529 -174 +28 /
[Fri 13.06. 09:58] 550 -174 +44 /
[Fri 13.06. 11:00] 548 -129 +0
Lowpass Short Invested Capital: 1095, on 6/13
[GER30:lowpass:S1819] Short 11@9843 Risk 39 t at 10:59

The same period from a backtest:
[1056: Thu 12.06. 21:59] 9910.00
[1057: Fri 13.06. 06:59] 9910.00
[1058: Fri 13.06. 07:59] 9926.00
[1059: Fri 13.06. 08:59] 9881.00
[1060: Fri 13.06. 09:59] 9883.00
[1061: Fri 13.06. 10:59] 9850.00
[1062: Fri 13.06. 11:59] 9842.00
[1063: Fri 13.06. 12:59] 9853.00
[1064: Fri 13.06. 13:59] 9880.00


Part of the code of my lowpass component which is the most affected one by this problem (although equity curve trading logic in other components is also heavily affected):


function tradeLowPass() {
algo("lowpass:S");
Stop = 22 * PIP;
Margin = margin * 3;
Trail = 0;
ExitTime = 18;
vars Price = series(price());
vars lowPass = series(LowPass(Price, 600));
vars lowPass2 = series(LowPass(Price, 760));
vars lowPass3 = series(LowPass(Price, 100));

if (isTradingHour() and falling(lowPass2) and falling(lowPass) and falling(lowPass3) and not opened) {
Lots = 1;
enterShort(0, 0, 25, 0, 30, 115);
opened = 1;
openedAt = price();
}
...
}
Posted By: jcl

Re: Problem with CFDs: Series are running even when market is closed - 06/16/14 06:18

This also happens when the market is not closed, but no price quotes arrive during a bar period. There are two solutions. You can either generate bars even without quotes in the backtest, or you can skip bars without quotes in trade mode.

For the first solution, select a 24 hours asset such as EUR/USD before selecting the CFD. The first selected asset determines the bars.

For the second case, use the TimeFrame mechanism to skip bars when their price is identical to the previous bar or when the time is outside market hours.
Posted By: molloy

Re: Problem with CFDs: Series are running even when market is closed - 06/16/14 07:55

Hi jcl,

thank you for the answer, I will try the second solution!
© 2024 lite-C Forums