Questions from Beginners MQL5 MT5 MetaTrader 5 - page 356

 

Karputov Vladimir:
Высылайте.

Sent

 
Karputov Vladimir:
Send it to me.
I would also add that if the input parameters are changed, the indicator also works correctly and without errors
 

With the help ofKarputov Vladimir. I have solved the problem by getting the indicator handle in the OnInit() function and then deleting it in OnDeinit().

Could you please make the indicator draw lines from a certain bar, not on the entire history?

 

Good afternoon. I have such a problem. I have started to learn MQL and am writing an EA. When I compile and then run my EA, it opens EURUSD one hour chart, but I have not specified which chart to open. I have prescribed the opening of Euro dollar for 5 minutes. First it opens Euro dollar by an hour, and then by 5 minutes. How can I delete the hour chart? Here is the code of the Expert Advisor. Thanks for the advice in advance.


//+------------------------------------------------------------------+
//|а.mq4 |
//|Valery Wilkes |
//|https://www.mql5.com ||
//+------------------------------------------------------------------+
#property copyright "Valery Wilkes"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
double iAlligator();
bool ObjectSetInteger();
long a=ChartOpen("EURUSD",PERIOD_M5);
//+------------------------------------------------------------------+
//| Expert initialization function|
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetTimer(5);

//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function|
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();

}
//+------------------------------------------------------------------+
//| expert tick function|
//+------------------------------------------------------------------+
void OnTick()
{


for(int f=3;; f++)
{
double val=iFractals("EURUSD",15,1,f);
if(val!=0)
{
Alert("Buy Fractal",val, "Bar Left",f);
break;
}
}
for(int f1=3;; f1++)
{
double val1=iFractals("EURUSD",15,2,f1);
if(val1!=0)
{
Alert("Fractal to sell ",val1, "Bar left",f1);
break;
}
Alert(Bid);
}


}
//+------------------------------------------------------------------+
//| Timer function|
//+------------------------------------------------------------------+

void OnTimer()
{


}
//+------------------------------------------------------------------+
//| Tester function|
//+------------------------------------------------------------------+
double OnTester()
{
//---
double ret=0.0;
//---

//---
return(ret);
}
//+------------------------------------------------------------------+

Автоматический трейдинг и тестирование торговых стратегий
Автоматический трейдинг и тестирование торговых стратегий
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
valeravilks:

Good afternoon. I have such a problem. I have started studying MQL, and I am writing an Expert Advisor. When I compile and run the Expert Advisor, it opens EURUSD hourly chart, but I have not specified yet which chart to open. I have prescribed the opening of Euro dollar for 5 minutes. First it opens Euro dollar by an hour, and then by 5 minutes. How can I delete the hour chart? Here is the code of the Expert Advisor. Thanks for the tip in advance.



You must be enabling debugging and then your EA starts on the default symbol. Specify the required symbol and TF in the metaeditor settings. (See attached picture).

Files:
kagfqct9ki.png  28 kb
 
Good afternoon.
int maxValueIdx= ArraySort(INDEX,WHOLE_ARRAY,ArrayMaximum(INDEX,WHOLE_ARRAY,0),MODE_ASCEND);
int minValueIdx=ArraySort(INDEX,WHOLE_ARRAY,ArrayMinimum(INDEX,WHOLE_ARRAY,0),MODE_DESCEND);  
What do you think it means?
 
azfaraon:
Good afternoon.
What do you think it means?
This is MQL4 code. First, it looks for the maximum in the array, checks the whole array, starting from the zero element. And then the array is sorted starting from the found maximal index (in the first example in ascending order, in the second - in descending order).
 

So in this piece we are looking for max and min values from maximum to minimum ?

and in this

  int maxValueIdx=ArrayMaximum(INDEX,WHOLE_ARRAY,0);
      int minValueIdx=ArrayMinimum(INDEX,WHOLE_ARRAY,0);

from min to max?

 
azfaraon:


This code:

int maxValueIdx=ArrayMaximum(INDEX,WHOLE_ARRAY,0);

searches for the index of the element with the maximum value. The search is performed starting from element zero and through the whole array.

 
azfaraon:

Here's the code

//+------------------------------------------------------------------+
//|                                                  test_script.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- Инициализация массива
   int INDEX[]={2,45,21,8,96,14,32,6,81,46,1,3,31,22,5,78,24,25,66};

//--- Выведем на печать наш массив
   int size;
   string text;

   size=ArraySize(INDEX);        // размер нашего массива
   text=NULL;
   for(int i=0;i<size;i++)
     {
      if(i<size-1)
         text=text+IntegerToString(INDEX[i])+",";
      else
         text=text+IntegerToString(INDEX[i]);
     }
   Print("Старт");
   Print(text);
//---
   Print("---");
   Print("Элемент с индексом ",ArrayMaximum(INDEX,WHOLE_ARRAY,0),
         " имеет максимальное значение равное ",INDEX[ArrayMaximum(INDEX,WHOLE_ARRAY,0)]);
   int maxValueIdx=ArraySort(INDEX,WHOLE_ARRAY,ArrayMaximum(INDEX,WHOLE_ARRAY,0),MODE_ASCEND);

//--- Выведем на печать наш массив
   size=ArraySize(INDEX);       // размер нашего массива   
   text=NULL;
   for(int i=0;i<size;i++)
     {
      if(i<size-1)
         text=text+IntegerToString(INDEX[i])+",";
      else
         text=text+IntegerToString(INDEX[i]);
     }
   Print(text);

//---
   Print("---");
   Print("Элемент с индексом ",ArrayMinimum(INDEX,WHOLE_ARRAY,0),
         " имеет минимальное значение равное ",INDEX[ArrayMinimum(INDEX,WHOLE_ARRAY,0)]);
   int minValueIdx=ArraySort(INDEX,WHOLE_ARRAY,ArrayMinimum(INDEX,WHOLE_ARRAY,0),MODE_DESCEND);

//--- Выведем на печать наш массив
   size=ArraySize(INDEX);       // размер нашего массива   
   text=NULL;
   for(int i=0;i<size;i++)
     {
      if(i<size-1)
         text=text+IntegerToString(INDEX[i])+",";
      else
         text=text+IntegerToString(INDEX[i]);
     }
   Print(text);
   Print("Конец");
  }
//+------------------------------------------------------------------+

and this is the result:

2015.05.03 19:20:03.917 test_script #CHL,Daily:  Старт
2015.05.03 19:20:03.917 test_script #CHL,Daily: 2,45,21,8,96,14,32,6,81,46,1,3,31,22,5,78,24,25,66
2015.05.03 19:20:03.917 test_script #CHL,Daily: ---
2015.05.03 19:20:03.917 test_script #CHL,Daily:  Элемент с индексом 4 имеет максимальное значение равное 96
2015.05.03 19:20:03.917 test_script #CHL,Daily: 2,45,21,8,1,3,5,6,14,22,24,25,31,32,46,66,78,81,96
2015.05.03 19:20:03.917 test_script #CHL,Daily: ---
2015.05.03 19:20:03.917 test_script #CHL,Daily:  Элемент с индексом 4 имеет минимальное значение равное 1
2015.05.03 19:20:03.917 test_script #CHL,Daily: 2,45,21,8,96,81,78,66,46,32,31,25,24,22,14,6,5,3,1
2015.05.03 19:20:03.917 test_script #CHL,Daily:  Конец

Explore, please.