Download MetaTrader 5

MQL4 Add indicator to chart from EA

To add comments, please log in or register
Having a great idea? Share it on the traders' Forum!
Georgiy Liashchenko
2561
Georgiy Liashchenko 2016.02.13 03:50 

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
Moderator
30721
Alain Verleyen 2016.02.13 11:39  
#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
2561
Georgiy Liashchenko 2016.02.13 15:26  
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?
Vasyl Nosal
18537
Vasyl Nosal 2016.02.13 16:41  
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
2561
Georgiy Liashchenko 2016.02.13 16:42  
Vasyl Nosal:
Are you sure?
Well if you know some, please share... :)
Vasyl Nosal
18537
Vasyl Nosal 2016.02.13 16:48  
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
2561
Georgiy Liashchenko 2016.02.13 17:19  
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.
Vasyl Nosal
18537
Vasyl Nosal 2016.02.13 17:49  
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
2561
Georgiy Liashchenko 2016.02.13 18:16  
Vasyl Nosal:

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

doesn't work, ea gets handle but no indicator
Vasyl Nosal
18537
Vasyl Nosal 2016.02.13 19:48  
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.

Vasyl Nosal
18537
Vasyl Nosal 2016.02.13 19:48  
Maybe write to srvice desk and ask they to add ChartIndicatorAdd() like in mql5?
123
To add comments, please log in or register