I have read http://zorro-trader.com/manual/en/advisor.htm and http://zorro-trader.com/manual/en/tutorial_pre.htm (Workshop7). I have been working under the assumption that the models built by adviseLong and adviseShort were independent. I tested this assumption and found it is not the case. I get very different results depending on whether I call adviseLong followed by adviseShort, or the other way around.
Code:
#define LONG_FIRST
function run() {
if (is(INITRUN)) {
BarPeriod = 80;
BarOffset = 40;
LookBack = 245;
NumWFOCycles = 6;
StartDate = 20130601;
EndDate = 20131230;
set(NFA + TICKS + RULES + TESTNOW + PLOTNOW + LOGFILE);
TradesPerBar = 2;
Weekend = 1;
Hedge = 4;
}
vars ol = series((priceOpen(0) - priceLow(0)) / PIP);
var v00 = APO(ol, 4, 7, MAType_WMA);
var v01 = APO(ol, 148, 245, MAType_TRIMA);
polyfit(0, ol, 24, 2, 1);
var v02 = polynom(0, -1);
TakeProfit = 3 * ATR(100);
Stop = 3 * ATR(100);
int al;
int as;
#ifdef LONG_FIRST
al = adviseLong(PERCEPTRON, 0, v00, v01, v02);
if (al > 0) {
enterLong();
}
as = adviseShort();
if (as > 0) {
enterShort();
}
#else
as = adviseShort(PERCEPTRON, 0, v00, v01, v02);
if (as > 0) {
enterShort();
}
al = adviseLong();
if (al > 0) {
enterLong();
}
#endif
plot("al", al, LINE + NEW , BLUE);
plot("as", as, LINE, RED);
}
[Train] with #define LONG_FIRST ==> Annual loss -28325p [Train] without #define LONG_FIRST ==> Annual +42% +9366p
I attached the Performance Chart as long_then_short.png and short_then_long.png, respectively.
Additional observations. Whichever model is first will have little variation and will always have the values -100 or 100. Whichever model is second will have reasonable variation and the values vary depending on cycle. I observed +/- 48, 55, and 53. See red/blue chart in the attached images.
I expected it to not matter which one is called first, since the outcome of only the very next enterLong/enterShort forms the prediction with which to train the model.
Quote:
Prediction Value to be trained for prediction by the current Signal combination. Either a positive value for suggesting a trade, or a negative value for advising against a trade, or 0 for using the result of the next trade for prediction. This parameter is only used in the training run and has no meaning in test or trade mode.
Can you please shed some light on this?
Re: Different Result depending on Order of adviseLong / adviceShort
[Re: GPEngine]
#435723 01/12/1400:3401/12/1400:34
Reviving this thread. This is still a huge problem for me.
These two scripts give different results. Can anyone explain why? The only difference is the order that adviseLong+enterLong and adviseShort+enterShort appear in the code.
adviseLong first --> Annual +9% +555p adviseShort first --> Annual +37% +985p
During training, adviseLong and adviseShort return True unconditionally. So, Zorro makes a trade (2 trades in this case) unconditionally at every single bar. This is how Zorro knows what target to train against. These trades all need to be independent with no interference. The account state, other open trades, etc., should not play a role.
Re: Different Result depending on Order of adviseLong / adviceShort
[Re: GPEngine]
#440531 04/27/1415:5404/27/1415:54
I see that the order long/short might play a small role in the Test phase, when perhaps both orders compete for entry at the same bar. But I think this would be rare -- it would have to mean that both adviseLong and adviseShort return True in Test mode at a certain bar.
But, anyway, that's not what happening. I am getting different generated code in Data/ . Meaning Zorro's Train output is depending on the order of adviseLong/adviseShort. That shouldn't happen.
Re: Different Result depending on Order of adviseLong / adviceShort
[Re: GPEngine]
#440535 04/27/1417:0204/27/1417:02
Guessing and assuming is no good when you develop a system - you need to definitely _know_ what your script is doing. For this you have the log. Just compare the logs of different script versions and you can see immediateley how and why your script changes affect the single trades.
As you see, the order of long/short can heavily affect performance unless your trades are really independent. But this is not the case here due to your hedge setting. Orders can not "compete", but spread losses by netting always depend on which order comes first.
Re: Different Result depending on Order of adviseLong / adviceShort
[Re: jcl]
#440545 04/27/1419:1504/27/1419:15
That is good advice. In my own testing I have concluded that I have once again been burned by the fact that set(NFA) is not compatible with Train and causes training targets to be corrupt due to interference with each other that would not happen during Test/Trade mode.
Do you agree that this is possible?
Last edited by GPEngine; 04/27/1419:16.
Re: Different Result depending on Order of adviseLong / adviceShort
[Re: GPEngine]
#440594 04/28/1414:3904/28/1414:39