Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (TipmyPip, AndrewAMD, dBc), 18,430 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 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: 311
Netherlands
G
Grant Offline
Senior Member
Grant  Offline
Senior Member
G

Joined: Aug 2017
Posts: 311
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