MQL4 从EA添加指标到图表 - 页 5

 

关于交易、自动交易系统和测试交易策略的论坛

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

大家好

上述代码在专家中起作用,我如何在指标中使用上述代码?

请帮助。

 
在MT4中,是否可以用EA将指标从图表中移除?可以在OnDenit()函数 中编写一些代码。
 
Abdul Manan:
在MT4中,是否可以用EA将指标从图表中删除?一些代码可以写在OnDenit()函数 中。

从指定的图表窗口中删除一个具有指定名称的指标。该命令被添加到图表消息队列中,只有在所有先前的命令被处理后才会执行。

boolChartIndicatorDelete(
longchart_id,// 图表ID
intsub_window,// 子窗口的编号
const stringindicator_shortname// 指标的短名称
);

参数

chart_id

[in] 图表ID。0表示当前图表。

sub_window

[in] 图表子窗口的编号。0表示主图表的子窗口。

const indicator_shortname

[in] 指标的短名称,通过IndicatorSetString() 函数在INDICATOR_SHORTNAME 属性中设置。 要获得一个指标的短名称,请使用ChartIndicatorName() 函数。

返回值

如果命令被添加到图表队列中,返回true,否则返回false。要获得错误信息,请使用GetLastError() 函数。

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...
 
Alain Verleyen:
是否有办法在回溯测试 时从EA的图表上自动附加指标?
 
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 ?
 
你好,我无法使用相同的代码从一个EA加载2个指标。
 
这条线对我帮助很大,但并没有让我完全达到目的 -- 请看这条线(https://www.forexfactory.com/showthread.php?p=12764287#),它从这里的对话中继续前进。
 
Kray:

大家好。

我想感谢Georgiy Liashchenko,我想分享他的代码的升级版,即把指标直接添加到图表中并自动接受默认值 (当它是 "true "时)

我希望它能帮助一些需要从专家那里插入指标的人。

注意:我适用于自定义指标,否则请更改窗口名称。

注2:不要使用超过15个字符的指标(在".ex4 "之前)。

你好,我得到了这个结果

不能调用'user32.dll::RegisterWindowMessageW','user32.dll'没有加载。

谁能帮助我?


 
Alain Verleyen:

我没有这个问题(用我发布的代码)。

检查hWnd是否与0不同。

你也可以尝试将睡眠值增加到50或100。

亲爱的阿兰,

我使用你的代码在所有打开的图表 中添加了一个指标。但它只添加到我运行EA的图表中。

这里是代码,你能不能修改你的代码,将同一个指标添加到所有打开的图表中?

请帮助我们

BTW(我试着用EA和脚本,都只在一个图表上添加指标):)

问候。



#import "user32.dll"

int RegisterWindowMessageW(string MessageName);

int PostMessageW(int hwnd,int msg,int wparam,ucar &Name[])。

#import


#define INDICATOR_NAME "CCI_FILTER6C"


int NOS ;

string suffix=""。

string symbol[30];

long chartid[30];


//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+


int OnStart()

{

NOS=10。

后缀="c"。

symbol[0] = "AUDCAD" + suffix ;

symbol[1] = "AUDCHF" + suffix ;

符号[2] = "AUDJPY" + 后缀。

符号[3] = "AUDNZD" + 后缀。

符号[4] = "AUDUSD" + 后缀。

符号[5] = "CADJPY" + 后缀 ;

符号[6] = "CHFJPY" + 后缀。

符号[7] = "EURAUD" + 后缀。

符号[8] = "EURCAD" + 后缀 ;

符号[9] = "EURCHF" + 后缀。

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

}

 
Abdul Manan:
你好,我无法使用相同的代码从一个EA中加载两个指标。

也在寻找这个--有人想出了如何从同一个EA中添加多个指标吗?


我想在同一个EA中添加2个https://docs.mql4.com/indicators/ima


谢谢