Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding?

Posted By: laz

Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/21/19 10:32

OFF-TOPIC
Hi guys, this is my first post here and I'm really excited to be here. Many thanks to the creators of Zorro, you have really developed a great program - its surface is tiny - but there is something in it. Thank you also for the effort you put into assisting your users. I've been programming for many years, but I'm new to Lite-C and Zorro. English is not my mother tongue and everything I know about programming I have taught myself. That's why I sometimes express myself inaccurately or wrongly, thanks for your understanding.
OFF-TOPIC


I've found 2 errors, maybe I've also programmed something wrong, please take a look at it. I've upload 4 files to test with, parameter_test_"1-4".c.

Let's start with file (parameter_test_1.c)...

After [TRAIN] everything looks fine, training is fast and we get some results. We have optimized 2 parameters, we see 2 pictures in the parameter charts htm file.

If we change only 1 line in the code now, the problems will start: (in parameter_test_2.c)
Code:
while(asset(loop("EURUSD")))
while(algo(loop("TRND"))) {

changes to:

while(asset(loop("EURUSD")))
while(algo(loop("TRND:L","TRND:S"))) {


We now need twice as long as we train 2 different components, that's normal. We should now be able to see parameter charts
in which the optimized values for 2x2 parameters are visible. Zorro creates a parameter chart with 4 images,
but if you look closer, the 2 x 2 are the same?
Code:
<h1>parameter_test_2 Parameter Charts</h1>
<p> EURUSD TRND Parameter 1 (10 Cycles Average: 172.1)<br> <br><img src="parameter_test_2_EURUSD_TRND_p1.png"></p>
<p> EURUSD TRND Parameter 2 (10 Cycles Average: 1.798)<br> <br><img src="parameter_test_2_EURUSD_TRND_p2.png"></p>
<p> EURUSD TRND Parameter 1 (10 Cycles Average: 172.1)<br> <br><img src="parameter_test_2_EURUSD_TRND_p1.png"></p>
<p> EURUSD TRND Parameter 2 (10 Cycles Average: 1.798)<br> <br><img src="parameter_test_2_EURUSD_TRND_p2.png"></p>


Here is the first problem, test it with parameter_test_2.c
It shows 4 but only 2 not 2X2=4 graphics have been created, "parameter_test_2_EURUSD_TRND_p1.png" and "parameter_test_2_EURUSD_TRND_p2.png".

Not 2 for :L and 2 for :S...

Has anyone noticed this or have I already done something wrong here? I thought it was because I forgot to assign
the enterLong and enterShort to the respective component. So let's do that:(in parameter_test_3.c)
Code:
if(valley(sig)) enterLong(); else
if(peak(sig)) enterShort();

changes to:

if(strstr(Algo,":L") && valley(sig)) enterLong(); else
if(strstr(Algo,":S") && peak(sig)) enterShort();


At this point, something was strange, Zorro was slowing down and you can see that the runtimes have increased.
Code:
EXITRUN @ bar 9955 time = 3234.774 ms
EXITRUN @ bar 9955 time = 6970.485 ms


Nothing strange in the log file, only the runtimes are much larger. I stopped it, it's time to make Verbose more active.

Does that happen because Zorro does not close the trades anymore? Or is something crashing here?
I changed the script and added exitLong() and exitShort() in (parameter_test_4.c). This works and is just as fast as version parameter_test_2.

But... Unfortunately at the end of this trip I realized that the parameter charts from parameter_test_4.c are still wrong wink...

Thanks for your help laugh

[EDIT] I've removed the part with diag and Chinese signs in it because that seems to be only here for me...

Attached File
parameter_test_1.c  (36 downloads)
Attached File
parameter_test_2.c  (51 downloads)
Attached File
parameter_test_3.c  (57 downloads)
Attached File
parameter_test_4.c  (37 downloads)
Posted By: AndrewAMD

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/21/19 15:32

Since most of us don't have the time to download your zip file and dig through your stuff, consider boiling down your question to a single miniature-sized script and say, "I expect X, but I get Y". You'll get answers quickly that way. laugh
Posted By: laz

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/21/19 16:51

Hi Andrew. I have added all files and i changed my first post to make it more clear.

In short:

parameter_test_1.c runs fine, but has only 1 component called TRND.
parameter_test_2.c runs fine, we now use 2 components TRND:L & TRND:S but parameter chart is wrong, it shows 2 times the same pictures
parameter_test_3.c is slow has many open handles and it sometimes creates chinese signs in diag file (for me with Verbose = 7|DIAG; enabled )
parameter_test_4.c runs fine but the parameter chart is still wrong

I think the problem in parameter_test_3.c are the open trades, it does not close the trades anymore or something else is going wrong. I'm confused because of the chinese signs in diagfile.

I hope it's more clear now wink...
Posted By: Dalla

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/21/19 18:53

One thing I would try is to name the algos something other than
TRND:L and TRND:S. Maybe just TRNDL and TRNDL. Since the strategy report short long/short trades using the :L/:S suffix, maybe they are used internally by Zorro.
Posted By: laz

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/21/19 19:37

Hi Dalla, that works but the manual says:

http://manual.zorro-trader.com/algo.htm

Quote:
If different algorithms or parameters for long and short trades are used, the identifiers should end with ":L" or ":S" for being consistent with the trade names used in the message window and parameter files. Long trades should be suppressed by script on ":S" algos and vice versa.

Thanks for the hint, did I get it wrong?

Incidentally, I have already tried that, then you have an OptimalF for the component but either OptimalFLong = 0 or OptimalFShort = 0.

(TRENDL -> OptimalFLong has a value and OptimalFShort = 0) or
(TRENDS -> OptimalFShort has a value and OptimalFLong = 0)
Posted By: Dalla

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/22/19 09:04

It was just a thought, but you should probably trust the manual rather than me :-)
Posted By: laz

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/22/19 17:16

Hello Dalla smile. I know you, because I've read a lot of you here in the forum, by Andrew too. I respect you guys and know that you are experienced Zorro users...

By the way, the problem with the Chinese characters in diag file seems to be a problem only with me, I had that yesterday with another script. When opening the diag file with gedit there are sometimes cryptic unreadable characters in it.

I hope you are not angry with me that I do not implement the tip, as you can see here there are several different sources in which :L and :S are used:

https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=407922
https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=408151#Post408151
http://www.forexfabrik.de/topic/3273-zorro-trader
https://forums.babypips.com/t/automated-trading-course-part-2-strategy-design/46305/24

Jcl has posted:
Quote:
They are the same algorithms as before, only now separately for long and short trades by adding a “:L” or a “:S” to the algorithm identifier. Accordingly, some code within the trade functions must ensure that only the right sort of trades are opened:

if(strstr(Algo,":L") and crossUnder(Signal,-Threshold))
enterLong();
else if(strstr(Algo,":S") and crossOver(Signal,Threshold))
enterShort();

But the links they are very old, some are from 2012...? I'm just wondering why this has not been noticed yet, so I was also unsure if I even ask;).

Please check the attached script, the "Parameter Charts" it generates are clearly wrong. It shows the same pictures twice?

Attached File
babypips_jcl_LS.c  (37 downloads)
Posted By: AndrewAMD

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/23/19 02:54

You have the **option** of using separate ":L" and ":S" suffixed algos, and now you can see the consequences of this approach.

It is easier to keep the algo names completely different in the first place, because:

1) They are more distinct in all respects (such as chart names), and
2) Optimal F values will not be assigned to algo longs/shorts where trades do not take place.
3) Since you will be **required** to only do long trades with ":L" and short with ":S", you will find that there is not much difference anyways.

EDIT:
Why not do both? A unique algo name **and** “:L” or “:S” at the end?
Posted By: laz

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/23/19 20:10

Quote:
You have the **option** of using separate ":L" and ":S" suffixed algos, and now you can see the consequences of this approach.

crazy smirk
Quote:
You got a car with 5 gears, but if you switch to the 5 gear you will find the engine out below. Then you go to the dealer and he says: "You have the option to use 5 gears, now you see the consequences..."

tongue

Haha sorry that was a joke, I use Zorro for free and do not want to complain. But it would be great if they could fix that, actually everything works great, except that the parameter charts are wrong.

The other suggestions are possible as a workaround, but I wanted to know if I made a mistake or the program. And actually, I was pretty surprised that so far no one noticed it.

Zorro even seems to calculate the parameters internally, only the images shown in "Parameter Charts" are wrong.

Code:
EURUSD CNTR Parameter 2 (8 Cycles Average: 0.878)
EURUSD CNTR Parameter 2 (8 Cycles Average: 1.173)


correct:
Code:
EURUSD CNTR:L Parameter 2 (8 Cycles Average: 0.878)
EURUSD CNTR:S Parameter 2 (8 Cycles Average: 1.173)

Posted By: AndrewAMD

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/23/19 20:20

Does your car not have a manual transmission? You learn how to use it by combining proper instruction with real experience. laugh

This is my recommendation: instead of this:

Code:
loop("TRND:L","TRND:S")



Do this:

Code:
loop("TRNDL:L","TRNDS:S")

Posted By: laz

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/23/19 20:55

But then I get all the results twice sick...

I think I prefer to do it with "ALGO:L & ALGO:S" without the parameter chart first.

I just have to check again if at least the resulting fac and par values with

"TREND: L + TREND: S"

and

"TRENDL: L + TRENDS: S"

are identical.
Posted By: AndrewAMD

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/23/19 21:01

Does parameter_test_1 take about as much time to process as parameter_test_2?
Posted By: laz

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/23/19 21:15

parameter_test_1
Code:
while(asset(loop("EURUSD")))
while(algo(loop("TRND"))) {

changes in parameter_test_2 to:
Code:
while(asset(loop("EURUSD")))
while(algo(loop("TRND:L","TRND:S"))) {


Script parameter_test_2 now need twice as long as we train 2 different components...

But as I write this I wonder, why was parameter_test_3 so slow, I have to look at it again...
I do not really know, what the problem was.

Quote:
parameter_test_1 - runtime about 3 minutes from first _1.par to .fac file
parameter_test_2 - runtime about 7 minutes from first _1.par to .fac file
parameter_test_3 - i stopped it, it's getting slower and slower, why?
parameter_test_4 - runtime about 5 minutes from first _1.par to .fac file

Internal Timer from FIRSTINITRUN to EXITRUN

parameter_test_1
Quote:
EXITRUN @ bar 10035 time = 501.353 ms
EXITRUN @ bar 10035 time = 493.324 ms
EXITRUN @ bar 10035 time = 487.299 ms
EXITRUN @ bar 10035 time = 487.029 ms
parameter_test_2
Quote:
EXITRUN @ bar 10035 time = 493.028 ms
EXITRUN @ bar 10035 time = 495.644 ms
EXITRUN @ bar 10035 time = 503.310 ms
EXITRUN @ bar 10035 time = 493.658 ms
parameter_test_3
Quote:
EXITRUN @ bar 10035 time = 12252.315 ms
EXITRUN @ bar 10035 time = 10282.861 ms
EXITRUN @ bar 10035 time = 10487.490 ms
EXITRUN @ bar 10035 time = 9688.894 ms
parameter_test_4
Quote:
EXITRUN @ bar 10035 time = 350.156 ms
EXITRUN @ bar 10035 time = 351.938 ms
EXITRUN @ bar 10035 time = 346.190 ms
EXITRUN @ bar 10035 time = 345.802 ms

I don't know why test_4 is faster but it's good smile.
Posted By: AndrewAMD

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/23/19 21:27

Does parameter_test_5 take longer than parameter_test_2?

Test #5 does this:
loop("TRNDL:L","TRNDS:S")

You know how strstr works.

My hypothesis is that Test #5 == Test #2 > Test #1 (time consumed)
Posted By: AndrewAMD

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/23/19 21:31

I'm assuming that test #3 is time consuming because it might be I/O intensive.

EDIT: Disregard, I thought verbose was high.
Posted By: laz

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/23/19 21:56

Quote:
I'm assuming that test #3 is time consuming because it might be I/O intensive.

Can you please explain more, the runtimes look very suspicious.

Training for test_5 is running, i think it will take the same time as test_2 & test_4.

Quote:
parameter_test_1 - runtime about 3 minutes from first _1.par to .fac file
parameter_test_2 - runtime about 7 minutes from first _1.par to .fac file
parameter_test_3 - i stopped it, it's getting slower and slower, why?
parameter_test_4 - runtime about 5 minutes from first _1.par to .fac file
parameter_test_5 - runtime about 6 minutes from first _1.par to .fac file

parameter_test_5
Quote:
EXITRUN @ bar 22787 time = 386.639 ms
EXITRUN @ bar 22787 time = 386.281 ms
EXITRUN @ bar 22787 time = 390.088 ms
EXITRUN @ bar 22787 time = 396.646 ms


Attached File
parameter_test_5.c  (30 downloads)
Posted By: laz

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/23/19 22:14

The strange thing is, jcl does it in the same way as i did in #3, his script runs fine...?

babypips_jcl_LS.c
Quote:
if(strstr(Algo,":L") and valley(Trend)) enterLong(); else
if(strstr(Algo,":S") and peak(Trend)) enterShort();

parameter_test_3
Code:
if(strstr(Algo,":L") && valley(sig)) enterLong(); else
if(strstr(Algo,":S") && peak(sig))   enterShort();


EDIT:
I think I found a possible explanation (maybe)?
Quote:
Hedge
0 = no hedging; automatically close opposite positions with the same asset when a new position is opened (default for NFA accounts).
1 = hedging across algos; automatically close opposite positions with the same algo when a new position is opened (default for unspecified accounts).
2 = full hedging; long and short positions can be open at the same time.

From test_1 to test_3 I'm in Hedge = 1 (default for me).

But in test_3 I'm limiting enterLong() + enterShort() to :L or :S
Code:
if(strstr(Algo,":L") && valley(sig)) enterLong(); else
if(strstr(Algo,":S") && peak(sig))   enterShort();


Because of that:
Quote:
while(algo(loop("TRND:L","TRND:S")))

Does Zorro now handle TRND:L and TRND:S as "the same" or 2 different Algos?

If so, we never have a enterLong() & (exit short) for TRND:S and never a enterShort() & (exit long) for TRND:L.

Result = Open trades are no longer closed?

That would explain why test_4 works correctly, there I have Hedge = 2 and i correctly close the open orders in the respective algo.

There is only 1 open question, why does it work in the jcl babypips script, there is no Hedge set, so it is also Hedge = 1...?

Attached File
babypips_jcl_LS.c  (30 downloads)
Posted By: laz

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/24/19 01:22

Ok I had a guess, but what I'm telling you now was too significant, so I wanted to be sure.

Because if I'm right then many examples that were posted everywhere are wrong!

In the babypips_jcl_LS.c I set the barperiod to = 60 (more trades) and it also got extremely slow.

So I thought, if my suspicion is right, there must be more than 1-2 trades open at the same time.

Please download new versions of #2 and #3 and hit TRAIN :

parameter_test_2 works as intended, in the train.log I never found more than 2 open trades.

Take a look at the train.log of parameter_test_3, there are 20,30,40 open trades.

Whatever ends the trades (End of WFOCycle?), it is not your function!

That would mean all the examples:
https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=407922
https://opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=408151#Post408151
http://www.forexfabrik.de/topic/3273-zorro-trader
https://forums.babypips.com/t/automated-trading-course-part-2-strategy-design/46305/24

are wrong?

Can one check this please, it can be the solution to a lot of questions...

Attached File
parameter_test_2.c  (24 downloads)
Attached File
parameter_test_3.c  (25 downloads)
Posted By: jcl

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/25/19 19:21

The ":L" and ":S" suffixes to algo names are from an early Zorro version. I have no notice of discontinuation, so theoretically they should still work, but otherwise please use "TRNDL" and "TRNDS" at the moment. We'll look into that.
Posted By: laz

Re: Using ":L" & ":S" causes 2 possible bug(s) or is it bad coding? - 01/26/19 04:38

OFFTOPIC
Hi jcl, nice to meet you wink ... Thanks for everything here, I do not know who is behind the project but you (guys) did a really good job. Zorro's framework is great & takes a lot off, I already had the r-bridge in my own dll (freepascal) and the WFO coded in R but i was still missing so much, zorro makes it all superfluous wink.
OFFTOPIC


Quote:
The ":L" and ":S" suffixes to algo names are from an early Zorro version.

Please don't remove it wink It would be nice if you can fix only 1 thing:

1. wrong parameter charts with :L & :S

Why ?

:L & :S make it possible to combine/use both adviseLong/adviseShort Calls for LONG and
both for SHORT as we have different components now wink. So we can use 2 perceptrons or neural nets for 1 direction.


But TRNDL & TRNDS are ok for the moment wink

Problem 2, the open trades can be solved by understanding that by using :L & :S
you now use 2 different algo's and that your script has to close open trades.

Because enterLong() and enterShort() are not doing it for you with :L & :S.

This should be correct?
Code:
if(strstr(Algo,":L")) {
	
   if(peak(sig))   exitLong(); else 
   if(valley(sig)) enterLong();

} else if(strstr(Algo,":S")) {

   if(valley(sig)) exitShort(); else		
   if(peak(sig))   enterShort();

}

© 2024 lite-C Forums