How to combine strategies

Posted By: TrumpLost

How to combine strategies - 06/13/22 08:27

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?
Posted By: Grant

Re: How to combine strategies - 06/13/22 09:49

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.
© 2024 lite-C Forums