Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1287

 

Hello. 2020.10.28_05:19:00 GMT+3. I translated the LeManTrend_Indicator.mq5 indicator into the fourth version .mq4 . The indicator appears on the chart, but when I try to switch GBPUSD,H1 to M5 timeframe, MetaTrader4 hangs, CPU is overloaded. I have to close MetaTrader4 and open it again. No freezes when I remove LeManTrend_Indicator.ex4 from the chart. I do not understand what is wrong in the indicator code. Who can give me a hint? How to fix it?

And LeMan_BrainTrend1Sig.mq5 converted to the fourth version, it is in the list of indicators, but nothing appears on the chart. How to rewrite the code of this indicator to make it work properly, I do not know. I have written only Expert Advisors before. How to check them in strategytester- I know. And when I write Print() of variables in the code, it becomes clear what is wrong. I do not know how to check the indicators. I wrote Print() in the code, it is not saved in any log. Will someone advise me what to do with indicators to make them work, not to take up space on the hard disk? Looking forward to hearing from you. 05:44 GMT+3.

Yes I'll post the indicator codes now. One more thing. Why have I converted indicators from .mq5 to .mq4 ? Because my broker has ruble accounts only in MetaTrader4. And indicators are written in fifth version. And I need indicators to write a profitable Expert Advisor for MetaTrader4. That's it now. 05:53 GMT+3.

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

Hello. 2020.10.28_05:19:00 GMT+3. I translated the LeManTrend_Indicator.mq5 indicator into the fourth version .mq4 . The indicator appears on the chart, but when I try to switch GBPUSD,H1 to M5 timeframe, MetaTrader4 hangs, CPU is overloaded. I have to close MetaTrader4 and open it again. No freezes when I remove LeManTrend_Indicator.ex4 from the chart. I do not understand what is wrong in the indicator code. Who can give me a hint? How to fix it?

And LeMan_BrainTrend1Sig.mq5 converted to the fourth version, it is in the list of indicators, but nothing appears on the chart. How to rewrite the code of this indicator to make it work properly, I do not know. I have written only Expert Advisors before. How to check them in strategytester- I know. And when I write Print() of variables in the code, it becomes clear what is wrong. I do not know how to check the indicators. I wrote Print() in the code, it is not saved in any log. Will someone advise me what to do with indicators to make them work, not to take up space on the hard disk? Looking forward to hearing from you. 05:44 GMT+3.

Yes I'll post the indicator codes now. One more thing. Why have I converted indicators from .mq5 to .mq4 ? Because my broker has ruble accounts only in MetaTrader4. And indicators are written in fifth version. And I need indicators to write a profitable Expert Advisor for MetaTrader4. That's it now. 05:53 GMT+3.

LeManTrend_Indicator.mq5- the indicator itself herehttps://www.mql5.com/ru/code/27570

it also works in 4 - but you need to remove the repeating (string ) before (err_text)

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

it would look like this

//+------------------------------------------------------------------+
//| 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- the indicator itself herehttps://www.mql5.com/ru/code/27570

it also works in 4 - but you need to remove the repeating (string ) before (err_text)

it should look like this

string

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

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

This one should contain the already corrected LeManTrend_Indicator.mq4 for quadruplets

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

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

Here you need to add LeManTrend_Indicator.mq4, already fixed for 4

there is an error - you need to delete this line ( double const = 0; )

and everything will work

    double const = 0;

double const = 0; 2.PNG


 
Nikolai Semko:

You're a comedian.

Who was I talking to?



What's this situation about? Same bar index. And it seems to happen only on the first run on a symbol. Either deeper into the story. I thought the code above was just checking for bars...

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


Here is a good indicatorhttps://www.mql5.com/ru/code/28364

Everything you need can be built into it !!!!!!!

//+------------------------------------------------------------------+
//|                                                      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 также реализована система звуковых и текстовых алертов, а также отправка...
Files:
EURUSDM30.png  35 kb
 

Good afternoon!

Please help me with the following task:

I need to run a script (Python) from MQL4 Expert Advisor. I'm trying to do it using ShellExecuteW() in the following way:

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

I get a file access error. The script is running but the code does not go further.


I will be glad if you can share the function to run the script.

Another question: how do I check the script's execution?

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

Hello! 2020.10.28_05:19:00 GMT+3. I translated the LeManTrend_Indicator.mq5 indicator into the fourth version .mq4 .

This one does not fit

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

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

And this one doesn't fit.

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

This one seems to be better.

//+------------------------------------------------------------------+
//|                                                      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);
  }
//+------------------------------------------------------------------+
Files: