Timeframe-switcher problem

 

Hello again,

encouraged by my "success" in my other thread, also wanted to make a script to switch the timeframe on the current chart between 5 and 1 minutes.

So here's my code:

void OnStart()
  {
   if(Period() != 5)
     {
      ChartSetSymbolPeriod(0, NULL, 5);
     }
   else
     {
      ChartSetSymbolPeriod(0, NULL, 1);
     }    
  }

Really simple and I see no reason, why it shouldn't work...

But in 90% the times of running this script, I get asked, if I really want to close this script.... and regardless of clicking Yes or NO nothing happens. (The 10% it works flawlessly)

Am I missing here anything important? - Again, my programming skills are next to nothing. So I would really appreciate it if you could take a look give me a hint ;-)

Thanks

kensho

 
kensho:

Hello again,

encouraged by my "success" in my other thread, also wanted to make a script to switch the timeframe on the current chart between 5 and 1 minutes.

So here's my code:

Really simple and I see no reason, why it shouldn't work...

But in 90% the times of running this script, I get asked, if I really want to close this script.... and regardless of clicking Yes or NO nothing happens. (The 10% it works flawlessly)

Am I missing here anything important? - Again, my programming skills are next to nothing. So I would really appreciate it if you could take a look give me a hint ;-)

Thanks

kensho

Try adding a ChartRedraw()
 

Hmm, this doesn't work. Same problems as before. (also tried the Redraw directly after Start....)

void OnStart()
  {
   if(Period() != 5)
     {
      ChartSetSymbolPeriod(0, NULL, 5);
     }
   else
     {
      ChartSetSymbolPeriod(0, NULL, 1);
     }
   ChartRedraw(0);   
  }
 
kensho:

Hmm, this doesn't work. Same problems as before. (also tried the Redraw directly after Start....)

ChartRedraw() doesn't apply in this case. It seems a bug. Do you want to report it to ServiceDesk (you have to register on mql5.com) ?

As a side note I suggest you to use defined value for period (enum) :

   if(Period()!=PERIOD_M5)
     {
      ChartSetSymbolPeriod(0,NULL,PERIOD_M5);
     }
   else
     {
      ChartSetSymbolPeriod(0,NULL,PERIOD_M1);
     }    
 

Thanks for the input.

Well then I will report to ServiceDesk.

Best regards

kensho

 
kensho:

Thanks for the input.

Well then I will report to ServiceDesk.

Best regards

kensho

Thank you.
 

Hello again. ;)

After reporting my problem to the ServiceDesk, I got the message that it is fixed.

So I decided to wait for the next update, which was deployed by my MM a few days ago.

The good news is that, switching between timeframes now works flawlessly. The bad news is, the Alert that asks me, if I really want to close this script still pops up every time. When I click "Yes" - the script switches as it is supposed to. When I click "No" - nothing happens.

Am I missing something in this simple code?

void OnStart()
  {
   int actTimeframe = Period();
//+------------------------------------------------------------------+  
   
   switch (actTimeframe)
     {
      case PERIOD_M5 : ChartSetSymbolPeriod(0,NULL,PERIOD_M1); break;
      case PERIOD_M1 : ChartSetSymbolPeriod(0,NULL,PERIOD_M5); break;
      default: ChartSetSymbolPeriod(0,NULL,PERIOD_M5);
     }
   ChartRedraw(0);   
  }

Also I'll attach a screen shot of the "Alert"

I hope you can help me.

Best regards

 
kensho:

Hello again. ;)

After reporting my problem to the ServiceDesk, I got the message that it is fixed.

So I decided to wait for the next update, which was deployed by my MM a few days ago.

The good news is that, switching between timeframes now works flawlessly. The bad news is, the Alert that asks me, if I really want to close this script still pops up every time. When I click "Yes" - the script switches as it is supposed to. When I click "No" - nothing happens.

Am I missing something in this simple code?

Also I'll attach a screen shot of the "Alert"

I hope you can help me.

Best regards

It works without problem for me, build 628.
 
i think it's designed to use only with a EA and not with a script
 
angevoyageur:
It works without problem for me, build 628.



Hmmm, I have build 625.

So I guess I'll have to wait until the next update of my MM.

Thank you for your fast response.

Best regards

kensho

 
qjol:
i think it's designed to use only with a EA and not with a script
It works with a script. Of course you have to execute the script each time.
Reason: