Gamestudio Links
Zorro Links
Newest Posts
Purchase A8 full licence version
by ukgamer. 04/29/26 18:09
Z9 getting Error 058
by k_ivan. 04/25/26 19:13
ZorroGPT
by TipmyPip. 04/25/26 16:09
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 4,134 guests, and 76 spiders.
Key: Admin, Global Mod, Mod
Newest Members
ukgamer, valino, juergenwue, VladMak, Geir
19210 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
ExitTime not respected #441576
05/27/14 15:17
05/27/14 15:17
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
In a script which does not set an invalid value for Margin (see ExitTIme=3 but Max open trades is thousands, I have observed a case where Zorro does not respect ExitTime.

In my script
I set ExitTime = 18
I loop over 7 assets
TradesPerBar = 2

It produces the following report
Code:
Walk-Forward Test maxopen00 portfolio - performance report

Simulation period   23.03.2011-01.10.2012
Test period         23.12.2011-01.10.2012
WFO test cycles     6 x 616 bars (6 weeks)
Training cycles     7 x 3490 bars (39 weeks)
Monte Carlo cycles  200(Confidence 75%)
Lookback time       501 bars (5 weeks)
Assumed slippage    10.0 sec

Gross win/loss      1481886$ / -922552$ (+5686890p)
Average profit      721684$/year, 60140$/month, 2776$/day
Max drawdown        -331954$ 59% (MAE -395415$ 71%)
Total down time     57% (TAE 94%)
Max down time       11 weeks from May 2012
Largest margin      808693$
Trade volume        288957303$ (372828935$/year)
Transaction costs   -73945$ spr, 14194$ slp, 1111$ rol
Capital required    1325591$

Number of trades    13820 (17832/year, 343/week, 71/day)
Percent winning     55%
Max win/loss        1868$ / -2025$
Avg trade profit    40$ 411.5p (+1975.2p / -1514.8p)
Avg trade slippage  1.03$ 10.4p (+30.6p / -14.4p)
Avg trade bars      126 (+128 / -123)
Max trade bars      1219 (13 weeks)
Time in market      47178%
Max open trades     1177
Max loss streak     63 (uncorrelated 12)

Annual return       54%
Profit factor       1.61 (PRR 1.57)
Sharpe ratio        1.16
Kelly criterion     1.51
R2 coefficient      0.794
Ulcer index         18.4%
Prediction error    7%
Cycle performance   1.57 1.64 

Confidence level     AR   DDMax  Capital

 10%                 67%  135109$  1074510$
 20%                 64%  161416$  1126267$
 30%                 63%  173766$  1150565$
 40%                 61%  191840$  1186125$
 50%                 58%  216490$  1234622$
 60%                 57%  231272$  1263704$
 70%                 56%  249470$  1299507$
 80%                 54%  273360$  1346509$
 90%                 50%  317544$  1433437$
 95%                 47%  363781$  1524406$
100%                 40%  515542$  1822985$

Portfolio analysis  OptF  ProF  Win/Loss  Wgt%  Cycles

EUR/CAD avg         .392  2.71  810/453   46.8  /\///\
EUR/GBP avg         .331  1.59  1988/1492 23.3  ////\/
EUR/USD avg         .000  0.53  1711/2301-26.2  ///X\\
GBP/CAD avg         .816  1.77  1274/996   5.9  \/X//\
GBP/USD avg         .137  1.55  1134/743   8.8  ///\//
USD/CAD avg         .246  3.15  653/181   49.5  ///\//

EUR/CAD             .785  2.71  810/453   46.8  /\///\
EUR/CAD:L           .000  ----    0/0      0.0  ......
EUR/CAD:S           .785  2.71  810/453   46.8  /\///\
EUR/GBP             .423  1.59  1988/1492 23.3  ////\/
EUR/GBP:L           .000  0.42  396/520   -6.2  //./\/
EUR/GBP:S           .663  2.02  1592/972  29.5  .///\/
EUR/USD             .000  0.53  1711/2301-26.2  ///X\\
EUR/USD:L           .000  0.67  1247/1569-12.4  ///\\\
EUR/USD:S           .000  0.24  464/732  -13.8  ////\\
GBP/CAD             .717  1.77  1274/996   5.9  \/X//\
GBP/CAD:L           .999  7.31  106/55     0.3  .//...
GBP/CAD:S           .634  1.74  1168/941   5.6  \/\//\
GBP/USD             .000  1.55  1134/743   8.8  ///\//
GBP/USD:L           .274  1.55  1134/743   8.8  ///\//
GBP/USD:S           .000  ----    0/0      0.0  ......
USD/CAD             .492  3.15  653/181   49.5  ///\//
USD/CAD:L           .000  ----    0/0      0.0  ......
USD/CAD:S           .492  3.15  653/181   49.5  ///\//



Observed
Max open trades 1177
Expected
Max open trades should not exceed (num assets) * (tradesperbar) * (Exittime+1) = 7 * 2 * 19 = 266

Re: ExitTime not respected [Re: GPEngine] #441578
05/27/14 15:42
05/27/14 15:42
Joined: Jul 2000
Posts: 28,094
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,094
Frankfurt
If I remember right, you reported that already and I suggested to contact Support with details. We just need to know how you produced that problem - preferably with a script. The number of assets or the margin are not related to the exit time.

Re: ExitTime not respected [Re: jcl] #441588
05/28/14 02:34
05/28/14 02:34
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
This is the same symptom, but a different problem. I should have mentioned, I am not supplying an invalid value for Margin anymore.

Re: ExitTime not respected [Re: GPEngine] #441591
05/28/14 06:26
05/28/14 06:26
Joined: Jul 2000
Posts: 28,094
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,094
Frankfurt
Margin affects the trade volume, not the exit time. Thus, the problem must be elsewhere.

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

Joined: Sep 2013
Posts: 504
California
I will send a complete script to you via private message. Here I will post a redacted version.
Code:
#define PERTRADE 5263.15
string selected_asset;

function run() {
  BarPeriod = 79;
  LookBack = 501;
  StartDate = 20110401;
  EndDate = 20121001;
  set(TICKS + MUTE);
  set(RULES + FACTORS + TESTNOW + PLOTNOW);
  if (Train) {
    Hedge = 2;
  } else {
    set(NFA);
    Hedge = 4;
  }
  TradesPerBar = 2;
  Weekend = 1;
  ExitTime = 18;
  NumSampleCycles = 2;
  NumWFOCycles = 7;
  Confidence = 75;

  while(selected_asset = loop("EUR/CAD", "EUR/GBP", "EUR/USD")) {
    asset(selected_asset);

    var atrx = ATR(200);
    vars Price = series(price());
    var v00 = 0;  // redacted
    var v01 = 0;  // redacted
    var v02 = 0;  // redacted
    var v03 = 0;  // redacted
    var v04 = 0;  // redacted

    Stop = 3.9 * atrx;
    Trail = 4.7 * atrx;
    TrailLock = 26.4;
    TrailSlope = 86.4;
    TrailStep = 44.0;

    if (adviseLong(PERCEPTRON, 0, v00, v01, v02, v03, v04) > 0) {
      Margin = OptimalFLong * PERTRADE;
      enterLong();
    }
    if (adviseShort(PERCEPTRON, 0, v00, v01, v02, v03, v04) > 0) {
      Margin = OptimalFShort * PERTRADE;
      enterShort();
    }
  }
}



[Train] and [Test] produces a report with the following values.
Code:
Avg trade bars      38 (+39 / -37)
Max trade bars      870 (9 weeks)
Time in market      9156%
Max open trades     416


This should not be possible with ExitTime = 18.

Re: ExitTime not respected [Re: GPEngine] #441633
05/29/14 05:57
05/29/14 05:57
Joined: Jul 2000
Posts: 28,094
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,094
Frankfurt
Thanks for the script, but it won't produce a wrong exit time. The script that you sent by PM won't either.

So the problem is still elsewhere. If it's not the script, it can be the price data you're using. It seems that you downloaded it yourself. Check it for gaps - I've posted a gap checker some days ago. Gaps can delay the exit because a trade can't exit when no price data is available.

BTW, you normally don't need to guess in such a case. If trades behave wrong, check them on the chart. And look in the log and examine them in detail. Normally you can then quickly see the reason.

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

Joined: Sep 2013
Posts: 504
California
The theory about gaps in the data is interesting, but I don't think it explains the wild "Max open trades" result. If there are gaps, open trades cannot be exited, but new trades cannot be entered either, right? So, that theory may explain why "Avg trade bars" could exceed ExitTime. But it does not explain the accumulation of "Max open trades".

I have examined and grep'ed the test.log and do not see the reason. Many bars pass by in the test log. Then, suddenly Zorro closes hundreds of open trades in a single bar. The reason is, you have a bug. laugh

I will seek another script which reproduces the problem.

Re: ExitTime not respected [Re: GPEngine] #441642
05/29/14 14:40
05/29/14 14:40
Joined: Sep 2013
Posts: 504
California
G
GPEngine Offline OP
User
GPEngine  Offline OP
User
G

Joined: Sep 2013
Posts: 504
California
Thank you for your patience and open mind.

How about this one? Please look at Max open trades
Code:
Avg trade bars      7 (+10 / -4)
Max trade bars      41 (29 days)
Time in market      1508%
Max open trades     45



45 is greater than |assets| x TradesPerBar x ExitTIme = 3 x 2 x 2 = 12.

Code:
#define BANK 50000.0
string selected_asset;

function run() {
  BarPeriod = 720;
  LookBack = 501;
  StartDate = 20121021;
  EndDate = 20140421;
  set(TICKS + LOGFILE + MUTE);
  set(RULES + FACTORS + TESTNOW + PLOTNOW);
  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("EUR/CAD", "EUR/GBP", "EUR/USD")) {
    asset(selected_asset);
    var atrx = ATR(100);
    var v00 = WillR(100);
    vars Price = series(price());
    BBands(Price, 322, 0.2, 2.7, MAType_SMA);
    var v01 = (rRealUpperBand - priceClose()) / PIP;
    var v02 = DCOsc(Price, 265);
    var v03 = ATR(27);

    Stop = 4.0 * atrx;
    Trail = 2.0 * atrx;
    TrailLock = 25.0;
    
    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();
    }
  }
}


Here I will grep the test.log for all the info about an interesting trade, l0517.
Code:
$ grep -n '^\[13\|l0517' Log/ATR_027test.log 
1886:[1300: Fri 20.12. 00:00]  2: 618071p 144/174
1897:[1301: Fri 20.12. 12:00]  2: 622308p 142/178
1912:[1302: Sat 21.12. 00:00]  2: 634420p 139/185
1918:[1303: Mon 23.12. 00:00]  2: 642495p 142/183
1929:[1304: Mon 23.12. 12:00]  2: 638180p 138/189
1940:[1305: Tue 24.12. 00:00]  2: 636735p 140/189
1941:{EUR/CAD::l0517} Long 52@1.4543 Risk 1211$ tl at 00:00
1955:[1306: Tue 24.12. 12:00]  2: 639212p 143/190
1966:[1307: Thu 26.12. 00:00]  2: 641653p 144/191
1981:[1308: Thu 26.12. 12:00]  2: 646319p 149/190
1992:[1309: Fri 27.12. 00:00]  2: 642485p 159/182
2007:[1310: Fri 27.12. 12:00]  2: 647875p 173/172
2016:[1311: Sat 28.12. 00:00]  2: 634939p 174/172
2021:[1312: Mon 30.12. 00:00]  2: 642462p 174/172
2031:[1313: Mon 30.12. 12:00]  2: 654585p 174/174
2041:[1314: Tue 31.12. 00:00]  2: 666632p 174/176
2053:[1315: Tue 31.12. 12:00]  2: 659308p 172/180
2064:[1316: Thu 02.01. 00:00]  2: 667192p 174/181
2076:[1317: Thu 02.01. 12:00]  2: 674020p 168/189
2087:[1318: Fri 03.01. 00:00]  2: 674275p 170/190
2101:[1319: Fri 03.01. 12:00]  2: 688707p 160/202
2126:[1320: Sat 04.01. 00:00]  2: 673513p 161/203
2134:[1321: Mon 06.01. 00:00]  2: 657504p 162/203
2151:[1322: Mon 06.01. 12:00]  2: 670989p 162/206
2163:[1323: Tue 07.01. 00:00]  2: 666948p 166/204
2174:[1324: Tue 07.01. 12:00]  2: 665118p 177/196
2184:[1325: Wed 08.01. 00:00]  2: 662717p 187/188
2203:[1326: Wed 08.01. 12:00]  2: 670251p 191/186
2214:[1327: Thu 09.01. 00:00]  2: 689896p 194/184
2227:[1328: Thu 09.01. 12:00]  2: 711168p 193/187
2238:[1329: Fri 10.01. 00:00]  2: 721878p 193/189
2249:[1330: Fri 10.01. 12:00]  2: 729789p 196/188
2262:[1331: Sat 11.01. 00:00]  2: 750193p 193/193
2269:[1332: Mon 13.01. 00:00]  2: 763385p 194/193
2279:[1333: Mon 13.01. 12:00]  2: 776403p 194/194
2289:[1334: Tue 14.01. 00:00]  2: 794747p 194/196
2299:[1335: Tue 14.01. 12:00]  2: 810897p 194/198
2309:[1336: Wed 15.01. 00:00]  2: 828849p 196/198
2319:[1337: Wed 15.01. 12:00]  2: 852294p 205/191
2331:[1338: Thu 16.01. 00:00]  2: 885232p 208/190
2347:[1339: Thu 16.01. 12:00]  2: 905654p 207/193
2359:[1340: Fri 17.01. 00:00]  2: 930072p 207/195
2369:[1341: Fri 17.01. 12:00]  2: 948683p 214/190
2379:[1342: Sat 18.01. 00:00]  2: 955352p 217/188
2386:[1343: Mon 20.01. 00:00]  2: 959631p 218/188
2396:[1344: Mon 20.01. 12:00]  2: 979306p 217/190
2406:[1345: Tue 21.01. 00:00]  2: 992740p 219/190
2418:[1346: Tue 21.01. 12:00]  2: 1006122p 222/188
2430:[1347: Wed 22.01. 00:00]  2: 1027716p 217/194
2440:[1348: Wed 22.01. 12:00]  2: 1032914p 218/194
2445:{EUR/CAD::l0517} Sell 52@1.4857: +1466$ at 12:00
2478:[1349: Thu 23.01. 00:00]  2: 1111751p 221/199
2489:[1350: Thu 23.01. 12:00]  2: 1122354p 217/205
2499:[1351: Fri 24.01. 00:00]  2: 1154772p 217/206
2507:[1352: Fri 24.01. 12:00]  2: 1154562p 217/207
2517:[1353: Sat 25.01. 00:00]  2: 1190357p 217/208



Why does Zorro wait until bar 1348 to close l0517? That's the entry point + 43 bars, many multiples of my ExitTime, 2. It's not that there isn't an opportunity to exit at market before that. There is EUR/CAD action two bars before that, in 1346. See?
Code:
$ grep -n -A10 '^\[134[67]' Log/ATR_027test.log
2418:[1346: Tue 21.01. 12:00]  2: 1006122p 222/188
2419-[EUR/CAD::S] Skipped: Lots/Margin = 0
2420-[EUR/GBP::L] Skipped: Lots/Margin = 0
2421-{EUR/USD::l4663} Long 81@1.3524 Risk 1731$ tl at 12:00
2422-[EUR/USD::S2389] Cover 81@1.3524: +638$ at 12:00
2423-{EUR/CAD::l0412} Sell 52@1.4892: +1774$ at 12:00
2424-[EUR/CAD::L1457] Sell 52@1.4892: +893$ at 12:00
2425-{EUR/USD::s1458} Cover 76@1.3524: +2120$ at 12:00
2426-[EUR/USD::S4154] Cover 76@1.3524: +537$ at 12:00
2427-{EUR/USD::l4356} Sell 81@1.3524: -56.52 at 00:00
2428-[EUR/USD::S4764] Short 81@1.3524 Net trade at 00:00
--
2430:[1347: Wed 22.01. 00:00]  2: 1027716p 217/194
2431-[EUR/CAD::S] Skipped: Lots/Margin = 0
2432-[EUR/GBP::L] Skipped: Lots/Margin = 0
2433-{EUR/USD::l4765} Long 81@1.3558 Risk 1738$ tl at 00:00
2434-[EUR/USD::S2494] Cover 81@1.3558: +567$ at 00:00
2435-{EUR/USD::s0415} Cover 76@1.3558: +944$ at 00:00
2436-[EUR/USD::S4459] Cover 76@1.3558: -46.92 at 00:00
2437-{EUR/USD::l4561} Sell 81@1.3558: +72.13 at 12:00
2438-[EUR/USD::S4866] Short 81@1.3558 Net trade at 12:00
2439-
2440-[1348: Wed 22.01. 12:00]  2: 1032914p 218/194



And by they way, since I've just shown a trade that was held open for 43 bars, shouldn't Max trade bars be at least 43 in the Performance report? It says 41.

The attached gz file contains the Strategy, learned parameters, fac, test.log, and train.log.

The Strategy earns alot in Dec-Feb by ignoring my ExitTime. That's great. Perhaps it knows something I don't ! But, it's my robot. It should do what I tell it to do.

Last edited by GPEngine; 05/29/14 14:43. Reason: s/EUR/USD/EUR/CAD
Re: ExitTime not respected [Re: GPEngine] #441651
05/29/14 16:05
05/29/14 16:05
Joined: Jul 2000
Posts: 28,094
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,094
Frankfurt
I can not tell if "Max open trades" is correct or not. You are virtual hedging, so the number of open trades is anyway different than your calculation above. Max open trades can be any number. But as far as I see, there is indeed something wrong in your log - not only the exit time, I see also no net trade opened or closed for the phantom trade.

I could not reproduce any of those problem with your scripts, so can you try to produce such a problem not with your downloaded prices, but with the standard assets that come with Zorro? If then there's still something wrong, I can at least check it here and tell you the reason.

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

Joined: Sep 2013
Posts: 504
California
I anticipated this. Stand by.

Page 1 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