Gamestudio Links
Zorro Links
Newest Posts
Zorro version 3.0 prerelease!
by jcl. 02/12/26 14:05
MarginCost discrepancy?
by jcl. 02/12/26 14:02
Hedge on FXCM, 4 or 5?
by qin. 02/11/26 14:12
CMC MT4 CFD vs FX Active - what's better?
by mayarik. 02/11/26 11:00
print a "still alive" log
by qin. 02/10/26 12:16
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (TipmyPip), 7,786 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon, mayarik
19198 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