Download MetaTrader 5

MQL4 Add indicator to chart from EA - page 3

To add comments, please log in or register
alessandrovb
7
alessandrovb  
Georgiy Liashchenko:
sleep has worked, thanks

I'm using Alain's code and it works in the sense that the classic indicator form appears asking me to fill the parameter and then click Ok to activate the indicator and it's similar to manually attach the indicator. Is it possible to completely automate the entire operation even the settings of the required parameters? Thanks

Alain Verleyen
Moderator
36713
Alain Verleyen  
alessandrovb:

I'm using Alain's code and it works in the sense that the classic indicator form appears asking me to fill the parameter and then click Ok to activate the indicator and it's similar to manually attach the indicator. Is it possible to completely automate the entire operation even the settings of the required parameters? Thanks

You just have to add code to simulate key stroke, like you do manually.
kandymans
10
kandymans  
Alain Verleyen:

I don't have this problem (with the code I posted).

Check that hWnd is different from 0.

You can also try to increase the sleep value to 50 or 100.

Hello,

This comment to many help, I need other question,

Can I bypass the input popup and use default of indicator? How to coding?

Can I delete indicator from the chart? 

Hilman Pridana
130
Hilman Pridana  
Alain Verleyen:

Thanks this is what i am looking for, i can add my custom indicator, just one more question, how to unload it ?

Andre Tavares
2576
Andre Tavares  
Alain Verleyen:

Congratulaions, it works fine.

Mohammad Bazrkar
1650
Mohammad Bazrkar  
Alain Verleyen:

I don't have this problem (with the code I posted).

Check that hWnd is different from 0.

You can also try to increase the sleep value to 50 or 100.


I'm using your code, but I have a problem with it's name.

2018.01.11 12:06:15.864 cannot open file 'C:\............\MQL4\indicators\MACDèõšp.ex4' [123]

2018.01.11 12:04:00.518 cannot open file 'C:\.............\MQL4\indicators\MACD.ex4' [123]

First line is raised when

   uchar name2[4];

   name2[0]='M'; name2[1]='A'; name2[2]='C'; name2[3]='D';

   // StringToCharArray(IndicatorName,name2,0,StringLen(IndicatorName));

Second line is raised when

   uchar name2[];

   StringToCharArray(IndicatorName,name2,0,StringLen(IndicatorName));


I changed First code it's working now!

   uchar name2[5];

   name2[0]='M'; name2[1]='A'; name2[2]='C'; name2[3]='D'; name2[4]=0;

   // StringToCharArray(IndicatorName,name2,0,StringLen(IndicatorName));

I think my problem is about end of array detecting!
Kray
53
Kray  

Hello everyone,

I would like to thanks Georgiy Liashchenko, and I would like to share my upgraded version of his code that add the indicator directly into the chart with AutomaticallyAcceptDefaults (when it is on "true").

#import "user32.dll"
   int  RegisterWindowMessageW(string MessageName);
   int  PostMessageW(int hwnd,int msg,int wparam,uchar &Name[]);
   int  FindWindowW(string lpszClass,string lpszWindow);
#import

#define VK_RETURN 13 //ENTER key

void StartCustomIndicator(int hWnd,string IndicatorName,bool AutomaticallyAcceptDefaults=false)
{
   Sleep(100);
   uchar name2[];
   StringToCharArray(IndicatorName,name2,0,StringLen(IndicatorName));
   int MessageNumber=RegisterWindowMessageW("MetaTrader4_Internal_Message");
   int r=PostMessageW(hWnd,MessageNumber,15,name2);
   Sleep(100);
   if(AutomaticallyAcceptDefaults) {
      int ind_settings = FindWindowW(NULL, "Custom Indicator - "+IndicatorName);
      PostMessageW(ind_settings,0x100,VK_RETURN,name2);
   }
}

int OnInit()
{
   int hWnd = WindowHandle(Symbol(), 0);
   StartCustomIndicator(hWnd, "Indicator_name");
   return(INIT_SUCCEEDED);
}

I hope it will help some people that need to insert indicators from the expert.

Note : I works for custom indicators, else change the windows name

Note2 : Don't use indicators with more than 15 characters (before the ".ex4")

fridayda13
75
fridayda13  
Kray:

Hello everyone,

I would like to thanks Georgiy Liashchenko, and I would like to share my upgraded version of his code that add the indicator directly into the chart with AutomaticallyAcceptDefaults (when it is on "true").

I hope it will help some people that need to insert indicators from the expert.

Note : I works for custom indicators, else change the windows name

Note2 : Don't use indicators with more than 15 characters (before the ".ex4")

Very nice.


I discovered that using:

int r=PostMessageW(hWnd,MessageNumber,13,name2);

Instead of using:

int r=PostMessageW(hWnd,MessageNumber,15,name2);

Will let you use standard indicators also, by using the standard indicator's name.

123
To add comments, please log in or register