MQL4 Add indicator to chart from EA - page 5

To add comments, please log in or register
Behrooz Basaeri
190
Behrooz Basaeri  

Forum on trading, automated trading systems and testing trading strategies

MQL4 Add indicator to chart from EA

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);
  }

Hi every body

above code works in a Expert ,How do I use from above codes in a Indicator ?

please help.

Abdul Manan
43
Abdul Manan  
Is it possible in MT4 to remove the indicator from the chart using EA ? Some code may be written in OnDenit() function.
long_a17
33
long_a17  
Abdul Manan:
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.

ChartIndicatorDelete - 图表操作 - MQL4参考
ChartIndicatorDelete - 图表操作 - MQL4参考
  • docs.mql4.com
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. If the short name of an indicator is not set explicitly, then the name of the file containing the source code of the indicator will be specified during...
Cromo
259
Cromo  
Alain Verleyen:
Is there way to attach the indicator by auto on the chart from EA when backtest?
Tatix
5
Tatix  
int OnInit()
  {
//---
// In my code where I launch the indicator
   int hWnd=WindowHandle(Symbol(),0);
   StartCustomIndicator(hWnd,INDICATOR_NAME);

   return(INIT_SUCCEEDED);
  }


This code work, but only in OnInit section. If i try transfer it to section CHARTEVENT_OBJECT_CLICK for launch with key, nothing happend. Can you help me ?
Abdul Manan
43
Abdul Manan  
Hi, I'm not able to load 2 indicators from 1 EA using the same code.
To add comments, please log in or register