[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 99

 
alsu:

It's not worth it. Donating 'for something' is a consolation to one's ego, nothing more.

Real charity is always unaddressed.


How's that? Transferring money... Where? To whom? Why?
 

Good afternoon! Please help me with the ArrayMo function (it returns the maximum of the density curve).

double ArrayMo(double& x[], int d=4) {
  double e, s=0;
  double m[][2];             // временный массив:
                             //  столбец 1 - количество значений
                             //  столбец 2 - значения
  int    i, k=ArraySize(x);
  int    n;                  // номер строки временного массива m
  int    r;                  // количество строк во временном массиве m

  if (k>0) {
    for (i=0; i<k; i++) {
      e=NormalizeDouble(x[i], d);
      n=ArraySearchDouble(m, e);
      if (n<0) {
        r=ArrayRange(m, 0);
        ArrayResize(m, r+1);
        m[r][0]++;
        m[r][1]=e;
      } else m[n][0]++;
    }
    ArraySort(m, WHOLE_ARRAY, 0, MODE_DESCEND);
    s=m[0][1];
  } else Print("ArrayMo(): Массив пуст!");

  return(s);
}

The following questions have arisen:

1.What is the purpose of creating a temporary array

m[][2]

2. It's not clear what the values of the temporary array will be taken from, and therefore it's not clear how this array may be searched:

n=ArraySearchDouble(m, e)

3. And then generally for me the truth is deeply hidden))))) Once we have ascertained that there is no value, we start to determine the size of the array of "incomprehensible values".

I would really appreciate a ray of light in this story))))


 
Foxy, what about the ArraySearchDouble function code, is it there? Without it, figuring out what the program does would be much harder)
 

Hello! Here's the trailing stop function, check if it's correct. Because my code will change drastically, it will be hard to deal with errors when I start changing it

void TrailStop(int ticket, int TStop)                           //ф-ция трейлинг стопа, TStop-расстояние в пп
   {
    if (TStop>0)
      {
       OrderSelect(ticket, SELECT_BY_TICKET);
       if(OrderType()==OP_BUY)
         {
          if(Bid - OrderOpenPrice()>Point*TStop)
            {
             if(OrderStopLoss()<Bid-Point*TStop)
               {
                OrderModify(OrderTicket(), OrderOpenPrice(), 
                Bid-Point*TStop, OrderTakeProfit(), 0, Blue);
                return;
               }
             else { }
            }
            else{ }
         }
       else if (OrderType()==OP_SELL)
         {
          if(OrderOpenPrice() - Ask>Point*TStop)
            {
             if(OrderStopLoss()>Ask + TStop*Point)
               {
                OrderModify(OrderTicket(), OrderOpenPrice(), 
                Ask+Point*TStop, OrderTakeProfit(), 0, Blue);
                return;
               }
             else { }
            }
          else { }
         }
       else { }
      }
    else { }
    }
 
gogent:

Hello! Here's the trailing stop function, check if it's correct. I will change my code drastically, it will be hard to deal with errors when I start changing it.

You do not take into account the Stoplevel, so if you have not ECN/NDD, you may get the error "wrong stops".

And in general, after OrderModify it is better to handle all errors, just in case.

 
alsu:
Foxy, how about the code of ArraySearchDouble function, is it there? Without it, it would be much harder to understand what the program does)


These are all functions from KimIV, which is what I'm trying to figure out. Here is the code:


This function searches for an element of an array using a value of type double and returns the index of the found element or -1. The function finds only one element and stops searching if the result is positive.

  • m - The array in which the element is searched.
  • e - The value of type double to be found in array m.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 01.09.2005                                                     |
//|  Описание : Выполняет поиск элемента массива по значению                   |
//|             и возвращает индекс найденного элемента или -1.                |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    m - массив элементов                                                    |
//|    e - значение элемента                                                   |
//+----------------------------------------------------------------------------+
int ArraySearchDouble(double& m[], double e) {
  for (int i=0; i<ArraySize(m); i++) {
    if (m[i]==e) return(i);
  }
  return(-1);
}
 
Professionals, can you tell me what I'm doing wrong? I need to redraw indicator window when a new bar appears. If (Bars != Prebars) WindowRedraw();
does not work. PreBars is equal to the number of bars on the previous tick. Maybe I put it in the wrong place or in the wrong function?
 
kon12:
Professionals, can you tell me what I'm doing wrong? I need to redraw the indicator window when a new bar appears. if (Bars != Prebars) WindowRedraw();
it doesn't result in anything. Maybe I put it in the wrong place or something is wrong?

You have to draw it first in order to redraw something.
 
sergeev:

To redraw something, you have to draw it first.


Everything is drawn perfectly, the indicator is based on a zigzag, but when new bars appear, the curve should be redrawn all over, but it only adds the value of the indicator in a new bar...

int init() {
SetIndexBuffer(0,ZZ);
SetIndexStyle(0,DRAW_SECTION);
SetIndexEmptyValue(0,0.0);

 
kon12:


Everything is drawn fine, the indicator is based on a zigzag, but when new bars appear, the curve should be redrawn all over, but it only adds the value of the indicator in the new bar...

int init() {
SetIndexBuffer(0,ZZ);
SetIndexStyle(0,DRAW_SECTION);
SetIndexEmptyValue(0,0.0);

WindowRedraw() redraws graphical objects. It has nothing to do with buffers.