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

 

Hello.

Please help me to colour a zigzag.

I want to make it so that if the distance from the trough to the top is >=100 points, to colour the segment green.

 
Dimitry-1983:

Hello!

I've already racked my brains. How do I check if there is a certain price in the double array?

I wrote it like this for the test:



The script finds 11, 22, 33, 44 without any problems (the terminal has such orders). However, if the script processes the price of 45, for example, it still shows 3 (position of the price 44 in the array).

What I really need is a bool - if there is a price of the order being processed in the array, it should return true, if not, it should return false. But I have not yet found such a function in the language.

The functionreturns the index of the first element found in the first array dimension, butif the sought value is not found, it returns the index of the element with the smallest value, between which the sought value is located. Therefore, for this task, we should also check for the equality of the sought value and the found one. The result of the comparison will be true or fakse

 
STARIJ:

Why should I print something from the indicator? Everything is on the screen - that's what the indicator is. When I need a table - I run the script with iCustom()


What you wrote here, I didn't understand anything. We were talking about the fact that I create a file, which is always empty for some reason. I can't get an array of data into a file.

I need the data to be saved in a file. If the indicator is attached to the chart for 1 year, so that there are all records of its readings for the year!

 
Alekseu Fedotov:

That's an interesting way of sewing it in.

Try this by mistake.


Thank you! But I already tried that and it didn't work.

 

Can you people advise me why the errors are coming up?

//--- input parameters
input int      MyLevel=100; // установка уровня (отступ) выше (ниже) текущей цены;
//--- indicator buffers
double         Label1Buffer[];
double         Label2Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   SetIndexBuffer(1,Label2Buffer);
   double R1 = 0; // служеные переменные принимаются равными 0;
   double R2 = 0; // служебные переменные; принимаются равными 0;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---

   double i=Bid; // переменной i присваивается значение текущего курса;

   if(i>=R1) // если текущий курс >= служебной переменной R1;
     {
      R1=i+(MyLevel*Point); // то присваиваем R1 новое значение равное текущему курсу + отступ,
      R2=i-(MyLevel*Point); // также присваиваем R2 новое значение = текущий курс - отступ;
     }
   else
     {
      break;  // иначе, выходим из оператора
     }
   if(i<=R2) // если текущий курс <= служебной переменной R2;
     {
      R1=i+(MyLevel*Point); // то присваиваем R1 новое значение равное текущему курсу + отступ,
      R2=i-(MyLevel*Point); // также присваиваем R2 новое значение = текущий курс - отступ;
     }
   else
     {
      break; // иначе выходим
     }

   Label1Buffer [0] = R1; // заносим в буфер данные R1
   Label2Buffer [0] = R2; // и R2

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Errors:

'R1' - undeclared identifier Mylevel.mq4 61 10

possible loss of data due to type conversion Mylevel.mq4 63 9

'R2' - undeclared identifier Mylevel.mq4 64 7

';' - 'break' must be used within some loop or switch statement Mylevel.mq4 68 12

';' - 'break' must be used within some loop or switch statement Mylevel.mq4 77 12


 
YarTrade:

Can you people advise me why the errors are coming up?

Errors:

'R1' - undeclared identifier Mylevel.mq4 61 10

possible loss of data due to type conversion Mylevel.mq4 63 9

'R2' - undeclared identifier Mylevel.mq4 64 7

';' - 'break' must be used within some loop or switch statement Mylevel.mq4 68 12

';' - 'break' must be used within some loop or switch statement Mylevel.mq4 77 12


R1, R2 are declared inside a function, respectively - only visible there - they are local.
break is used in loops and swith
 

I'm not sure if there is a program for combining testing reports similar to reportmanager for mt5,reportmanager doesn't open them.

 
iv1986:

If you know, is there a program for combining testing reports similar to reportmanager for mt5, butreportmanager doesn't open them?

It's easier to rewrite the code and do multicurrency testing in mt5. The results of testing in the mt4 platform are definitely not correct, and the final result will be critically distorted and there is no point in analyzing it.

Here is one of the 23 symbol tests, everything is clear and almost obvious


 

Can I make a multi-instrumental EA if I have different parameters and strategies for each instrument?

Vitaly Muzichenko:

It's easier to rewrite the code and do multicurrency testing in mt5. The results of testing in the mt4 platform are obviously wrong, and the final result will be critically distorted and there is no point in analyzing it.

Here is one of the tests for 23 symbols, everything is clear and almost obvious


And if I have a different strategy and correspondingly different code for each symbol, can I make such an EA?

 
iv1986:

Can I make a multi-instrumental EA if I have different parameters and strategies for each instrument?

And if I have different strategies and code for each instrument, is it possible to make such an EA?

You can write a multi-currency EA, it will be in one file. It is possible to combine the strategies for different pairs in one file for the tester, and it is also possible to trade them online on one chart, but it is possible to separate them so that each strategy trades on the symbol on which the EA has been placed. The possibilities are unlimited