MQL4 Add indicator to chart from EA

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  
#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);
  }
[Deleted]  
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  
Vasyl Nosal:
Are you sure?
Well if you know some, please share... :)
[Deleted]  
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  
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.
[Deleted]  
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  
Vasyl Nosal:

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

doesn't work, ea gets handle but no indicator
[Deleted]  
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.

[Deleted]  
Maybe write to srvice desk and ask they to add ChartIndicatorAdd() like in mql5?