MT4(build 625) hang-up -- OnChartEvent() { .. ChartSetSymbolPeriod() .. }

 

Why MT4(build 625) hang-up?


=== Step ===

(1) create a new chart

(2) drag and drop Expert Advisor ( testEA ) onto the chart

(3) repeat key press ( key is 'j' or 'k' )

(4) MT4 hang-up


<< text code (Expert Advisor) -- testEA.mq4 >>

int OnInit() {
   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
   return;
}

void OnTick()
{
   return;
}


void
OnChartEvent(
   const int id,         // Event ID
   const long& lparam,   // Parameter of type long event
   const double& dparam, // Parameter of type double event
   const string& sparam  // Parameter of type string events
)
{
   switch (id) {
   
   case CHARTEVENT_KEYDOWN:
      if (lparam == 'J' || lparam == 'j') {
         ENUM_TIMEFRAMES new_timeframe = PERIOD_CURRENT;
         switch (Period()) {
         case PERIOD_M5:   new_timeframe = PERIOD_M1; break;
         case PERIOD_M15:  new_timeframe = PERIOD_M5; break;
         case PERIOD_M30:  new_timeframe = PERIOD_M15; break;
         case PERIOD_H1:   new_timeframe = PERIOD_M30; break;
         case PERIOD_H4:   new_timeframe = PERIOD_H1; break;
         case PERIOD_D1:   new_timeframe = PERIOD_H4; break;
         case PERIOD_W1:   new_timeframe = PERIOD_D1; break;
         case PERIOD_MN1:  new_timeframe = PERIOD_W1; break;
         }
         if (new_timeframe != PERIOD_CURRENT) {
            ChartSetSymbolPeriod(0, NULL, new_timeframe);
         }
      } else if (lparam == 'K' || lparam == 'k') {
         new_timeframe = PERIOD_CURRENT;
         switch (Period()) {
         case PERIOD_M1:   new_timeframe = PERIOD_M5; break;
         case PERIOD_M5:   new_timeframe = PERIOD_M15; break;
         case PERIOD_M15:  new_timeframe = PERIOD_M30; break;
         case PERIOD_M30:  new_timeframe = PERIOD_H1; break;
         case PERIOD_H1:   new_timeframe = PERIOD_H4; break;
         case PERIOD_H4:   new_timeframe = PERIOD_D1; break;
         case PERIOD_D1:   new_timeframe = PERIOD_W1; break;
         case PERIOD_W1:   new_timeframe = PERIOD_MN1; break;
         }
         if (new_timeframe != PERIOD_CURRENT) {
            ChartSetSymbolPeriod(0, NULL, new_timeframe);
         }
      }
      break;

   }
}
 
void
OnChartEvent(
             const int id,         // Event ID
             const long& lparam,   // Parameter of type long event
             const double& dparam, // Parameter of type double event
             const string& sparam  // Parameter of type string events
             )
  {
  int new_timeframe;
   switch(id) 
     {

      case CHARTEVENT_KEYDOWN:
         if(lparam=='J' || lparam=='j')
           {
            //ENUM_TIMEFRAMES new_timeframe=PERIOD_CURRENT;
            switch(Period()) 
              {
               case PERIOD_M1:   new_timeframe = PERIOD_M1; break;
               case PERIOD_M5:   new_timeframe = PERIOD_M1; break;
               case PERIOD_M15:  new_timeframe = PERIOD_M5; break;
               case PERIOD_M30:  new_timeframe = PERIOD_M15; break;
               case PERIOD_H1:   new_timeframe = PERIOD_M30; break;
               case PERIOD_H4:   new_timeframe = PERIOD_H1; break;
               case PERIOD_D1:   new_timeframe = PERIOD_H4; break;
               case PERIOD_W1:   new_timeframe = PERIOD_D1; break;
               case PERIOD_MN1:  new_timeframe = PERIOD_W1; break;
              }
            if(new_timeframe!=PERIOD_CURRENT) 
              {
               ChartSetSymbolPeriod(0,NULL,new_timeframe);
              }
              } 
              else if(lparam=='K' || lparam=='k') {
            new_timeframe= PERIOD_CURRENT;
            switch(Period()) 
              {
               case PERIOD_M1:   new_timeframe = PERIOD_M5; break;
               case PERIOD_M5:   new_timeframe = PERIOD_M15; break;
               case PERIOD_M15:  new_timeframe = PERIOD_M30; break;
               case PERIOD_M30:  new_timeframe = PERIOD_H1; break;
               case PERIOD_H1:   new_timeframe = PERIOD_H4; break;
               case PERIOD_H4:   new_timeframe = PERIOD_D1; break;
               case PERIOD_D1:   new_timeframe = PERIOD_W1; break;
               case PERIOD_W1:   new_timeframe = PERIOD_MN1; break;
               case PERIOD_MN1:  new_timeframe = PERIOD_MN1; break;
              }
            if(new_timeframe!=PERIOD_CURRENT) 
              {
               ChartSetSymbolPeriod(0,NULL,new_timeframe);
              }
           }
         break;

     }
  }
//+------------------------------------------------------------------+
 
taro300:

Why MT4(build 625) hang-up?


=== Step ===

(1) create a new chart

(2) drag and drop Expert Advisor ( testEA ) onto the chart

(3) repeat key press ( key is 'j' or 'k' )

(4) MT4 hang-up


<< text code (Expert Advisor) -- testEA.mq4 >>


It's just running fine for me.

Edit : I am using build 628.

 
GumRai:

Which problem are you trying to correct with these modifications ?
 
angevoyageur:
Which problem are you trying to correct with these modifications ?

Well I included the additional cases so to avoid "Not all control paths return a value", although it could probably be better done with a default.

int new_timeframe can just be left at ENUM_TIMEFRAMES new_timeframe=PERIOD_CURRENT;

but it needed to be moved because it was declared locally to the first if and so had no value in the 2nd if

The code as posted will not compile in 625.

void
OnChartEvent(
             const int id,         // Event ID
             const long& lparam,   // Parameter of type long event
             const double& dparam, // Parameter of type double event
             const string& sparam  // Parameter of type string events
             )
  {
  int new_timeframe;
   switch(id) 
     {

      case CHARTEVENT_KEYDOWN:
         if(lparam=='J' || lparam=='j')
           {
            //ENUM_TIMEFRAMES new_timeframe=PERIOD_CURRENT;
            switch(Period()) 
              {
               case PERIOD_M1:   new_timeframe = PERIOD_M1; break;
               case PERIOD_M5:   new_timeframe = PERIOD_M1; break;
               case PERIOD_M15:  new_timeframe = PERIOD_M5; break;
               case PERIOD_M30:  new_timeframe = PERIOD_M15; break;
               case PERIOD_H1:   new_timeframe = PERIOD_M30; break;
               case PERIOD_H4:   new_timeframe = PERIOD_H1; break;
               case PERIOD_D1:   new_timeframe = PERIOD_H4; break;
               case PERIOD_W1:   new_timeframe = PERIOD_D1; break;
               case PERIOD_MN1:  new_timeframe = PERIOD_W1; break;
              }
            if(new_timeframe!=PERIOD_CURRENT) 
              {
               ChartSetSymbolPeriod(0,NULL,new_timeframe);
              }
              } 
              else if(lparam=='K' || lparam=='k') {
            new_timeframe= PERIOD_CURRENT;
            switch(Period()) 
              {
               case PERIOD_M1:   new_timeframe = PERIOD_M5; break;
               case PERIOD_M5:   new_timeframe = PERIOD_M15; break;
               case PERIOD_M15:  new_timeframe = PERIOD_M30; break;
               case PERIOD_M30:  new_timeframe = PERIOD_H1; break;
               case PERIOD_H1:   new_timeframe = PERIOD_H4; break;
               case PERIOD_H4:   new_timeframe = PERIOD_D1; break;
               case PERIOD_D1:   new_timeframe = PERIOD_W1; break;
               case PERIOD_W1:   new_timeframe = PERIOD_MN1; break;
               case PERIOD_MN1:  new_timeframe = PERIOD_MN1; break;
              }
            if(new_timeframe!=PERIOD_CURRENT) 
              {
               ChartSetSymbolPeriod(0,NULL,new_timeframe);
              }
           }
         break;

     }
  }
 

I was changed source code.

But MT4 was hang-up. (>_<)/


<< MT4 hang-up >>



>
 
GumRai:

Well I included the additional cases so to avoid "Not all control paths return a value", although it could probably be better done with a default.

There is not such problem with this code.

int new_timeframe can just be left at ENUM_TIMEFRAMES new_timeframe=PERIOD_CURRENT;

but it needed to be moved because it was declared locally to the first if and so had no value in the 2nd if

The code as posted will not compile in 625.

Ok it compiles fine without #property strict, not with it. But in all case it doesn't hang up MT4 for me.
 
angevoyageur:
There is not such problem with this code.Ok it compiles fine without #property strict, not with it. But in all case it doesn't hang up MT4 for me.


I commented out #property strict and yes, seems to be working properly in 625, no hang ups.
 

i have problem with B625.. in OnChartEvent()


CHARTEVENT_OBJECT_DRAG not trigered at all..

 

Bug was fixed.

It did not hang-up in MT4 build 646.

Reason: