Need coding guidance on switch operator ...

 

Hi

I am trying to get a true/false result through a method(), if price have tagged a certain Pivot Level. I have tried to code it as below, however getting error "not all control paths return a value".

It seems "return(vLow < Pivots[k].S3_0618 && vClose > Pivots[k].S3_0618)" does not returns a boolean value.

Please help me how can I correct this.

//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:       IsTaggedKeyPivot()
//| APPLICATION:  Return [true] if High / Low Price TAGGED a key pivot level
//+-----------------------------------------------------------------------------------------------------------------------------+
bool CFollowTheTrend::IsTaggedKeyPivot(ENUM_ORDER_TYPE pOrderType, int pIndex) {

        int k = pIndex;
        double vLow   = HAshiM15[k].high;
        double vHigh  = HAshiM15[k].low;
        double vClose = HAshiM15[k].close;
        enum_PIVOT_LEVEL vPivotLevel;

        // ORDER TYPE LONG
        if(pOrderType == ORDER_TYPE_BUY) {
                switch(vPivotLevel) {
                        case R3_FIBO_RESISTANCE0618:            return(vHigh > Pivots[k].R3_0618 && vClose < Pivots[k].R3_0618);
                        case R1_FIBO_RESISTANCE0236:            return(vHigh > Pivots[k].R1_0236 && vClose < Pivots[k].R1_0236);
                        case PG_PIVOT_GUN:                      return(vHigh > Pivots[k].PG && vClose < Pivots[k].PG);
                        case S1_FIBO_SUPPORT0236:               return(vHigh > Pivots[k].S1_0236 && vClose < Pivots[k].S1_0236);
                        case S3_FIBO_SUPPORT0618:               return(vHigh > Pivots[k].S3_0618 && vClose < Pivots[k].S3_0618);
                } // End of switch()
        }

        // ORDER TYPE SHORT
        else
        if(pOrderType == ORDER_TYPE_SELL) {

                switch(vPivotLevel) {
                        case R3_FIBO_RESISTANCE0618:            return(vLow < Pivots[k].R3_0618 && vClose > Pivots[k].R3_0618);
                        case R1_FIBO_RESISTANCE0236:            return(vLow < Pivots[k].R1_0236 && vClose > Pivots[k].R1_0236);
                        case PG_PIVOT_GUN:                      return(vLow < Pivots[k].PG && vClose > Pivots[k].PG);
                        case S1_FIBO_SUPPORT0236:               return(vLow < Pivots[k].S1_0236 && vClose > Pivots[k].S1_0236);
                        case S3_FIBO_SUPPORT0618:               return(vLow < Pivots[k].S3_0618 && vClose > Pivots[k].S3_0618);
                } // End of switch()
        }

        else
                return(false);

} // END Of method IsTaggedKeyPivot()
 
Of course, you get not all control paths. You have
        if(pOrderType == ORDER_TYPE_BUY) { … }
        else if(pOrderType == ORDER_TYPE_SELL) { … }
        else return(false);
   // What are you returning here?
} // END Of method IsTaggedKeyPivot()
Drop your else
 
William Roeder #:
Of course, you get not all control paths. You have Drop your else

Thanks William

Dropping else did help me get rid of error.

However, as I was doubting SWITCH / CASE OPERATOR did not return true values when condition was true.

I have instead now resorted to use IF OPERATOR and is working as expected.

//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:       IsTaggedKeyPivot()
//| APPLICATION:  Return [true] if High / Low Price TAGGED a key pivot level
//+-----------------------------------------------------------------------------------------------------------------------------+
bool CFollowTheTrend::IsTaggedKeyPivot(ENUM_ORDER_TYPE pOrderType, int pIndex) {

        int k = pIndex + 1;                                                                     // INDEX[1] = pIndex AND INDEX[2] ON WHICH TAG IS CHECKED
        int j = 1;                                                                              // INDEX FOR PIVOT VALUE
        double vLow   = HAshiM15[k].low;
        double vHigh  = HAshiM15[k].high;
        double vClose = HAshiM15[k].close;
        enum_PIVOT_LEVEL vPivotLevel;

        // ORDER TYPE LONG
        if(pOrderType == ORDER_TYPE_BUY) {
                if(vHigh > Pivots[j].R3_0618 && vClose < Pivots[j].R3_0618)             return(true);
                if(vHigh > Pivots[j].R1_0236 && vClose < Pivots[j].R1_0236)             return(true);
                if(vHigh > Pivots[j].PG && vClose < Pivots[j].PG)                       return(true);
                if(vHigh > Pivots[j].S1_0236 && vClose < Pivots[j].S1_0236)             return(true);
                if(vHigh > Pivots[j].S3_0618 && vClose < Pivots[j].S3_0618)             return(true);
        }

        // ORDER TYPE SHORT
        if(pOrderType == ORDER_TYPE_SELL) {
                PrintFormat("Index[%i] Low[%.1f] < Pivot[%.1f] and Close[%.1f] > Pivot[%.1f]",k,vLow,Pivots[j].R1_0236,vClose,Pivots[j].R1_0236);
                if(vLow < Pivots[j].R3_0618 && vClose > Pivots[j].R3_0618)              return(true);
                if(vLow < Pivots[j].R1_0236 && vClose > Pivots[j].R1_0236)              return(true);
                if(vLow < Pivots[j].PG && vClose > Pivots[j].PG)                        return(true);
                if(vLow < Pivots[j].S1_0236 && vClose > Pivots[j].S1_0236)              return(true);
                if(vLow < Pivots[j].S3_0618 && vClose > Pivots[j].S3_0618)              return(true);
        }

        return(false);

} // END Of method IsTaggedKeyPivot()