mql4 - 如何使用指标计数以及如何将关键事件转换为 MQL4 中的代码
问题描述
我只是在学习编码并且有几个问题。有人可以告诉我如何做这件事吗?
1- 如何防止我的自定义指标在图表上重复?如果它已经在图表上并且我会将它再次放到图表上,我希望它检测到第一个并中止启动第二个。
像这样的东西:但工作:)
int OnInit()
{
int indicators_total = ChartIndicatorsTotal(0,0);
for(int i = 0; ndicators_total > i; i++)
{
if(ChartIndicatorName(0,0,i)==IndicatorName)
return(INIT_FAILED); (AND THEN EXIT)
}
}
2 - 我如何检测图表上是否有多个同名指标?
3 - 如果图表上不存在指标“x”(=0),如何编写“if”语句来做某事?
像这样的东西:但工作:)
if(IndicatorName==0)
{
Print("INDI ",IndicatorName, " NOT DETECTED");
}
4 - 有没有办法将键盘事件(F11 - 全屏)放入代码中?为了让我的自定义指标能够像“图表比例”一样检测全屏显示ChartGetInteger(0,CHART_SCALEFIX);
?
解决方案
欢迎来到 SOF。看counter
下面。这个想法是计算图表上的指标数量。您要添加的副本将在此列表中出现一次(此副本)或更多(您正在尝试将新副本添加到现有副本)。此示例适用于主图表(子窗口 = 0)。
int OnInit()
{
const string indName = WindowExpertName(); // name of your indicator
int counter=0;
for(int i=ChartIndicatorsTotal(0,0)-1;i>=0;i--)
{
//printf("%i %s: i=%d/%d, %s",__LINE__,__FILE__,i,ChartIndicatorsTotal(0,0),ChartIndicatorName(0,0,i));
if(ChartIndicatorName(0,0,i)==indName)
counter++;
}
if(counter>1)
{
Print("already exist!");
return INIT_FAILED;
}
//--- indicator buffers mapping
// do all other indicator preparation work here
//---
return(INIT_SUCCEEDED);
}
推荐阅读
- python - 如何理解“鸡”与“超市”有关,与“犹太教堂”或“牙医”无关
- python - 如何让 pygame 更快地加载图像?
- c# - 路由没有找到控制器
- image - 如何在android中使用不同像素比的android图像?对于无法使用 imageName@1.5x 的 hdpi 图像,我应该使用什么?
- python - 使用小数据集进行回归
- android - 如何在 Android 上实现 OAuth2 授权
- html - 具有自动适应功能的网格
- ruby-on-rails - 使用茧宝石时看不到部分
- python - Python函数从未见过
- javascript - 如何导出 javascript 类以在测试单元中使用?