
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Forum on trading, automated trading systems and testing trading strategies
MQL4 Add indicator to chart from EA
Alain Verleyen, 2016.02.13 11:39
Hi every body
above code works in a Expert ,How do I use from above codes in a Indicator ?
please help.
Is it possible in MT4 to remove the indicator from the chart using EA ? Some code may be written in OnDenit() function.
Removes an indicator with a specified name from the specified chart window. The command is added to chart message queue and executed only after all previous commands have been processed.
bool ChartIndicatorDelete(
long chart_id, // chart id
int sub_window, // number of the subwindow
const string indicator_shortname // short name of the indicator
);
Parameters
chart_id
[in] Chart ID. 0 denotes the current chart.
sub_window
[in] Number of the chart subwindow. 0 denotes the main chart subwindow.
const indicator_shortname
[in] The short name of the indicator which is set in the INDICATOR_SHORTNAMEproperty with the IndicatorSetString()function. To get the short name of an indicator use the ChartIndicatorName()function.
Return Value
Returns true if the command has been added to chart queue, otherwise false. To get errordetails use the GetLastError()function.
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")
Hi I got this
Cannot call 'user32.dll::RegisterWindowMessageW', 'user32.dll' is not loaded
Can anyone help me?
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
Dear Alain ,
I used your code to add one indicator to all open charts. but it only added to the chart on which I run the EA.
here is the code , can you please modify your code to add the same indicator to all open charts ?
please help
BTW ( I tried it as EA and also as script , both added the indicator to only one chart ) :)
regards,
#import "user32.dll"
int RegisterWindowMessageW(string MessageName);
int PostMessageW(int hwnd,int msg,int wparam,uchar &Name[]);
#import
#define INDICATOR_NAME "CCI_FILTER6C"
int NOS ;
string suffix="";
string symbol[30];
long chartid[30];
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int OnStart()
{
NOS=10;
suffix="c";
symbol[0] = "AUDCAD" + suffix ;
symbol[1] = "AUDCHF" + suffix ;
symbol[2] = "AUDJPY" + suffix;
symbol[3] = "AUDNZD" + suffix;
symbol[4] = "AUDUSD" + suffix ;
symbol[5] = "CADJPY" + suffix ;
symbol[6] = "CHFJPY" + suffix;
symbol[7] = "EURAUD" + suffix ;
symbol[8] = "EURCAD" + suffix ;
symbol[9] = "EURCHF" + suffix;
for(int is=0;is<NOS;is++)
{
int hWnd=WindowHandle(symbol[is],PERIOD_M30);
StartCustomIndicator(hWnd,INDICATOR_NAME);
}
return(0);
}
void StartCustomIndicator(int hWnd,string IndicatorName,bool AutomaticallyAcceptDefaults=true)
{
uchar name2[];
StringToCharArray(IndicatorName,name2,0,StringLen(IndicatorName));
int MessageNumber=RegisterWindowMessageW("MetaTrader4_Internal_Message");
int r=PostMessageW(hWnd,MessageNumber,15,name2);
Sleep(100);
}
Hi, I'm not able to load 2 indicators from 1 EA using the same code.
looking for this as well - has anyone figured out how to add multiple indicators from the same EA?
i want to add 2 https://docs.mql4.com/indicators/ima from the same EA
thanks