Gamestudio Links
Zorro Links
Newest Posts
Black Book, 4th edition
by TipmyPip. 05/11/26 08:40
ZorroGPT
by TipmyPip. 05/09/26 11:58
No errors in the command line
by jcl. 05/08/26 10:59
Purchase A8 full licence version
by jcl. 05/05/26 11:20
Z9 getting Error 058
by k_ivan. 04/25/26 19:13
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (JMMAC, Quad), 4,055 guests, and 22 spiders.
Key: Admin, Global Mod, Mod
Newest Members
curry, DhandhaxKrsna, Specific, DeepxKalsi, codestar42
19215 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: ExitTime not respected [Re: GPEngine] #441659
05/30/14 05:24
05/30/14 05:24
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
After some effort and computing resources, I have an example which uses History of USDCAD, GBPUSD, and USDCHF from the official Downloads section. However, you must use my AssetsFix.dta file. (attached.) Max trade bars is 44, which is too much, considering there are 3 assets, 2 TradesPerBar, and ExitTime is 2. Below I demonstrate that the test.log shows positions are held too long.
Code:
Avg trade bars      5 (+5 / -4)
Max trade bars      38 (27 days)
Time in market      1490%
Max open trades     44


Code:
#define BANK 50000.0
string selected_asset;

function run() {
  BarPeriod = 720;
  LookBack = 501;
  StartDate = 20130801;
  EndDate = 20140401;
  set(TICKS + LOGFILE + MUTE);
  set(RULES);
  set(PLOTNOW);
  set(TESTNOW);
  set(FACTORS);
  if (Train) {
    Hedge = 2;
  } else {
    set(NFA + MARGINLIMIT + ACCUMULATE);
    Hedge = 4;
  }
  TradesPerBar = 2;
  Weekend = 1;
  ExitTime = 2;
  NumSampleCycles = 2;
  NumWFOCycles = 4;
  Confidence = 75;
  float max_margin_per_trade = BANK / ((ExitTime + 1) * TradesPerBar);

  while(selected_asset = loop("GBP/USD", "USD/CAD", "USD/CHF")) {
    asset(selected_asset);
    var atrx = ATR(100);
    Stop = 4.0 * atrx;
    Trail = 2.0 * atrx;
    TrailLock = 25.0;
    var v00 = WillR(100);
    plot("v00", v00, LINE+NEW, BLUE);
    vars Price = series(price());
    BBands(Price, 162, 1.1, 0.2, MAType_SMA);
    var v01 = (rRealMiddleBand - priceClose()) / PIP;
    var v02 = HighPass(Price, DominantPeriod(Price, 123));
    BBands(Price, 83, 1.8, 2.0, MAType_SMA);
    var v03 = (rRealLowerBand - priceClose()) / PIP;

    if (adviseLong(PERCEPTRON, 0, v00, v01, v02, v03) > 0) {
      Margin = OptimalFLong * max_margin_per_trade;
      enterLong();
    }

    if (adviseShort(PERCEPTRON, 0, v00, v01, v02, v03) > 0) {
      Margin = OptimalFShort * max_margin_per_trade;
      enterShort();
    }
  }
}


The relevant lines from AssetsFix.dta are
Code:
GBP/USD   1.67892 0.00028 0.0700 -0.1500 0.0001 0.10000 38.000 1000.0
USD/CAD   1.10353 0.00025 -0.3200 0.1400 0.0001 0.09063 20.000 1000.0
USD/CHF   0.88230 0.00022 0.0400 -0.0800 0.0001 0.11335 20.000 1000.0


Here I grep the test.log to show a position which was held for 20 bars, despite my ExitTime=2 setting.
Code:
$ grep -n '^\[9[7-9]\|l7866' Log/worsttest.log 
1696:[970: Fri 07.03. 12:00]  2: 312063p 139/126
1713:[971: Sat 08.03. 00:00]  2: 377825p 143/125
1719:[972: Mon 10.03. 00:00]  2: 381360p 143/126
1731:[973: Mon 10.03. 12:00]  2: 392960p 144/128
1743:[974: Tue 11.03. 00:00]  2: 403625p 147/128
1755:[975: Tue 11.03. 12:00]  2: 397995p 146/132
1767:[976: Wed 12.03. 00:00]  2: 380779p 148/133
1779:[977: Wed 12.03. 12:00]  2: 382858p 150/134
1789:[978: Thu 13.03. 00:00]  2: 368629p 152/134
1794:{USD/CHF::l7866} Long 125@0.8744 Risk 2378$ tl at 00:00
1800:[979: Thu 13.03. 12:00]  2: 401640p 154/136
1815:[980: Fri 14.03. 00:00]  2: 465401p 150/144
1829:[981: Fri 14.03. 12:00]  2: 463916p 146/152
1841:[982: Sat 15.03. 00:00]  2: 466282p 161/141
1847:[983: Mon 17.03. 00:00]  2: 470468p 158/145
1867:[984: Mon 17.03. 12:00]  2: 478817p 153/153
1879:[985: Tue 18.03. 00:00]  2: 479768p 158/151
1889:[986: Tue 18.03. 12:00]  2: 479768p 157/156
1908:[987: Wed 19.03. 00:00]  2: 469659p 163/153
1918:[988: Wed 19.03. 12:00]  2: 469659p 177/143
1933:[989: Thu 20.03. 00:00]  2: 480189p 166/156
1955:[990: Thu 20.03. 12:00]  2: 559160p 168/157
1967:[991: Fri 21.03. 00:00]  2: 566827p 170/159
1979:[992: Fri 21.03. 12:00]  2: 544094p 170/163
1986:{USD/CHF::l7866} Trail 125@0.8744 Stop 0.8766 at 12:01
2003:[993: Sat 22.03. 00:00]  2: 544094p 173/163
2009:[994: Mon 24.03. 00:00]  2: 526524p 173/164
2021:[995: Mon 24.03. 12:00]  2: 515918p 179/162
2031:[996: Tue 25.03. 00:00]  2: 499316p 178/166
2043:[997: Tue 25.03. 12:00]  2: 485604p 183/164
2053:[998: Wed 26.03. 00:00]  2: 470649p 188/162
2063:[999: Wed 26.03. 12:00]  2: 459578p 196/157
2070:{USD/CHF::l7866} Sell 125@0.8867: +1714$ at 00:00


There was an opportunity to exit the position in bar 998, or earlier.
Code:
$ grep -n -A10 '^\[998' Log/worsttest.log 
2053:[998: Wed 26.03. 00:00]  2: 470649p 188/162
2054-{GBP/USD::l9876} Long 109@1.6533 Risk 2883$ tl at 00:00
2055-[GBP/USD::L9877] Long 109@1.6533 Net trade at 00:00
2056-{USD/CHF::l9878} Long 125@0.8833 Risk 2401$ tl at 00:00
2057-[USD/CHF::L9879] Long 125@0.8833 Net trade at 00:00
2058-{GBP/USD::l7862} Sell 109@1.6533: -988$ at 12:00
2059-[GBP/USD::L8611] Sell 109@1.6533: -1107$ at 12:00
2060-{USD/CAD::l8612} Sell 54@1.1166: +569$ at 12:00
2061-[USD/CAD::S9980] Short 54@1.1166 Net trade at 12:00
2062-
2063-[999: Wed 26.03. 12:00]  2: 459578p 196/157


Attached Files
AssetsFix.dta.zip (1 downloads)
Re: ExitTime not respected [Re: GPEngine] #441665
05/30/14 11:04
05/30/14 11:04
Joined: Jul 2000
Posts: 28,100
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,100
Frankfurt
Thanks!! I can finally reproduce the problem here with these asset settings.

The Max open trades and Max trade bars are probably correct. After all, they are from net trades which have no fixed exit time. Not correct are phantom trades in the log that stay open over more than 2 bars. This is in my opinion a bug, possibly the same virtual hedging bug that's listed under "What's New" in the bug list. I'll forward this to the developers.

If you want, I can send you an interim version where this is fixed when I get confirmation that it is the same bug.

Re: ExitTime not respected [Re: jcl] #441671
05/30/14 14:13
05/30/14 14:13
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
Great. You're welcome.

Can please you nail down the correctness of the metrics? I would really like to undestand whether I can expect Max open trades, Avg trade bars, and Time in market, and especially Capital Required to behave as described in 2.4 of Jaekle/Tomasini, regardless of Hedge setting.

If getting these numbers to be useful is not a possible for certain Hedge modes, then you should remove them from Performance Report so the user does not get a false sense.

But, remember, I noticed the odd Max open trades value first before cracking open the raw, 64,000-line test.log. If it wasn't for the funny metrics, I might have deployed a system like this in Trade mode without noticing the error.

Please add sanity checks?


Yes, please connect me with the release candidate.

Last edited by GPEngine; 05/30/14 14:31.
Re: ExitTime not respected [Re: GPEngine] #441675
05/30/14 15:05
05/30/14 15:05
Joined: Jul 2000
Posts: 28,100
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,100
Frankfurt
It is principially not possible to guarantee that a software is bug free. In the case of Zorro, we find on average 3-4 bugs per release period. But I think we can safely assume that the numbers in the performance report are correct. If there were a problem, someone had certainly reported it meanwhile.

In this case we had the lucky coincidence that the numbers appeared wrong and thus made you look into the log - which revealed a real bug. BTW, I got confirmation that it was indeed the virtual hedging bug.

I'll upload an interim version next week. Inbetween you can just continue developing without virtual hedging. It has no effect on the basic system algorithm.

Re: ExitTime not respected [Re: jcl] #441676
05/30/14 15:08
05/30/14 15:08
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
Got it. Thanks.

And thanks for sticking with me even though the first few scripts did not demonstrate the bug.

Page 2 of 2 1 2

Moderated by  Petra 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1