Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TipmyPip, AndrewAMD), 911 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Elegant way to trade every nth week #484891
12/27/21 10:44
12/27/21 10:44
Joined: Mar 2018
Posts: 8
V
VHX Offline OP
Newbie
VHX  Offline OP
Newbie
V

Joined: Mar 2018
Posts: 8
Hi,
is there an elegant way to trade e.g. every 5th week and on different days (e.g. Tuesday in week 1, Thursday in week 6,...). I tried it with something like

if(week(0)%5 == 1) {...}

which works for one year, but if the script moves on to the next year this does not work propperly, as it trades in week 51 of the current year and then again in week 1 of the next year. Using the Bar number directly also does not work properly, because of missing trading day (holidays etc.).

Also, I only want to trade once per week, so if I am in the right week I can select Tuesday with dow(0)==2, but if I also have a condition for Thursday, it would also trad Thursday that week. Do I then have to flag it with something like

boolean tradedThisWeek = True;

and toggle that accordingly? Or is there an easier, more elegant way to do this?

Re: Elegant way to trade every nth week [Re: VHX] #484892
12/27/21 11:04
12/27/21 11:04
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
static int Weeknum = 0;
if(week(0) != week(1)) Weeknum = (Weeknum+1) % 5;
if(Weeknum == 0 && dow(0) == TUESDAY) ...
...

Re: Elegant way to trade every nth week [Re: Petra] #484893
12/27/21 16:25
12/27/21 16:25
Joined: Mar 2018
Posts: 8
V
VHX Offline OP
Newbie
VHX  Offline OP
Newbie
V

Joined: Mar 2018
Posts: 8
Thanks Petra,
that piece of code does work well during the year, but at the end of the year you'll get shorter periods (as there are sometimes weeks with only 1 day, i.e. Mon 18-12-31 is only one day in week 53, so on Wed 19-01-02 you'll increase Weeknum too early). And you'll get longer periods if you are in the right week, but if the stock markets were closed that TUESDAY.

Re: Elegant way to trade every nth week [Re: VHX] #484894
12/27/21 17:53
12/27/21 17:53
Joined: Jul 2017
Posts: 784
Z
Zheka Offline
User
Zheka  Offline
User
Z

Joined: Jul 2017
Posts: 784
To solve the problem of holidays/'missing data', try playing with BR_FLAT.


Moderated by  Petra 

Gamestudio download | chip programmers | 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