MQL4 Add indicator to chart from EA

To add comments, please log in or register
Georgiy Liashchenko
4563
Georgiy Liashchenko  

Hello people,

I am trying to solve the current problem. In mql4 there is no command which would add an indicator to a chart like in mql5 ChartIndicatorAdd(). It is really sad.

I want my ea to initiate an indicator. Scrolling forums i came across with such solution but it isn't working properly. Please help!

 

 This code tries to launch the indicator, but it doesn't read the file name properly. It tries to open only (first letter of indicator name).ex4 or I.ex4

Obvious solution was chararray but  compiler returns error "parametr conversion not allowed". So how can we solve it?

 

#import "user32.dll"
   int RegisterWindowMessageW(string MessageName);
   int PostMessageW(int hwnd, int msg, int wparam, string Name);
#import

void StartCustomIndicator(int hWnd, string IndicatorName, bool AutomaticallyAcceptDefaults = false)
{
 string name = "Indicator_name";
 char name2[];
 StringToCharArray(name,name2,0,StringLen(name));
 
 int MessageNumber = RegisterWindowMessageW("MetaTrader4_Internal_Message");
 int r = PostMessageW(hWnd, MessageNumber, 15, name);
}
int OnInit()
  {
//---

// In my code where I launch the indicator
int hWnd = WindowHandle(Symbol(), 0);
StartCustomIndicator(hWnd, "Indicator_name");

return(INIT_SUCCEEDED);
}
Alain Verleyen
37157
Alain Verleyen  
#import "user32.dll"
int RegisterWindowMessageW(string MessageName);
int PostMessageW(int hwnd,int msg,int wparam,uchar &Name[]);
#import

#define INDICATOR_NAME "Indicator_name"
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void StartCustomIndicator(int hWnd,string IndicatorName,bool AutomaticallyAcceptDefaults=false)
  {
   uchar name2[];
   StringToCharArray(IndicatorName,name2,0,StringLen(IndicatorName));

   int MessageNumber=RegisterWindowMessageW("MetaTrader4_Internal_Message");
   int r=PostMessageW(hWnd,MessageNumber,15,name2);
   Sleep(10);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
// In my code where I launch the indicator
   int hWnd=WindowHandle(Symbol(),0);
   StartCustomIndicator(hWnd,INDICATOR_NAME);

   return(INIT_SUCCEEDED);
  }
Georgiy Liashchenko
4563
Georgiy Liashchenko  
Alain Verleyen:
Thanks, it has worked now, but it works only from second attemp. If i start ea, indicator call returns error fail to open / .ex4[123]. If the ea is already attached to a chart and i try to re attach it, then it works. How this can be solved?
eevviill7
20513
eevviill7  
Georgiy Liashchenko:

...In mql4 there is no command which would add an indicator to a chart like in mql5 ChartIndicatorAdd(). It is really sad....

 

Are you sure?
Georgiy Liashchenko
4563
Georgiy Liashchenko  
Vasyl Nosal:
Are you sure?
Well if you know some, please share... :)
eevviill7
20513
eevviill7  
Georgiy Liashchenko:
Well if you know some, please share... :)

:))))))))))))))))))))))))))))))))))))))))))))))))))

ChartIndicatorAdd() 

Oh sorry. Few minutes. 

 

Hmm. I thought that it is in mql4.

Maybe this will help you

ChartApplyTemplate() 

Georgiy Liashchenko
4563
Georgiy Liashchenko  
Vasyl Nosal:

:))))))))))))))))))))))))))))))))))))))))))))))))))

ChartIndicatorAdd() 

Oh sorry. Few minutes. 

 

Hmm. I thought that it is in mql4.

Maybe this will help you

ChartApplyTemplate() 

Yes, but thats not a case as for example i sell ea and a client want to use it, he doesnt have a same template. Even if i give it with file, he may prefer different outlook. Therefore i want to initialize indicator from ea.
eevviill7
20513
eevviill7  
Georgiy Liashchenko:
Yes, but thats not a case as for example i sell ea and a client want to use it, he doesnt have a same template. Even if i give it with file, he may prefer different outlook. Therefore i want to initialize indicator from ea.

Hmm. Maybe than add indicator in EA using "resourse".

#resource "\\Indicators\\SampleIndicator.ex4"


int OnInit()
  {

   double value=iCustom(_Symbol,_Period,"::Indicators\\SampleIndicator.ex4",0,0);
Georgiy Liashchenko
4563
Georgiy Liashchenko  
Vasyl Nosal:

Hmm. Maybe than add indicator in EA using "resourse".

doesn't work, ea gets handle but no indicator
eevviill7
20513
eevviill7  
Georgiy Liashchenko:
doesn't work, ea gets handle but no indicator

It is not add indicator to chart. It compile ind in ea ex.4 file.

eevviill7
20513
eevviill7  
Maybe write to srvice desk and ask they to add ChartIndicatorAdd() like in mql5?
To add comments, please log in or register