The more I debug the more I am confused. I tested 3 different situations and got 3 different results. But all tested Zorro versions behave identical. RTG, you got a lucky Zorro version! And sorry for the long post but most of it are extracts from log files.
within the run function, that will print each bar the Asset, both SMAs and additionally (1|0) if a SMA is falling or (0|1) if a SMA is rising.
Further the run function contains both conditions and prints additional statements if the conditions become true:
Code:
if (dow() == 5 && NumOpenLong == 0 && NumPendingLong == 0 && SMAShort[0] > SMALong[0] && rising(SMAShort) && rising(SMALong)) {
Margin = 0.1 * OptimalFLong * Capital;
printf("\nNow I setup a long trade with a margin of %.5f and a BuyStop of %.5f",Margin,BuyStop);
enterLong(0,BuyStop);
}
else if (dow() == 5 && NumOpenShort == 0 && NumPendingShort == 0 && SMAShort[0] < SMALong[0] && falling(SMAShort) && falling(SMALong)) {
Margin = 0.1 * OptimalFShort * Capital;
printf("\nNow I setup a short trade with a margin of %.5f and a SellStop of %.5f",Margin,SellStop);
enterShort(0,SellStop);
}
In live trading today for Zorro the conditions do not become true. The results of today:
But there are no "Now I setup ..." prints, so Zorro does not recognize the conditions are true, although in 7 cases they are.
In backtest it depends - if the simulation ends on a Friday, then you will find like for today:
Code:
[229: Fri 20.11.15 00:00]
AUD/JPY: SMAShort:87.65658 (0|1), SMALong: 86.45531 (1|0)
AUD/USD: SMAShort:0.71160 (1|0), SMALong: 0.71498 (1|0)
Now I setup a short trade with a margin of 18.10000 and a SellStop of 0.70153
CHF/JPY: SMAShort:122.14400 (1|0), SMALong: 123.27348 (1|0)
Now I setup a short trade with a margin of 99.90000 and a SellStop of 120.74000
EUR/JPY: SMAShort:132.21563 (1|0), SMALong: 133.87261 (1|0)
Now I setup a short trade with a margin of 99.90000 and a SellStop of 130.63700
EUR/USD: SMAShort:1.07096 (1|0), SMALong: 1.11471 (1|0)
Now I setup a short trade with a margin of 53.10000 and a SellStop of 1.06160
GBP/USD: SMAShort:1.52221 (0|1), SMALong: 1.52886 (0|1)
NZD/CHF: SMAShort:0.65756 (0|1), SMALong: 0.64893 (0|1)
Now I setup a long trade with a margin of 0.00000 and a BuyStop of 0.66823
NZD/JPY: SMAShort:80.37250 (1|0), SMALong: 79.50871 (0|1)
USD/CHF: SMAShort:1.00745 (0|1), SMALong: 0.98147 (0|1)
Now I setup a long trade with a margin of 99.90000 and a BuyStop of 1.02221
USD/JPY: SMAShort:123.01745 (0|1), SMALong: 120.91655 (1|0)
USOil: SMAShort:43.51261 (1|0), SMALong: 44.73911 (1|0)
Now I setup a short trade with a margin of 22.60000 and a SellStop of 39.91000
In contrast to live trading Zorro confirms at least the 7 true conditions in the backtest of today as you can see printed, but it does not setup trades. I can imagine that Zorro does not setup new trades on the very last day/bar of the simulation.
This can be adjusted e.g. also for last Friday with "EndDate = 20151113;" and the result is similar:
Code:
[224: Fri 13.11.15 00:00]
AUD/JPY: SMAShort:86.99101 (0|1), SMALong: 86.74006 (1|0)
AUD/USD: SMAShort:0.71483 (1|0), SMALong: 0.71665 (1|0)
Now I setup a short trade with a margin of 18.10000 and a SellStop of 0.70153
CHF/JPY: SMAShort:122.79858 (1|0), SMALong: 123.53941 (1|0)
Now I setup a short trade with a margin of 99.90000 and a SellStop of 121.67200
EUR/JPY: SMAShort:132.70861 (1|0), SMALong: 134.26398 (1|0)
Now I setup a short trade with a margin of 99.90000 and a SellStop of 131.46501
EUR/USD: SMAShort:1.07799 (1|0), SMALong: 1.11715 (1|0)
Now I setup a short trade with a margin of 53.10000 and a SellStop of 1.06735
GBP/USD: SMAShort:1.51720 (1|0), SMALong: 1.53036 (1|0)
Now I setup a short trade with a margin of 63.20000 and a SellStop of 1.50264
NZD/CHF: SMAShort:0.66013 (1|0), SMALong: 0.64352 (0|1)
NZD/JPY: SMAShort:80.84656 (1|0), SMALong: 79.08822 (0|1)
USD/CHF: SMAShort:0.99684 (0|1), SMALong: 0.97678 (0|1)
Now I setup a long trade with a margin of 99.90000 and a BuyStop of 1.00885
USD/JPY: SMAShort:121.99323 (0|1), SMALong: 121.02335 (1|0)
USOil: SMAShort:45.06625 (1|0), SMALong: 44.92631 (1|0)
Only if you include at least the following Monday (here: EndDate = 20151116) then you'll see the result like expected in all cases - Zorro setup trades if the conditions become true:
Code:
[224: Fri 13.11.15 00:00]
AUD/JPY: SMAShort:86.99101 (0|1), SMALong: 86.74006 (1|0)
AUD/USD: SMAShort:0.71483 (1|0), SMALong: 0.71665 (1|0)
Now I setup a short trade with a margin of 18.10000 and a SellStop of 0.70153
(AUD/USD::S) Short 2@0.7015 Entry stop
CHF/JPY: SMAShort:122.79858 (1|0), SMALong: 123.53941 (1|0)
Now I setup a short trade with a margin of 99.90000 and a SellStop of 121.67200
(CHF/JPY::S) Short 2@121.67 Entry stop
EUR/JPY: SMAShort:132.70861 (1|0), SMALong: 134.26398 (1|0)
Now I setup a short trade with a margin of 99.90000 and a SellStop of 131.46501
(EUR/JPY::S) Short 10@131.47 Entry stop
EUR/USD: SMAShort:1.07799 (1|0), SMALong: 1.11715 (1|0)
Now I setup a short trade with a margin of 53.10000 and a SellStop of 1.06735
(EUR/USD::S) Short 5@1.0674 Entry stop
GBP/USD: SMAShort:1.51720 (1|0), SMALong: 1.53036 (1|0)
Now I setup a short trade with a margin of 63.20000 and a SellStop of 1.50264
(GBP/USD::S) Short 4@1.5026 Entry stop
NZD/CHF: SMAShort:0.66013 (1|0), SMALong: 0.64352 (0|1)
NZD/JPY: SMAShort:80.84656 (1|0), SMALong: 79.08822 (0|1)
USD/CHF: SMAShort:0.99684 (0|1), SMALong: 0.97678 (0|1)
Now I setup a long trade with a margin of 99.90000 and a BuyStop of 1.00885
(USD/CHF::L) Long 2@1.0088 Entry stop
USD/JPY: SMAShort:121.99323 (0|1), SMALong: 121.02335 (1|0)
USOil: SMAShort:45.06625 (1|0), SMALong: 44.92631 (1|0)
[...]
[225: Mon 16.11.15 00:00]
The main question is why Zorro does not recognize in live trading if the conditions become true while it does in backtest. Sure, I cannot exclude an error in the script, but I would really like to know where it is because I can't see it.
The results in live trading are identical with 1.32, 1.36 and 1.38, the simulation is done with 1.36 only.