Help on improving my if statements code logic

 

Dear Members

Seeking advise to improve my code writing for the attached file, where I want to find VSA concept Efforts High and REsult Low.

Currently I am using if statements and many conditions are repeated in different section of method.

I am sure there should be a better way to achieve same results, e.g. may be using Multi Dimensions Array or Matrix or Vector!!!

Since I have never used them, and seek advise will it be worth to explore them!!!

Also if I can get some initial guidelines to kick it off, that will be great help.

The full is attached in file as can not paste here due to character limits.

//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:     IsEffortHighResultLow()
//+-----------------------------------------------------------------------------------------------------------------------------+
bool CScanCPatterns::IsEffortHighResultLow(int pIndex) {

                int k = pIndex;
        //+---------------------------------------------------------------------------------------------------------------------------+
        //| [!] RVOL and Average SpreadToRange Comparision
        //+---------------------------------------------------------------------------------------------------------------------------+
                if(RVOL[2+k].high && mRVOLGrow) {                                                                                                                       // RVOL growing from High to High or High to Ulta
                        if(mAvgSpreadShrink)                                                                                                                                                                                                                                                                                                                                                            return(true);
                }
        //+---------------------------------------------------------------------------------------------------------------------------+
        //| [A] RVOL Peak in low/normal range
        //+---------------------------------------------------------------------------------------------------------------------------+
                if(mRVOLPeak) {
                        // Nuance [A1]
                        if(RVOL[2+k].low && RVOL[1+k].high && RVOL[k].normal) {
                                if(Spread[2+k].wide && Spread[1+k].narrow && Spread[k].wide) {
                                        if(Range[2+k].narrow && Range[1+k].narrow && Range[k].wide)                                                                                                                                                                             return(true);
                                }
                        } // End of Nuance [A1]
                        // Nuance [A2]
                        if(RVOL[2+k].high && RVOL[1+k].ultra && RVOL[k].ultra) {
                                if(Spread[2+k].narrow && Spread[1+k].ultra && Spread[k].wide) {
                                        if(Range[2+k].ultra && Range[1+k].ultra && Range[k].wide)                                                                                                                                                                                       return(true);   // [2023.08.21 18:00]
                                }
                                if(Spread[2+k].ultra && Spread[1+k].ultra && Spread[k].narrow) {
                                        if(Range[2+k].wide && Range[1+k].ultra && Range[k].narrow)                                                                                                                                                                                      return(true);   // [2023.08.04 22:00]
                                }
                        } // End of Nuance [A2]
                        // Nuance [A3]
                        if(RVOL[2+k].ultra && RVOL[1+k].ultra && RVOL[k].ultra) {
                                if(Spread[2+k].narrow && Spread[1+k].narrow && Spread[k].ultra) {
                                        if(Range[2+k].wide && Range[1+k].ultra && Range[k].ultra)                                                                                                                                                                                       return(true);   // [2023.08.09 18:00]
                                }
                                if(Spread[2+k].wide && Spread[1+k].narrow && Spread[k].narrow) {
                                        if(Range[2+k].ultra && Range[1+k].wide && Range[k].wide)                                                                                                                                                                                                return(true);   // [2023.07.05 20:00]
                                }
                        } // End of Nuance [A3]
                        // Nuance [A4]
                        if(RVOL[2+k].ultra && RVOL[1+k].ultra && RVOL[k].high) {
                                if(Spread[2+k].ultra && Spread[1+k].narrow && Spread[k].narrow) {
                                        if(Range[2+k].ultra && Range[1+k].ultra && Range[k].wide)                                                                                                                                                                                       return(true);   // [2023.07.20 18:00]
                                }
                        } // End of Nuance [A3]
                } // End of Nuance [A]
        //+---------------------------------------------------------------------------------------------------------------------------+
        //| [B] RVOL Growing
        //+---------------------------------------------------------------------------------------------------------------------------+
                if(mRVOLGrow) {
                        // Nuance [B1]
                        if(RVOL[2+k].normal && RVOL[1+k].normal && RVOL[k].high) {
                                if(Spread[2+k].narrow && Spread[1+k].wide && Spread[k].narrow) {
                                        if(Range[2+k].narrow && Range[1+k].wide && Range[k].wide)                                                                                                                                                                                       return(true);
                                }               
                                if(Range[2+k].narrow && Range[1+k].wide && Range[k].wide) {
                                        if(Spread[2+k].narrow && Spread[1+k].wide && Spread[k].narrow)                                                                                                                                                                  return(true);
                                }
                        } // End of Nuance [B1]
                        // Nuance [B2]
                        if(RVOL[2+k].low && RVOL[1+k].high && RVOL[k].high) {
                                if(Range[2+k].wide && Range[1+k].ultra && Range[k].ultra) {
                                        if(Spread[2+k].narrow && Spread[1+k].narrow && Spread[k].narrow)                                                                                                                                                                return(true);
                                }
                                if(Range[2+k].narrow && Range[1+k].ultra && Range[k].ultra) {
                                        if(Spread[2+k].narrow && Spread[1+k].narrow && Spread[k].narrow)                                                                                                                                                                return(true);
                                }
                        } // End of Nuance [B2]
                        // Nuance [B3]
                        if(RVOL[2+k].low && RVOL[1+k].high && RVOL[k].ultra) {
                                if(Spread[2+k].narrow && Spread[1+k].narrow && Spread[k].narrow) {
                                        if(Range[2+k].narrow && Range[1+k].ultra && Range[k].ultra)                                                                                                                                                                             return(true);   // [2023.09.01 15:00]
                                        if(Range[2+k].narrow && Range[1+k].wide && Range[k].wide)                                                                                                                                                                                       return(true);
                                }
                        } // End of Nuance [B3]
                        // Nuance [B4]
                        if(RVOL[2+k].low && RVOL[1+k].normal && RVOL[k].ultra) {
                                if(Spread[2+k].wide && Spread[1+k].wide && Spread[k].wide) {
                                        if(Range[2+k].wide && Range[1+k].ultra && Range[k].ultra)                                                                                                                                                                                       return(true);   // [2023.08.28 16:00]
                                }
                        } // End of Nuance [B4]
                        // Nuance [B5]
                        if(RVOL[2+k].normal && RVOL[1+k].ultra && RVOL[k].ultra) {
                                if(Spread[2+k].narrow && Spread[1+k].wide && Spread[k].narrow) {
                                        if(Range[2+k].wide && Range[1+k].ultra && Range[k].wide)                                                                                                                                                                                                return(true);   // [2023.08.08 17:00]
                                }
                        } // End of Nuance [B5]
                        // Nuance [B6]
                        if(RVOL[2+k].normal && RVOL[1+k].high && RVOL[k].ultra) {
                                if(Spread[2+k].narrow && Spread[1+k].narrow && Spread[k].narrow) {
                                        if(Range[2+k].narrow && Range[1+k].wide && Range[k].wide)                                                                                                                                                                                       return(true);   // [2023.08.03 16:00]
                                }
                                if(Spread[2+k].narrow && Spread[1+k].narrow && Spread[k].wide) {
                                        if(Range[2+k].wide && Range[1+k].ultra && Range[k].wide)                                                                                                                                                                                                return(true);   // [2023.09.22 17:00]
                                }
                        } // End of Nuance [B6]
                        // Nuance [B7]
                        if(RVOL[2+k].high && RVOL[1+k].high && RVOL[k].ultra) {
                                if(Spread[2+k].ultra && Spread[1+k].wide && Spread[k].wide) {
                                        if(Range[2+k].ultra && Range[1+k].wide && Range[k].ultra)                                                                                                                                                                                       return(true);   // [2023.10.03 16:00]
                                }
                        } // End of Nuance [B7]
                        // Nuance [B8]
                        if(RVOL[2+k].high && RVOL[1+k].high && RVOL[k].high) {
                                if(Spread[2+k].narrow && Spread[1+k].wide && Spread[k].wide) {
                                        if(Range[2+k].wide && Range[1+k].narrow && Range[k].wide)                                                                                                                                                                                       return(true);   // [2023.09.25 22:00]
                                }
                        } // End of Nuance [B8]
                } // End of Nuance [B]
        //+---------------------------------------------------------------------------------------------------------------------------+
                return(false);

} // END of method IsEffortHighResultLow()
Files:
AlgoTEMP.mqh  11 kb
 
Anil Varma:

Dear Members

Seeking advise to improve my code writing for the attached file, where I want to find VSA concept Efforts High and REsult Low.

Currently I am using if statements and many conditions are repeated in different section of method.

I am sure there should be a better way to achieve same results, e.g. may be using Multi Dimensions Array or Matrix or Vector!!!

Since I have never used them, and seek advise will it be worth to explore them!!!

Also if I can get some initial guidelines to kick it off, that will be great help.

The full is attached in file as can not paste here due to character limits.

In a semantic, what you could do to optimize this is use a bit map.

If you represent your states in a 32 bit uint value instead of member variables, you could create a "fall-through" Switch-Case statement to "jump" to the required segments of the code.

Currently you are using ".low" , ".high", ".ultra" as a boolean state. If you combine them into a bit field, you get a single integer. This single integer can then be evaluated using a switch statement.

If you need to repeat this statement, then you can wrap it into a while loop until you have reached the end of your processing. You will need an exit condition for your loop.

I actually have not looked at your code file, only the posted code.
 
Dominik Egert #:
In a semantic, what you could do to optimize this is use a bit map.

If you represent your states in a 32 bit uint value instead of member variables, you could create a "fall-through" Switch-Case statement to "jump" to the required segments of the code.

Currently you are using ".low" , ".high", ".ultra" as a boolean state. If you combine them into a bit field, you get a single integer. This single integer can then be evaluated using a switch statement.

If you need to repeat this statement, then you can wrap it into a while loop until you have reached the end of your processing. You will need an exit condition for your loop.

I actually have not looked at your code file, only the posted code.

Thanks a lot @Dominik Egert

This sounds interesting. Should I also take the message that using unit/int variable are optimum than using bool variables, as most of the time, for ease of reading I intend to use bool variables instead of unit/int type e.g. Trend_Direction I can easily use 0(Sideways) 1(Long) 2 (Short) but I prefer to used custom enumerations as SIDEWAYS,LONG and SHORT.

So for Spread: instead of "low,"high","ultra" I should use unit case1 = 123;

    "low","low","ultra" case2 = 113;

And Spread+Range I can use Spread(low,high,ultra) + Range(low,high,ultra) case1 = 123123;

  Spread(low,low,ultra) +  Rate(ultra+high+low  case2 = 113321;

Just trying to making sure I understood your concept.

Also a question out of curiosity what is the benefits of Metrix/Vectors? Is is worth to invest time to learn these? (I am already way behind my budgeted time for learning from scratch MQL and have my own EA)

Thanks again for your valuable feedback.