Download MetaTrader 5

Please help me find an error in this script

To add comments, please log in or register
Track Market top sellers!
zahidmahmood
66
zahidmahmood 2015.10.28 06:54 
Hi all. Please help me find an error in this script.

this script use for open new chart with specific symbol, time frame ,and template problem is this code open chart with specific time frame but not load specific template please guide me how to load  template 

#import "user32.dll"

   int GetAncestor(int hWnd, int gaFlags);
   int GetDlgItem(int hDlg, int nIDDlgItem);
   int PostMessageA(int hWnd, int Msg, int wParam, int lParam);
   int GetParent(int hWnd);
   int GetWindow(int hWnd,int uCmd);   

#import "kernel32.dll"     

   int  FindFirstFileA(string path, int& answer[]);
   bool FindNextFileA(int handle, int& answer[]);
   bool FindClose(int handle);
   
#import


#define WM_COMMAND   0x0111
#define WM_KEYDOWN   0x0100
#define VK_HOME      0x0024
#define VK_DOWN      0x0028

//+------------------------------------------------------------------+
//| Open a new chart                                                 |
//+------------------------------------------------------------------+
int OpenChart(string SymbolName, int TimeFrame, string Template)
{
   int hFile, SymbolsTotal, hTerminal, hWnd, intCmd;
   
   int counter;
   int win32_DATA[80];
   string tempfullname =".tpl";
   int tempnum = 34800;
   
   tempfullname=Template+tempfullname;
   
   int handle = FindFirstFileA(TerminalPath() + "\\templates\\*.tpl",win32_DATA);
   
   counter = 0;
   
   
  if (tempfullname==bufferToString(win32_DATA))
 
      {
         tempnum+=counter;
      }
      
   
   ArrayInitialize(win32_DATA,0);

   while (FindNextFileA(handle,win32_DATA))
      {

      counter++;
      
      if (tempfullname==bufferToString(win32_DATA))
      {
         tempnum+=counter;

      }

      ArrayInitialize(win32_DATA,0);
      }

   if (handle>0) FindClose(handle);   

   hFile = FileOpenHistory("symbols.sel", FILE_BIN|FILE_READ);
   if(hFile < 0) return(-1);

   SymbolsTotal = (FileSize(hFile) - 4) / 128;
   FileSeek(hFile, 4, SEEK_SET);

   hTerminal = GetAncestor(WindowHandle(Symbol(), Period()),2);

   hWnd = GetDlgItem(hTerminal, 0xE81C);
   hWnd = GetDlgItem(hWnd, 0x50);
   hWnd = GetDlgItem(hWnd, 0x8A71);

   PostMessageA(hWnd, WM_KEYDOWN, VK_HOME, 0);


   switch( TimeFrame )
   {
      case 1:   intCmd = 33137;  break;
      case 5:   intCmd = 33138;  break;
      case 15:  intCmd = 33139;  break;
      case 30:  intCmd = 33140;  break;
      case 60:   intCmd = 35400;  break;
      case 240:   intCmd = 33136;  break;
      case 1440:   intCmd = 33134;  break;
      case 10080:   intCmd = 33141;  break;
      case 43200:  intCmd = 33334;  break;
   }


   for(int i = 0; i < SymbolsTotal; i++)
   {
      if(FileReadString(hFile, 12) == SymbolName)
      {
      
      
      PostMessageA(hTerminal, WM_COMMAND, 33160, 0);
         
      Sleep(100);
         
      PostMessageA(hTerminal,WM_COMMAND,intCmd,0); 

      Sleep(100);
      
     
      PostMessageA(hTerminal, WM_COMMAND, tempnum, 0 );

               
         return(0);

      }
      
      
      PostMessageA(hWnd, WM_KEYDOWN, VK_DOWN, 0);
      FileSeek(hFile, 116, SEEK_CUR);
   }



   FileClose(hFile);

   return(-1);

}

string bufferToString(int buffer[])
   {
   string text="";
   
   int pos = 10;
   for (int i=0; i<64; i++)
      {
      pos++;
      int curr = buffer[pos];
      text = text + CharToStr(curr & 0x000000FF)
         +CharToStr(curr >> 8 & 0x000000FF)
         +CharToStr(curr >> 16 & 0x000000FF)
         +CharToStr(curr >> 24 & 0x000000FF);
      }
   return (text);
   }  


int init()
  {
  
// New chart opens with specified parameters.

   OpenChart(Symbol(),Period(), "Momentum");

   
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   
//----
   return(0);
  }
Carl Schreiber
6609
Carl Schreiber 2015.10.28 07:28  

I think since b+600 wee can do things like:

ChartApplyTemplate(..);  but the template has be in in the correct folder!

ChartOpen() only 'knows' the Symbol() and the Time_Frame.

This can replace most of your code!!

Trinh Dat
37213
Trinh Dat 2015.10.28 07:33  
  long chart = ChartOpen("EURUSD",Period());
  ChartApplyTemplate(chart,"Momentum");
simple code.
zahidmahmood
66
zahidmahmood 2015.10.28 07:35  
calli:

I think since b+600 wee can do things like:

ChartApplyTemplate(..);  but the template has be in in the correct folder!

ChartOpen() only 'knows' the Symbol() and the Time_Frame.

This can replace most of your code!!

hi calli thank u for your feed back ChartApplyTemplate  where i can change this
zahidmahmood
66
zahidmahmood 2015.10.28 07:37  
yes Trinh Dat its working Thanks u very much
To add comments, please log in or register