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.