Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 638

 
gnawingmarket:

My question is for a newbie:

I recently found out that MetaEditor is not opening in the terminal, and the "change" command does not work in EAs and indicators ............. Please help me with this. Thank you.


I'll try to answer that.

No possibility to correct old codes works anymore.

 
But you have a prince crowned.
 
tara:
At least you have a prince to crown.


You know everything! Today I couldn't catch who put me Administrator, and I didn't get the password, and I didn't think to ask! I'll get it tomorrow! What are you doing up?

Thank you tara for your participation! I had everything restored to me by my neighbour on the block! Computer science expert!

 
Top2n:

Yes, I understand that there are a lot of stupid questions. Honestly, I've been trying all day, but with no results.

I am writing the price values of several trend lines on the current bar into an array.

How can I delete a value from the array if there is no object?

artmedia70:

If we run through the values of the trend line prices on every tick, initialize the array and increase its dimension when finding the next necessary price of the necessary trend line, then there will be no need to remove the values of the deleted trend lines from the array. The array will be dynamic, and every time at every tick, it will contain only values of existing objects.


?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
double MassTrendNumber(double &array[], string tip) // Поиск значения цены трендовой линии, текущего бара, запись в массив. Два массива: masS и masB
ArrayResize(array,ObjectsTotal(OBJ_TREND));

 for (int i = 0, limit = ArrayResize(array,ObjectsTotal(OBJ_TREND)); i < limit; i++) 

 {
 string DWnem=ObjectName(i); 
  string DW="downtrendline"+IntegerToString(i); // существует два названия трендовых линий, первое
  string DW2="uptrendline"+IntegerToString(i); // второе
if(tip="Sell")   //первый массив цен на селл
  if(DWnem=DW)//если имя равно "downtrendline"
   if(ObjectGet(DWnem,OBJPROP_COLOR)==Goldenrod || ObjectGet(DWnem,OBJPROP_COLOR)==Gainsboro || ObjectGet(DWnem,OBJPROP_COLOR)==White)
// Также существует три цвета
   array[i]=ObjectGetValueByShift(DWnem,1); //записываем
if(tip="Buy")   //второй массивцен на бай
 if(DWnem=DW2)
 if(ObjectGet(DWnem,OBJPROP_COLOR)==Goldenrod || ObjectGet(DWnem,OBJPROP_COLOR)==Gainsboro || ObjectGet(DWnem,OBJPROP_COLOR)==White)
  array[i]=ObjectGetValueByShift(DWnem,1);

  }   return;
   }

	          
 

I am trying to make an oscillator around 0 from the close price in a separate window, but I can't. Maybe somebody already did it, could you please tell me the formula?

I.e. we have Close[i] price, I need this price to go above/below zero like in MACD/CCI, in a separate window, but try as I may, I cannot do it without additional values like MA: now I get something similar if I subtract iClose-iMA, but maybe there are variants without smoothing?

Or in the range 0.0...1.0 if there is no way around zero...

 
Top2n:

The search method in the one below is slightly different:

#property strict

/******************************************************************************/
bool AddValue(double &array[], const double value) {
  const int size = ArraySize(array);

  if (ArrayResize(array, size + 1) != size + 1) {
    return false; // Ошибка, значение не может быть добавлено к массиву
  }

  array[size] = value; //записываем
  return true; // Нет ошибки, значение добавлено к массиву
}

/******************************************************************************/
bool AddValueIfFound(double &array[], const string name) {
  const int type = ObjectType(name);

  if (type == OBJ_TREND) {
    switch ((color)ObjectGet(name, OBJPROP_COLOR)) { // Тип color допустимо использовать в switch
    case Goldenrod:
    case Gainsboro:
    case White:
      if (!AddValue(array, ObjectGetValueByShift(name, 1))) {
        return false; // Ошибка, значение найдено, но не может быть добавлено к массиву
      }
    }
  }

  return true; // Нет ошибки, значение, если найдено, добавлено к массиву
}

/******************************************************************************/
bool MassTrendNumber(double &array[], const bool buy) { // Поиск значения цены трендовой линии, текущего бара, запись в массив. Два массива: masS и masB
  const string subname = (buy ? "uptrendline" : "downtrendline"); // существует два названия трендовых линий, первое и второе

  if (ArrayResize(array, 0) != 0) {
    return false; // Ошибка, массив не может быть заполнен достоверно
  }

  for (int i = 0, limit = ObjectsTotal(OBJ_TREND); i < limit; i++) {
    if (!AddValueIfFound(array, subname + IntegerToString(i))) {
      return false; // Ошибка, массив, если и заполнен, то недостоверно
    }
  }

  return true; // Нет ошибки, массив заполнен достоверно
}

/******************************************************************************/
void FillAndPrint(double &array[], const bool buy) {
  if (MassTrendNumber(array, buy)) {
    const int limit = ArraySize(array);

    Print("Найдено объектов: ", limit);

    for (int i = 0; i < limit; i++) {
      Print("Price[", i, "] = ", DoubleToStr(array[i], Digits));
    }
  } else {
    Print("Чёрт!");
  }
}

/******************************************************************************/
void OnStart() {
  double masS[];
  double masB[];

  Print("Sell:");
  FillAndPrint(masS, false);

  Print("Buy:");
  FillAndPrint(masB, true);
}

Add two white trend lines with corresponding names to the graph and you have it:

04:14:34 Script 2 EURUSDm,H1: loaded successfully
04:14:34 2 EURUSDm,H1: initialized
04:14:34 2 EURUSDm,H1: Sell:
04:14:34 2 EURUSDm,H1: Найдено объектов: 1
04:14:34 2 EURUSDm,H1: Price[0] = 1.36268
04:14:34 2 EURUSDm,H1: Buy:
04:14:34 2 EURUSDm,H1: Найдено объектов: 1
04:14:34 2 EURUSDm,H1: Price[0] = 1.35668
04:14:34 2 EURUSDm,H1: uninit reason 0
04:14:34 Script 2 EURUSDm,H1: removed

Don't write kilometre-long functions, break the program into short "phrases" - "bricks". Small "bricks" make bigger ones, and larger ones make even bigger ones. You see, it's possible.

Pass all of your data to functions solely via parameters.

Be sure to handle errors if the function being called fails and further action if the error is ignored will have serious consequences. The vast majority of program crashes (in general) occur because error handling is not programmed in any way.

For example, if ArrayResize(), called to enlarge the array size, returned an error, and the programmer has not checked it and refers to the supposedly enlarged array, an error occurs that causes the MQL4 program to stop working later. The Expert Advisor, for example, stops trading by leaving open positions. Isn't it great?

Try to insert "array[0] = 0;" before the loop in function MassTrendNumber(), and make sure that the script finishes after the array overrun error.

 
evillive:

I am trying to make an oscillator around 0 from the close price in a separate window, but I can't. Maybe somebody already did it, could you please tell me the formula?

I.e. we have Close[i] price, I need this price to go above/below zero like in MACD/CCI, in a separate window, but try as I may, I cannot do it without additional values like MA: now I get something similar if I subtract iClose-iMA, but maybe there are variants without smoothing?

Or in the range 0.0...1.0 if there is no way around zero...


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

Oh, that's about right. Nothing is new in this world )))
 
simpleton:

The search method below is slightly different:

Add two white trend lines with corresponding names to the chart and you've got it:

Don't write kilometre-long functions, break the program into short "phrases"-"bricks". Small "bricks" make bigger ones, and larger ones make even bigger ones. You see, it's possible.

Only pass all data to the functions via parameters.

Be sure to handle errors if the function being called fails, and subsequent action if the error is ignored will have serious consequences. The vast majority of program crashes (in general) occur because error handling is not programmed in any way.

For example, if ArrayResize(), called to enlarge the array size, returned an error, and the programmer has not checked it and refers to the supposedly enlarged array, an error occurs that causes the MQL4 program to stop working later. The Expert Advisor, for example, stops trading by leaving open positions. Isn't that great?

Try to insert "array[0] = 0;" before the loop in MassTrendNumber() and make sure that the script terminates after the array overrun error.


Yes, thank you so much, you are just beyond words how helpful, so clear! Awesomeooo!!!
 
Top2n:

Yes, thank you so much, you are just beyond words how helpful, so clear! Awesomeooo!!!

It would be cool if you could gradually teach yourself important skills in the most direct and efficient way possible.

And if others can benefit in the same way.

Reason: