a simple question?

 

Can someone please tell me what's wrong with this code snippet, which is part of an EA I am trying to develop?

The indicator "myIndi8" has eight "extern" parameters and eight buffers, four of which are up arrows (0,2,4 and 6) and the other four are down arrows.

The indicator puts an EMPTY_VALUE into the buffer unless it should display an arrow, in which case it puts a double value into the buffer.

int start()
{
   double temp;
   upcount=0; //global
   downcount=0;
  
   for( int i=0; i<=7; i++ ) {
      temp = EMPTY_VALUE;
      temp = iCustom(NULL, 0, "myIndi8", 8, 17, 35, "", "", "", 100, "", i, 0);
      if( temp != EMPTY_VALUE ) {
         switch(i) {
            case 0:
            case 2:
            case 4:
            case 6:
               upcount++;
            case 1:
            case 3:
            case 5:
            case 7:
               downcount++;
         }
      }
   }

.
.
}

When I run the EA in Strategy Tester, it starts by taking both a long and a short position on the first bar. WHY?

The code where upcount and downcount are used is this...

bool get_signal()
{
    if( DayOfWeek()==5 && Hour()>=19 ) return(0);
    
    Buy = false;
    Sell = false;
    bool enable_trade = false;
      
    if( Bars >= 100 )
    {
      if( upcount>0 ){
         Buy=true;
      }
      
      if( downcount>0 ){
         Sell=true;
      }
   }
   if( Buy==true || Sell==true ) enable_trade = true;
   return(enable_trade);
}

I am truly hopeful the experts on this forum can shed light on this dilemma.

Thank you, Helmut

 

try:

if( temp != EMPTY_VALUE ) {
         switch(i) {
            case 0:
            case 2:
            case 4:
            case 6:
               upcount++; break;
            case 1:
            case 3:
            case 5:
            case 7:
               downcount++; break;
            default:break;
         }

https://book.mql4.com/operators/switch


Hope this helps


Enotrek

 
enotrek:

try:

https://book.mql4.com/operators/switch


Hope this helps


Enotrek

It works beautifully, thank you very much.