[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 251

 
Compiles, but does not execute.
 
Dimka-novitsek:
It compiles, but does not execute.

Checked. ServiceRefreshChart () is not available to you.

Which option doesn't work? It's too much already. The option with the script and a separate chart will always work.

You open a chart, e.g. EURUSD H1.

2. In the script this:

void start()
  {
   int hwndChart = WindowHandle("EURUSD", PERIOD_H1);
   while (!IsStopped())
    {
     for (int i = 0; i < 9 && !IsStopped(); i++)
      {
       ServiceSetTimeframeByNumber(hwndChart, i);
       Sleep(4000);
      }
    }
  }

3. Run the script on another chart.

4. EURUSD H1 chart will change the TF.

 
Thank you!
 
I drag the script onto the chart and nothing happens, either on the same chart with the EA or on a different one. This is my first time using the script at all. It looks like this.
//+------------------------------------------------------------------+
//|                                                   таймфрейм .mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <ServicesMT4.mqh>
void start()
  {
   int hwndChart = WindowHandle("EURUSD", PERIOD_H1);
   while (!IsStopped())
    {
     for (int i = 0; i < 9 && !IsStopped(); i++)
      {
       ServiceSetTimeframeByNumber(hwndChart, i);
       Sleep(4000);
      }
    }
  }
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
Expert Advisor looks like this.
//+------------------------------------------------------------------+
//|                                                  таймфрейммм.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <ServicesMT4.mqh>
void start()
  {
   int hwndChart = WindowHandle(Symbol(),Period());
   while (!IsStopped())
    {
     for (int i = 0; i < 9; i++)
      {
       ServiceSetTimeframeByNumber(hwndChart, i);
       Sleep(4000);
      }
    }
  }
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
And as a variant, respectively.
//+------------------------------------------------------------------+
//|                                                 таймфреймммм.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <ServicesMT4.mqh>
int hwndChart = NULL;
void init()
 {
  hwndChart = WindowHandle(Symbol(),Period()); // Получаем системный дескриптор графика.
  ServiceRefreshChart(hwndChart, 1000); // Запускаем обновление графика каждую 1 секунду.
 }

void start()
 {
  ServiceStopRefreshChart(hwndChart); // Останавливаем обновление. Больше не требуется.
  while (!IsStopped())
   {
    for (int i = 0; i < 9; i++)
     {
      ServiceSetTimeframeByNumber(hwndChart, i);
      Sleep(4000);
     }
   }
 }
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
 

This script works for me:

#include <ServicesMT4.mqh>
void start()
  {
   int hwndChart = WindowHandle("EURUSD", PERIOD_H1);
   while (!IsStopped())
    {
     for (int i = 0; i < 9 && !IsStopped(); i++)
      {
       ServiceSetTimeframeByNumber(hwndChart, i);
       Sleep(4000);
      }
    }
  }

This expert works strangely. You could say it doesn't work. On itself the TF switches only up to M5.

#include <ServicesMT4.mqh>
int hwndChart = NULL;

void init()
 {
  if (UninitializeReason() != REASON_CHARTCHANGE) hwndChart = WindowHandle(Symbol(),Period()); // Получаем системный дескриптор графика.
  ServiceRefreshChart(hwndChart, 1000); // Запускаем обновление графика каждую 1 секунду.
 }

void start()
 {
  ServiceStopRefreshChart(hwndChart); // Останавливаем обновление. Больше не требуется.
  while (!IsStopped())
   {
    for (int i = 0; i < 9; i++)
     {
      ServiceSetTimeframeByNumber(hwndChart, i);
      Sleep(4000);
     }
   }
 }
Waiting for the natural ticks. It's not clear where the problem came from. Something has changed in the new builds of MT4.
 
Zhunko:

This script works for me:

This expert works strangely. You could say it doesn't work. By itself the TF switches only up to M5.

I will wait for the natural ticks. I do not understand how the problem appeared. Something has changed in the new builds of MT4.


Right, why do we need software that constantly glitches so much that it is impossible to apply it ?

Use the standard features and everything will be fine.

The indicator will be placed on the chart and updated manually instead of ticks.

Do not forget to allow for DLL in the settings

//+------------------------------------------------------------------+
//|                                                    таймфрейм.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property indicator_chart_window
#import "user32.dll"
   int   PostMessageA(int  hWnd,int  Msg,int  wParam,string lParam);
#import
#define WM_COMMAND                     0x0111
int delimiter = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {//return;
   int    counted_bars=IndicatorCounted();
//----
   if(delimiter<3){delimiter++;Comment(delimiter);return(0);}
   delimiter=0;
   fChangePeriod();
//----
   return(0);
  }
//+------------------------------------------------------------------+
void fChangePeriod(){int ii,hwd = WindowHandle(Symbol(),Period());
   switch(Period()){
      case PERIOD_W1    : ii = 33134; break; //PERIOD_D1;
      case PERIOD_D1    : ii = 33136; break; //PERIOD_H4;
      case PERIOD_H4    : ii = 33135; break; //PERIOD_H1;
      case PERIOD_H1    : ii = 33140; break; //PERIOD_M30;
      case PERIOD_M30   : ii = 33139; break; //PERIOD_M15;
      case PERIOD_M15   : ii = 33138; break; //PERIOD_M5;
      case PERIOD_M5    : ii = 33137; break; //PERIOD_M1;
      case PERIOD_M1    : ii = 33141; break; //PERIOD_W1;
   }     
   PostMessageA(hwd, WM_COMMAND, ii, 0);
   return;
}
 
//+------------------------------------------------------------------+
// Скрипт для переключ таймфрейма.
// Для работы скрипта необходимо разрешить вызов функций из системных DLL:
// Сервис -> Настройки  -> Советники -> Разрешить импорт DLL.
#property show_inputs
#import "user32.dll"
        int PostMessageA(int hWnd,int Msg,int wParam,int lParam);
        void keybd_event(int bVk,int bScan,int dwFlags,int dwExtraInfo);
#import
#define WM_COMMAND 0x0111
extern int Per=5;
//+------------------------------------------------------------------+
int  start()
{int wParam,hWnd=WindowHandle(Symbol(),Period());
switch(Per)
        {case PERIOD_M1: wParam=33137;break;
         case PERIOD_M5: wParam=33138;break;
         case PERIOD_M15:wParam=33139;break;
         case PERIOD_M30:wParam=33140;break;
         case PERIOD_H1: wParam=33135;break;
         case PERIOD_H4: wParam=33136;break;
         case PERIOD_D1: wParam=33134;break;
         case PERIOD_W1: wParam=33141;break;
         case PERIOD_MN1:wParam=33334;break;}
PostMessageA(hWnd,WM_COMMAND,wParam,0);
keybd_event(0xD,0,0,0);keybd_event(0x23,0,0,0);return(0);}
//+------------------------------------------------------------------+ 
 
FAQ:


Right, why do you need software that constantly glitches so badly that it cannot be used?

Use the standard features and you'll be fine.

The indicator should be charted and updated manually instead of ticks.

Just do not forget to allow DLL in settings

What, you have the facts? What if I was joking? You can't even check. You need a certain skill.

PostMessage() works for me too. Only it's wrong. Try doing it with SendMessage(). I hope you know the difference.

Rustam, not everybody can handle the simplest software. You are out of luck. Some people even have a glitchy OS.

 
Thank you!!!!!!!
 

The script works!!!!!

But it only switches to the M5.

Reason: