新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 1287

 

你好!2020.10.28_05:19:00 GMT+3。我把LeManTrend_Indicator.mq5指标翻译成第四版.mq4。该指标出现在图表上,但当我试图将GBPUSD,H1切换到M5时间框架时,MetaTrader4挂起,CPU超载。我必须关闭MetaTrader4,然后再打开它。当我从图表中删除LeManTrend_Indicator.ex4时,没有冻结。我不明白指标代码中有什么问题。谁能给我一个提示?如何解决这个问题?

而LeMan_BrainTrend1Sig.mq5转换为第四个版本,它在指标列表中,但图表上什么也没有出现。如何重写这个指标的代码以使其正常工作,我不知道。我以前只写过专家顾问。如何策略测试器 检查它们--我知道。而当我在代码中写下变量的Print()时,就会发现问题所在了。我不知道如何检查指标。我在代码中写了Print(),它没有保存在任何日志中。谁能告诉我怎样处理指标才能使其发挥作用,而不是占用硬盘空间?期待您的来信。05:44 GMT+3。

是的,我现在就把指标代码贴出来。还有一件事。为什么我把指标从.mq5转换为.mq4?因为我的经纪人只在MetaTrader4中有卢布账户。而指标是用第五版写的。我需要指标来为MetaTrader4写一个有利可图的专家顾问。现在就是这样了。05:53 GMT+3。

Тестирование стратегий - Алгоритмический трейдинг, торговые роботы - Справка по MetaTrader 5
Тестирование стратегий - Алгоритмический трейдинг, торговые роботы - Справка по MetaTrader 5
  • www.metatrader5.com
Тестер стратегий позволяет тестировать и оптимизировать торговые стратегии (советники) перед началом использования их в реальной торговле. При тестировании советника происходит его однократная прогонка с начальными параметрами на исторических данных. При оптимизации торговая стратегия прогоняется несколько раз с различным набором параметров...
 
Николай Никитюк:

你好!2020.10.28_05:19:00 GMT+3。我把LeManTrend_Indicator.mq5指标翻译成第四版.mq4。该指标出现在图表上,但当我试图将GBPUSD,H1切换到M5时间框架时,MetaTrader4挂起,CPU超载。我必须关闭MetaTrader4,然后再打开它。当我从图表中删除LeManTrend_Indicator.ex4时,没有冻结。我不明白指标代码中有什么问题。谁能给我一个提示?如何解决这个问题?

而LeMan_BrainTrend1Sig.mq5转换为第四个版本,它在指标列表中,但图表上什么也没有出现。如何重写这个指标的代码以使其正常工作,我不知道。我以前只写过专家顾问。如何策略测试器 检查它们--我知道。而当我在代码中写下变量的Print()时,就会发现问题所在了。我不知道如何检查指标。我在代码中写了Print(),它没有保存在任何日志中。谁能告诉我怎样处理指标才能使其发挥作用,而不是占用硬盘空间?期待您的来信。05:44 GMT+3。

是的,我现在就把指标代码贴出来。还有一件事。为什么我把指标从.mq5转换为.mq4?因为我的经纪人只在MetaTrader4中有卢布账户。而指标是用第五版写的。我需要指标来为MetaTrader4写一个有利可图的专家顾问。现在就是这样了。05:53 GMT+3。

LeManTrend_Indicator.mq5- 这里的指标本身https://www.mql5.com/ru/code/27570

它在4中也能工作 - 但你需要删除(err_text)之前的重复(string)。

      string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")?
                      "Параметр \"Midle\" меньше 1!":
                      "Parameter \"Midle\" is less than 1!";

它看起来像这样

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- check "MA averaging period" parameter
   if(PeriodEMA<1)
     {
      string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")?
                      "Параметр \"MA averaging period\" меньше 1!":
                      "Parameter \"MA averaging period\" is less than 1!";
      //--- when testing, we will only output to the log about incorrect input parameters
      if(MQLInfoInteger(MQL_TESTER))
        {
         Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);
         return(INIT_FAILED);
        }
      else // if the Expert Advisor is run on the chart, tell the user about the error
        {
         Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);
         return(INIT_PARAMETERS_INCORRECT);
        }
     }
//--- check "Min" parameter
   if(Min<1)
     {
      err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")?
               "Параметр \"Min\" меньше 1!":
               "Parameter \"Min\" is less than 1!";
      //--- when testing, we will only output to the log about incorrect input parameters
LeManTrend Indicator
LeManTrend Indicator
  • www.mql5.com
Индикатор на основе анализа максимальных и минимальных цен. Сигналы индикатора возникают в месте пересечения линий 'BUY' и 'SELL':
 
SanAlex:

LeManTrend_Indicator.mq5- 这里的指标本身https://www.mql5.com/ru/code/27570

它在4中也能工作 - 但你需要删除(err_text)之前的重复(string)。

它应该看起来像这样

绳子

 
Николай Никитюк:

BrainTrend1Sig for 4 here -https://www.mql5.com/ru/code/8772

这个应该包含已经修正过的LeManTrend_Indicator.mq4,用于四合院。

BrainTrend1Sig
BrainTrend1Sig
  • www.mql5.com
Индикатор BrainTrend1Sig.
 
SanAlex:

BrainTrend1Sig for 4 here -https://www.mql5.com/ru/code/8772

在这里,你需要添加LeManTrend_Indicator.mq4,已经固定为4。

有一个错误 - 你需要删除这一行 ( double const = 0;)

而且一切都会成功

    double const = 0。

double const = 0; 2.PNG


 
Nikolai Semko:

你是一个喜剧演员。

我在和谁说话?



这种情况是怎么回事呢?相同的酒吧指数。而且这似乎只发生在一个符号的第一次运行上。要么深入到故事中。我以为上面的代码只是在检查酒吧...

 
Николай Никитюк:


这里有一个很好的指标https://www.mql5.com/ru/code/28364

你所需要的一切都可以建立在它的基础上 !!!!!!!

//+------------------------------------------------------------------+
//|                                                      Phoenix.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
//--- setting the indicator name
#property description "Phoenix"
//--- set the strict mode of compilation
#property strict
//--- specify where to draw the indicator
#property indicator_chart_window
//--- specify the number of buffers
#property indicator_buffers 2
//--- setting the color of the indicator rendering
#property indicator_color1 clrGreenYellow
#property indicator_color2 clrRed
//--- we define the input parameters

//--- specify arrays of indicator buffers
double arrow_01[];
double arrow_02[];
//*********************************************//
bool flag_buy   = false;
bool flag_sell  = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   string short_name;
//--- we specify two additional buffers for calculations
   IndicatorBuffers(2);
   SetIndexBuffer(0,arrow_01);
   SetIndexBuffer(1,arrow_02);
//--- setting the indicator to be drawn as a line
   SetIndexStyle(0,DRAW_ARROW,EMPTY,2,clrGreenYellow);
   SetIndexArrow(0,233);
   SetIndexBuffer(0,arrow_01);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,2,clrRed);
   SetIndexArrow(1,234);
   SetIndexBuffer(1,arrow_02);
//--- setting a name in the DataWindow window and a label
   short_name="Phoenix";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//--- if there are no errors,initialization is completed successfully
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                            Phoenix                               |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   for(int shift=rates_total; shift>=0; shift--)
     {
      //--- to simplify the coding and speed up access data are put into internal variables
      double MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,shift);
      double SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,shift);
        {
         if(flag_buy==false)
            //--- check for long position (BUY) possibility
            if(MacdCurrent>SignalCurrent)
              {
               arrow_01[shift]=Low[shift];
               flag_buy=true;
               flag_sell=false;
              }
         if(flag_sell==false)
            //--- check for short position (SELL) possibility
            if(MacdCurrent<SignalCurrent)
              {
               arrow_02[shift]=High[shift];
               flag_buy=false;
               flag_sell=true;
              }
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
Phoenix
Phoenix
  • www.mql5.com
В стрелочном индикаторе Phoenix используется комбинация трех индикаторов: Moving Average, Bolinger Bands и Momentum в сочетании с двумя мощными формулами, основанными на поведении цены текущего графика. В индикаторе Phoenix также реализована система звуковых и текстовых алертов, а также отправка...
附加的文件:
EURUSDM30.png  35 kb
 

下午好!

请帮助我完成以下任务。

我需要从MQL4专家顾问运行一个脚本(Python)。我想用ShellExecuteW()来做,方法如下。

#import "shell32.dll"
string ShellExecuteW(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);
#import
#include <WinUser32.mqh>

void OnStart()
  {
ShellExecuteW(NULL, NULL, "C:\\Users\\yansa\\Desktop\\test_script.py", NULL, NULL, 1);
  }

我得到一个文件访问错误。脚本在运行,但代码却没有进一步发展。


如果你能分享运行该脚本的功能,我将很高兴。

另一个问题:我怎样才能检查脚本的执行情况?

 
Николай Никитюк:

你好!2020.10.28_05:19:00 GMT+3。我把LeManTrend_Indicator.mq5指标翻译成第四版.mq4。

这个不适合

https://www.mql5.com/ru/code/9096

LeManTrend
LeManTrend
  • www.mql5.com
Индикатор определяет положение тренда на основе текущей цены и максимальных и минимальных цен за три периода.
 
MakarFX:

而这个人不适合。

https://www.mql5.com/ru/code/9096

这个似乎更好。

//+------------------------------------------------------------------+
//|                                                      Phoenix.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
//--- setting the indicator name
#property description "Phoenix"
//--- set the strict mode of compilation
#property strict
//--- specify where to draw the indicator
#property indicator_chart_window
//--- specify the number of buffers
#property indicator_buffers 2
//--- setting the color of the indicator rendering
#property indicator_color1 clrGreenYellow
#property indicator_color2 clrRed
//--- we define the input parameters

//--- specify arrays of indicator buffers
double arrow_01[];
double arrow_02[];
//*********************************************//
bool flag_buy   = false;
bool flag_sell  = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   string short_name;
//--- we specify two additional buffers for calculations
   IndicatorBuffers(2);
   SetIndexBuffer(0,arrow_01);
   SetIndexBuffer(1,arrow_02);
//--- setting the indicator to be drawn as a line
   SetIndexStyle(0,DRAW_ARROW,EMPTY,2,clrGreenYellow);
   SetIndexArrow(0,233);
   SetIndexBuffer(0,arrow_01);
   SetIndexStyle(1,DRAW_ARROW,EMPTY,2,clrRed);
   SetIndexArrow(1,234);
   SetIndexBuffer(1,arrow_02);
//--- setting a name in the DataWindow window and a label
   short_name="Phoenix";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//--- if there are no errors,initialization is completed successfully
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                            Phoenix                               |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   for(int shift=rates_total; shift>=0; shift--)
     {
      //--- to simplify the coding and speed up access data are put into internal variables
      double MacdCurrent=iCustom(NULL,0,"LeManTrend",13,21,34,3,MODE_MAIN,shift);
      double SignalCurrent=iCustom(NULL,0,"LeManTrend",13,21,34,3,MODE_SIGNAL,shift);
        {
         if(flag_buy==false)
            //--- check for long position (BUY) possibility
            if(MacdCurrent>SignalCurrent)
              {
               arrow_01[shift]=Low[shift];
               flag_buy=true;
               flag_sell=false;
              }
         if(flag_sell==false)
            //--- check for short position (SELL) possibility
            if(MacdCurrent<SignalCurrent)
              {
               arrow_02[shift]=High[shift];
               flag_buy=false;
               flag_sell=true;
              }
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
附加的文件:
原因: