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
3 registered members (7th_zorro, TipmyPip, RealSerious3D), 892 guests, and 4 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
How to combine strategies #486149
06/13/22 08:27
06/13/22 08:27
Joined: Feb 2022
Posts: 21
T
TrumpLost Offline OP
Newbie
TrumpLost  Offline OP
Newbie
T

Joined: Feb 2022
Posts: 21
I have two trading rules which reference NumOpenTotal to apply either the entry or the exit logic. This seems to work fine for very simple strategies, but how do I make this work if I'm holding multiple positions or if I want to apply multiple rules to the same asset? Here's some example code:

Rule 1:
Code
    if(NumOpenTotal == 0) {
        if(rising(TrendROC) && TrendROC[0] > TrendROCLimit) enterLong();
        if(falling(TrendROC) && TrendROC[0] < -TrendROCLimit) enterShort();
    }
    if(NumOpenTotal > 0) {
        if(peak(TrendROC)) exitLong();
        if(valley(TrendROC)) exitShort();
    }


Rule 2:
Code
    if(NumOpenTotal == 0 && IsTrending) {
        if(rising(Trend))
            enterLong();
        if(falling(Trend))
            enterShort();
    }
    if(NumOpenTotal > 0) {
        if(peak(TrendROC)) exitLong();
        if(valley(TrendROC)) exitShort();
    }


These both look great independently but together the results look totally messed up. Is there a simple solution?

Last edited by TrumpLost; 06/13/22 08:30.
Re: How to combine strategies [Re: TrumpLost] #486150
06/13/22 09:49
06/13/22 09:49
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
By replacing NumOpenTotal with an array that contains individual open position values for each individual asset. Than you put your code in an asset loop with a counter that refers to the asset's array position for your trading rules.

Last edited by Grant; 06/13/22 23:02.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1