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

 
Guys, this is a question for which I have not found an answer anywhere. What function to write in the indicator so that new bars do not open and ticking in the zero bar, until it works my condition, please answer me in private))
 

Hello!

I am confused in three pines:

I set numbers extern int a =2; extern int b =3; extern int c =4; how do I now set the number abcto change its value when changing a, or b, or c to compare it to some given d (e.g.d=344)?

Thank you!

 
novichok2018:

Hello!

I am confused in three pines:

I set numbers extern int a =2; extern int b =3; extern int c =4; how do I now set the number abcto change its value when changing a, or b, or c to compare it to some given d (e.g.d=344)?

Thank you!

x = c + b*10 + a*100

 
Сергей Таболин:

x = c + b*10 + a*100

Oh, my God! I'm racking my brains! Thank you!

 
Hello, 2020.10.03_13:33 GMT+3. I took the standard Moving Average EA for MetaTrader 4. And started changing it so that it became profitable. When trying to describe the closing conditions using the OrderProfit() function in the strategy tester, the Expert Advisor stopped closing trades at that condition. It does not go as far as closing a trade. However, I doubt that I have written closing conditions correctly. The Expert Advisor would close trades otherwise. I will probably try to write the deal opening price and the last prices. Once the maximum difference between the opening price and the last price is reached and this difference is reduced -- close the trade. I am attaching the Expert Advisor file. 13:50 GMT+3.
Files:
 
Николай Никитюк:
Hello, 2020.10.03_13:33 GMT+3. I took the standard Moving Average EA for MetaTrader 4. And started changing it so that it became profitable. When trying to describe the closing conditions using the OrderProfit() function in the strategy tester, the Expert Advisor stopped closing trades at that condition. It does not go as far as closing a trade. However, I doubt that I have written closing conditions correctly. The Expert Advisor would close trades otherwise. I will probably try to write the deal opening price and the last prices. Once the maximum difference between the opening price and the last price is reached and this difference is reduced -- close the trade. I am attaching the Expert Advisor file. 13:50 GMT+3.
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
   //--- check order type
      // 
      if(OrderType()==OP_BUY)
        {
        /*
         if(OrderProfit()>0.0)  
           {ProfitMax=OrderProfit(); break;} // Здесь у вас прерывается цикл, если сделка в плюсе
         if(OrderProfit()>ProfitMax)
           {ProfitMax=OrderProfit(); break;}
         if((ProfitMax-DiffProfit)<0.0) break;    
         if((ProfitMax-DiffProfit)>OrderProfit())
         */
         if(DiffProfit<OrderProfit())     // Исходя из ваших условий, то вот            
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }  
         else break;     
         break;
        }
      if(OrderType()==OP_SELL)
        {
        /*
         if(OrderProfit()>0.0)  
           {ProfitMax=OrderProfit(); break;} // Здесь у вас прерывается цикл, если сделка в плюсе
         if(OrderProfit()>ProfitMax)
           {ProfitMax=OrderProfit(); break;}
         if((ProfitMax-DiffProfit)<0.0) break;     
         if((ProfitMax-DiffProfit)>OrderProfit())
         */
         if(DiffProfit<OrderProfit())        // Исходя из ваших условий, то вот
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         else break;  
         break;
        }
     }      

//+------------------------------------------------------------------+
 

Hello!

I've started to write a function to normalise the input data. But I can't "replace" the original values with the normalized ones. I.e. I cannot update values in Open timeseries buffer with new values from Temp array. What is my error? I have a feeling that I'm trying to cross OOP and non-OOP)).

Open=new CiOpen();
   if(CheckPointer(Open)==POINTER_INVALID || !Open.Create(Symb.Name(),PERIOD_CURRENT))
      return;
//---
   int bars=10;
   double Temp[];                //Создаем массив для временного хранения входных данных
   ArraySetAsSeries(Temp,true);  //Устанавливает флаг AS_SERIES
   Open.GetData(0,bars,Temp);    //Копируем необходимые данные в массив Temp
   InputNormalize(Temp,bars);    //Нормализуем данные в массиве
 
//---Как заменить значения в Open значениями из Temp?---

  }
//+------------------------------------------------------------------+
//| функция нормализации входных данных                              |
//+------------------------------------------------------------------+
void InputNormalize(double &buffer[],int bars)
  {
   double d1=-1;
   double d2=1;
   double x_min=buffer[ArrayMinimum(buffer,0,bars)];
   double x_max=buffer[ArrayMaximum(buffer,0,bars)];
   for(int i=0; i<bars; i++)
     {
      buffer[i]=(((buffer[i]-x_min)*(d2-d1))/(x_max-x_min))+d1;
     }
   return;
  }

I'm sure it can be done in a simpler way! In this case please teach me)

 
Aleksei Lesnikov:

Hello!

I've started to write a function to normalise the input data. But I can't "replace" the original values with the normalized ones. I.e. I cannot update values in Open timeseries buffer with new values from Temp array. What is my error? I have a feeling that I'm trying to cross OOP and non-OOP)).

I'm sure it can be done in a simpler way! In this case please teach me)

Read the language documentation

The value of predefined variables is set by the client terminal before starting an mql4-program for execution. Predefined variables are constant and cannot be changed from the mql4-program.


Предопределенные переменные - Справочник MQL4
Предопределенные переменные - Справочник MQL4
  • docs.mql4.com
Для каждой выполняющейся mql4-программы поддерживается ряд предопределенных переменных, которые отражают состояние текущего ценового графика на момент запуска программы - эксперта, скрипта или пользовательского индикатора. Значение предопределенным переменным устанавливает клиентский терминал перед запуском mql4-программы на выполнение...
 
Alexey Viktorov:

Read the language documentation

Alexey, thank you! It's clear now that it's not possible.

It's true, I'm not exactly mql4. I'm trying to change data through the CiOpen class. I'm confused by the Update method, which should change the element at a specified position of the array.

Документация по MQL5: Стандартная библиотека / Индикаторы / Таймсерии / CiOpen
Документация по MQL5: Стандартная библиотека / Индикаторы / Таймсерии / CiOpen
  • www.mql5.com
CiOpen - Таймсерии - Индикаторы - Стандартная библиотека - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Aleksei Lesnikov:

Alexei, thank you! It's clear now that it's not possible.

It's true, I don't have exactly mql4. I'm trying to change data through the CiOpen class. I'm confused by the Update method, which should change the element at a specified position of the array.

Since the question is posed in the mql4 section, I answered regarding mql4. There are no hints to mql5 in your question. But the result is the same.