Questions from Beginners MQL5 MT5 MetaTrader 5 - page 484

 
Friends, I have more of a question about the signal settings.
The problem is the following: when the Provider's orders are closed, the Subscriber's orders are still held. Apparently because of the difference in spread. How should I make deals of a Subscriber be closed immediately when they are closed at the Provider's one? What setting should be changed?
 
Leo59:
Thank you Alexey!!!! for 4))))

So...I found my old turkey and cut out what I needed from it. I won't write it for you)), but it will do for a kick start. I've added comments there, the names of the variables are clear from the names.

datetime date[]; // тут будем хранить данные времени баров, которые видны на экране
// если нужны другие данные баров, заводим соотв. массивы 

void DoWork(bool redrawAll = false)
{
    int visibleBars = 1, firstVisibleBars = 0;
    visibleBars = (int)ChartGetInteger(0, CHART_VISIBLE_BARS);
    firstVisibleBars = (int)ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR);
    
    ArrayResize(date, visibleBars + 10); // выделяем память с запасом

    // так можно узнать масштаб графика, может пригодится
    int scale = (int)ChartGetInteger(0, CHART_SCALE);
    // копируем данные времен баров 
    if (CopyTime(Symbol(), Period(), startpos, visibleBars, date) == -1)
    {
        Print("Не удалось скопировать значения времени! Код ошибки = ", GetLastError());
        return;
    }

    //--- определим шаг, если надо работать с масштабом
    int step = 1;
    switch (scale)
    {
    case 0:
        step = 12;
        break;
    case 1:
        step = 6;
        break;
    case 2:
        step = 4;
        break;
    case 3:
        step = 2;
        break;
    }
    double priceMin = ChartGetDouble(0,CHART_PRICE_MIN,0);
    double priceMax = ChartGetDouble(0,CHART_PRICE_MAX,0);

    for (int i = visibleBars - 1; i >= 0; i--)
    {
        /*
        проходимся по всем видимым барам и ищем стрелки, искать можно путями:
        1. Изначально при создании стрелок надо формировать имена стрелок с привязкой ко времени, например
        string name = "UpArrow"  + IntegerToString(TimeCurrent());
        тогда тупо ищем стрелку с таким именем и далее двигаем, куда надо
        2. Заносить стрелки в структуры и класть их в хештаблицу, первый проще
        */
    }
    
}
 
Artem Prischepa:
My friends, I have a question more about the signal setting.
The problem is the following: when orders of a Provider are closed, they still remain on the Subscriber's one. Apparently because of the difference in spread. How should I make deals of a Subscriber be closed immediately when they are closed at the Provider's one? What setting should be changed?

The deal should also close almost instantly. Questions:

  1. Is the subscriber's terminal on at this time?
  2. Please attach the log file of the terminal for the problem day.
 
Alexey Volchanskiy:

So...I found my old turkey and cut out what I needed from it. I won't write it for you)), but it will do for a kick start. I added comments there, the names of variables are clear from the names.

Additionally, I should probably put indicator subwindow number in this line? I just don't know exactly what is needed

ChartGetDouble(0,CHART_PRICE_MIN,0);
 
Alexey Volchanskiy:

Addendum, you should probably put the indicator subwindow number on this line? I just don't know exactly what is needed

Oooops, absent-minded this morning, didn't copy the chart event handling in the code

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
    if(id == CHARTEVENT_CHART_CHANGE)
    {
        DoWork(true);
        ChartRedraw();
    }    
}
 
Alexey Volchanskiy:

So...I found my old turkey and cut out what I needed from it. I won't write it for you)), but it will do for a kick start. I have added comments there, the names of variables are clear from the names.

Thanks Alexey for your help!

And where to attach the step, and in general its functionality, about what?

    //--- определим шаг, если надо работать с масштабом
    int step = 1;

And this:

        2. Заносить стрелки в структуры и класть их в хештаблицу, первый проще

I've never done. If you can, please give me a code example, so that I can understand, understand and apply it.

 
Alexey Volchanskiy:

Oooops, absent-minded this morning, didn't copy the graph event handling in the code

I wish I had your absent-mindedness along with your knowledge))
It's easy enough when you know. Just bang on the keys, as long as you have the desire and means to do it.
And when you don't know and you're digging... that's a pain in the ass... And if there's more hints, you're screwed, no nerve at all.
So thank you for the tips!!!!
 
Leo59:
Thank you Alexey for your help!

Where do you screw in the pitch, and its functionality in general, about what?

And this:

I've never done. If you can, please give me a code example, so that I could understand, understand and use it.

When we compress the graph horizontally (+/- keys), it changes scale and sometimes the graphical objects can overlap each other. I cited this code just in case, how to determine the scale.

I won't cite the code with hash - I don't have it, it just occurred to me. It's better to do variant 1, it's simpler.

Regarding knowledge - I advise everyone who studies, read the help at your leisure, just hop around the sections, where everything is. That is, do not cram it, I was such a crammer, to no good. You just need to know, at least approximately, that there are such-and-such... at least sections/sub-sections. Then, when questions arise, the gears will spin in your head and a direction of search will arise. In principle, the help is not perfect, but it's fine, there are plenty of examples.

Because the language itself is simple, it's not hard to learn. Difficulties arise with API, where to look for what and how to apply

 
Hello!

At first glance, the task seems as simple as three cents. BUT! ....
There is a line of any oscillator in the indicator window, which wiggles relative to "0" with different amplitude.
The actual problem is:
- At "0" crossing from bottom to top, draw an arrow at the bottom border of the indicator window,
- At "0" crossing from the top downwards, to draw an arrow near the upper border of the indicator window,
- at self-scaling of the oscillator chart in the indicator window, the arrows should automatically remain at their borders of the indicator window.
I.e., scrolling the chart backwards and forwards through the history, or changing its horizontal scale, the arrows should always remain at the boundaries of the indicator window automatically.

Please don't give any tips, "help me financially")). Please attach the source code of such a function, or link to it.

Thanks in advance!
 

Please help me to understand!

I need to find the maximum drawdown on each (let it be) day (writing to the file happens once a day) - MT4 terminal.

The max drawdown is the distance on the chart from the peak to the current drawdown of funds and the drawdown of funds is the current loss.

I wrote the following code

   if(Analiz_Prosadki==true)
     {
      if(ContolSavaTXT==1)
        {
         ProfitNew=0;
         ProfitMin=0;
         ContolSavaTXT=0;
        }

      if(ContolSavaTXT==0)
        {
         ProfitNew=AccountInfoDouble(ACCOUNT_PROFIT);
         BalansNew==AccountInfoDouble(ACCOUNT_BALANCE);  //Текузее значение баланса
         if (BalansNew>BalansMax) BalansMax=BalansNew;
         if (ProfitNew<ProfitMin && BalansNew>=BalansMax) ProfitMin=ProfitNew;
         if (ProfitNew<ProfitMin && BalansNew<BalansMax) ProfitMin=ProfitNew-(BalansMax-BalansNew);
        }

      ContolSavaTXT=Printer.Write((string)TimeCurrent(),ProfitMin);   // Пишем информацию в файл - функция возвращает 1
     }

But it is correct in some charts and incorrect in others. At the same time, the charts are visually the same.

I must have made a mistake in the code or logic, but I cannot understand what kind.

Reason: