Download MetaTrader 5
To add comments, please log in or register
Order a robot or an indicator for MetaTrader. The Freelance service will help you!
kensho
40
kensho 2014.03.03 18:37 

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

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.03.03 18:40  
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()
kensho
40
kensho 2014.03.03 18:59  

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);   
  }
Alain Verleyen
Moderator
28672
Alain Verleyen 2014.03.03 19:32  
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);
     }    
kensho
40
kensho 2014.03.03 19:43  

Thanks for the input.

Well then I will report to ServiceDesk.

Best regards

kensho

Alain Verleyen
Moderator
28672
Alain Verleyen 2014.03.03 19:59  
kensho:

Thanks for the input.

Well then I will report to ServiceDesk.

Best regards

kensho

Thank you.
kensho
40
kensho 2014.04.04 09:47  

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

Alain Verleyen
Moderator
28672
Alain Verleyen 2014.04.04 12:09  
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.
qjol
3243
qjol 2014.04.04 12:44  
i think it's designed to use only with a EA and not with a script
kensho
40
kensho 2014.04.04 13:23  
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

Alain Verleyen
Moderator
28672
Alain Verleyen 2014.04.04 14:10  
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.
/
To add comments, please log in or register