Download MetaTrader 5

Script runs fine on one MT4 installation, but 'Uninit reason 0' on all others.

To add comments, please log in or register
blad4
77
blad4  

All builds are 670, Jul 2014. DLL calls are allowed under tools, options. I don't know if this could even be an error with the code?

 

#import "user32.dll"
   int GetParent(int hWnd);
   int SendMessageA(int hWnd, int Msg, int wParam, int lParam);
#import

#define WM_MDIACTIVATE 0x222
#define MAX_CHARTS 100

extern int SlideShowSeconds = 4;
extern string Direction = "DOWN";
extern int Skips = 1;


void OnStart()
{
   datetime time = TimeCurrent();
   if (Direction != "UP" && Direction != "DOWN")
   {
      Print("Check direction: I know only UP and DOWN");
      return;
   }
   if (Skips <= 0 || Skips > 10)
   {
      Print("Check skips: it should be one of these: 1,2,3,4,5,6,7,8,9,10");
      return;
   }
   
   int periods_true[MAX_CHARTS][2];
   int i, j = 0;
      
   //possible periods: from 1 to 1440; 2880; from 4320 to 43200 (all in minutes)
   for (i = 1; i <= 43200; i++)
   {
      if ((i > 1440 && i < 2880) ||
          (i > 2880 && i < 4320))
          continue;
          
      if (WindowHandle(Symbol(), i) != 0)
      {
         periods_true[j][1] = WindowHandle(Symbol(), i);
         periods_true[j][0] = i;
         j++;
      }
   }
   
   int periods[MAX_CHARTS];
   ArrayInitialize(periods, 0);
   ArrayResize(periods, j);
   
   for (i = 0; i < j; i++)
      periods[i] = periods_true[i][0];
      
   if (Direction == "UP")
      ArraySort(periods, WHOLE_ARRAY, 0, MODE_ASCEND);
   else
      ArraySort(periods, WHOLE_ARRAY, 0, MODE_DESCEND);
      
   
   int chart_index;
   for (i = 0; i < j; i++)
   {
      int ind;
      //èùåì periods â äâóìåðíîì ìàññèâå
      for (int k = 0; k < j; k++)
      {
         if (periods_true[k][0] == periods[i])
         {
            ind = k;
            break;
         }
      }
      if (periods_true[ind][1] == WindowHandle(Symbol(), Period()))
      {
         chart_index = i;
         break;
      }  
   }
   
   datetime time_diff = TimeCurrent() - time;

   bool first = true;
   while (GlobalVariableCheck("RunSlideShow"))
   {
      if (first)
      {
         first = false;
         if (time_diff < SlideShowSeconds)
            Sleep((SlideShowSeconds - time_diff)*1000);
         
      }
         
      else
         Sleep(SlideShowSeconds*1000);
         
      int shift = Skips;
      while (shift > 0)
      {
         chart_index++;
         if (chart_index == j)
            chart_index = 0;
         shift--;
      }
      
      int handle;
      //èùåì periods â äâóìåðíîì ìàññèâå
      for (int l = 0; l < j; l++)
      {
         if (periods_true[l][0] == periods[chart_index])
         {
            handle = periods_true[l][1];
            break;
         }
      }
      SendMessageA(GetParent(GetParent(handle)), WM_MDIACTIVATE, GetParent(handle), 0);
   }
   return;
}
Alain Verleyen
Moderator
32451
Alain Verleyen  
You probably don't have a global variable of the terminal "RunSlideShow" defined. Your code doesn't create it.
blad4
77
blad4  
Ah yes. Would it still work on one terminal though?? The exact same script on each terminal?
Alain Verleyen
Moderator
32451
Alain Verleyen  
blad4:
Ah yes. Would it still work on one terminal though?? The exact same script on each terminal?
It works for me.
blad4
77
blad4  
Really, with the  while " (GlobalVariableCheck("RunSlideShow")) "  ?
Alain Verleyen
Moderator
32451
Alain Verleyen  
blad4:
Really, with the  while " (GlobalVariableCheck("RunSlideShow")) "  ?
You have to create this "RunSlideShow" manually (press F3, or by code if you wish).
blad4
77
blad4  
Oh I see, if I were to delete a chunk out of the code would this save that hassle and the code just work without any mention of variables? If so, could you point me in the right direction and copy paste the according text I should delete?
blad4
77
blad4  
By the way it is working on any install now that I have added the GV! Thank you
To add comments, please log in or register