Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1197

 
Alexey Viktorov:

For display in the tester? Yes. Create a template with all the indicators you need and save it with the EA name or tester name and the test will open with these settings.

On the real and demo account charts.

 

Greetings!

Does anyone know how to contact Maxim Gutman?

Trader, developer of an automated trading system

 
odyn:

On the real and demo account charts.

Here is the MACD, for example

All the others are the same.

 

Good afternoon, please advise or throw me a link to see

I need to select from the open positions those that have a lifetime exceeding a certain period.

How do I correctly compare the time a position opens with the current time?

I threw this function, what to do next I can not think (little experience), how to compare the time?

//+------------------------------------------------------------------+
bool Selected_Positions_Time_Life(datetime time_life, int &array_base[][observations])
{
int n = 0;
int size = ArrayRange(array_base,0);

for(int i=0; i<size; i++)
{
   int index  = Arr_Position[i][0];
   int ticket = m_position.SelectByIndex(index);
   datetime tl = m_position.Time();
   datetime tc = TimeCurrent();
 //Вот тут наверное нужно сравнить tl и tc 
 //и если разница превышает time_life, то это наша позиция
}

return(n>0);
}
//+------------------------------------------------------------------+
 
Sergey Voytsekhovsky:

Good afternoon, please advise or throw me a link to see

I need to select from the open positions those that have a lifetime exceeding a certain period.

How do I correctly compare the time a position opens with the current time?

I named this function, but I have no idea what to do next (lack of experience), how do I compare times?

In the loop, select a position and get its ticket.

ulong posTicket = PositionGetTicket(i);

Next, get the opening time of the position

PositionGetInteger(POSITION_TIME)
and compare with the reference time ±.
 
Alexey Viktorov:

Select a position in the loop and get a ticket for it

Then get the opening time of position

And compare with the reference time ±.

Just this comparison procedure throw up please, with the ticket position, time of opening and server time, I think I figured it out, I can not compare. I looked through the comment, I just get dates.

 
Sergey Voytsekhovsky:

This is exactly the comparison procedure please, with the position ticket, opening time and server time I think I figured it out, I can't compare. I looked through the comment, I just get the dates.

So you compare the dates. But you have to consider the discrepancy. It's better to compare the difference between the opening time and the reference time with an allowable deviation.

fabs(время_позиции - эталонное_время) < допустимого_отклонения // например 600 секунд
 
Alexey Viktorov:

So compare the dates. But you have to consider the discrepancy. It's better to compare the difference between the opening time and the reference time with a tolerance deviation.

Alexey Viktorov:

So compare the dates. But you have to consider the discrepancy. It's better to compare the difference between the opening time and the reference time with the tolerance.

Roger that, thanks, I'll try it as soon as I'm at my computer (I'm on my mobile at the moment).

 

Good afternoon.

I want to sort the vertical lines by time on the chart. I've written a little script. But the result is not what I want.

Please advise what i am doing wrong.

void OnStart()
{
int      vlines            = 0;
string   vlines_name[];
string   vlines_name_sort[];
datetime tm[];

   vlines = ObjectsTotal(ChartID(),0,OBJ_VLINE);
   if(vlines < 20 * 2)
   {
      Print("вертикальных линий меньше необходимиого. (",vlines," < ",20 * 2,")");
      return;
   }
   ArrayResize(vlines_name,vlines);
   ArrayResize(vlines_name_sort,vlines);
   
   for(int i = 0; i < vlines; i++)
   {
      vlines_name[i] = ObjectName(ChartID(),i,0,OBJ_VLINE);
   }
   ArrayPrint(vlines_name);
   
   for(int i = 0, n = 0; i < 9000; i++)
   {
      ArrayFree(tm);
      CopyTime(Symbol(),Period(),i,1,tm);
      
      for(int a = 0; a < vlines - 1; a++)
      {
         datetime tml = (datetime)ObjectGetInteger(ChartID(),vlines_name[a],OBJPROP_TIME);
         if(tml == tm[0])
         {
            vlines_name_sort[n++] = vlines_name[a];
            break;
         }
      }
   }
   ArrayPrint(vlines_name_sort);
}

The result:

(GBPUSD,H6)     [ 0] "H6 Vertical Line 10771" "H6 Vertical Line 10884" "H6 Vertical Line 12743" "H6 Vertical Line 1371"  "H6 Vertical Line 14306"
(GBPUSD,H6)     [ 5] "H6 Vertical Line 16501" "H6 Vertical Line 17907" "H6 Vertical Line 20277" "H6 Vertical Line 23365" "H6 Vertical Line 28358"
(GBPUSD,H6)     [10] "H6 Vertical Line 28756" "H6 Vertical Line 29445" "H6 Vertical Line 30340" "H6 Vertical Line 31840" "H6 Vertical Line 32885"
(GBPUSD,H6)     [15] "H6 Vertical Line 33779" "H6 Vertical Line 34048" "H6 Vertical Line 38532" "H6 Vertical Line 38756" "H6 Vertical Line 39075"
(GBPUSD,H6)     [20] "H6 Vertical Line 39458" "H6 Vertical Line 39649" "H6 Vertical Line 40385" "H6 Vertical Line 41116" "H6 Vertical Line 4150" 
(GBPUSD,H6)     [25] "H6 Vertical Line 41900" "H6 Vertical Line 42820" "H6 Vertical Line 43071" "H6 Vertical Line 46245" "H6 Vertical Line 48196"
(GBPUSD,H6)     [30] "H6 Vertical Line 50258" "H6 Vertical Line 50374" "H6 Vertical Line 55171" "H6 Vertical Line 56003" "H6 Vertical Line 56400"
(GBPUSD,H6)     [35] "H6 Vertical Line 57565" "H6 Vertical Line 59075" "H6 Vertical Line 59881" "H6 Vertical Line 59969" "H6 Vertical Line 63122"
(GBPUSD,H6)     [40] "H6 Vertical Line 63540" "H6 Vertical Line 63904" "H6 Vertical Line 64359" "H6 Vertical Line 64420" "H6 Vertical Line 65200"
(GBPUSD,H6)     [45] "H6 Vertical Line 6695"  "H6 Vertical Line 7743"  "H6 Vertical Line 8707"  "H6 Vertical Line 9491"  "H6 Vertical Line 9662" 

(GBPUSD,H6)     [ 0] "H6 Vertical Line 46245" "H6 Vertical Line 39075" "H6 Vertical Line 40385" "H6 Vertical Line 55171" "H6 Vertical Line 31840"
(GBPUSD,H6)     [ 5] "H6 Vertical Line 63904" "H6 Vertical Line 6695"  "H6 Vertical Line 59075" "H6 Vertical Line 28358" "H6 Vertical Line 10884"
(GBPUSD,H6)     [10] "H6 Vertical Line 38532" "H6 Vertical Line 29445" "H6 Vertical Line 23365" "H6 Vertical Line 64420" "H6 Vertical Line 7743" 
(GBPUSD,H6)     [15] "H6 Vertical Line 30340" "H6 Vertical Line 39649" "H6 Vertical Line 38756" "H6 Vertical Line 34048" "H6 Vertical Line 42820"
(GBPUSD,H6)     [20] "H6 Vertical Line 64359" "H6 Vertical Line 50374" "H6 Vertical Line 14306" "H6 Vertical Line 48196" "H6 Vertical Line 57565"
(GBPUSD,H6)     [25] "H6 Vertical Line 20277" "H6 Vertical Line 41116" "H6 Vertical Line 12743" "H6 Vertical Line 50258" "H6 Vertical Line 41900"
(GBPUSD,H6)     [30] "H6 Vertical Line 17907" "H6 Vertical Line 4150"  "H6 Vertical Line 59881" "H6 Vertical Line 56400" "H6 Vertical Line 10771"
(GBPUSD,H6)     [35] "H6 Vertical Line 63540" "H6 Vertical Line 65200" "H6 Vertical Line 9491"  "H6 Vertical Line 16501" "H6 Vertical Line 63122"
(GBPUSD,H6)     [40] "H6 Vertical Line 32885" "H6 Vertical Line 1371"  "H6 Vertical Line 33779" null                     null                    
(GBPUSD,H6)     [45] null                     null                     null                     null                     null                    
 
Сергей Таболин:

Good afternoon.

I want to sort the vertical lines by time on the chart. I've written a little script. But the result is not what I want.

Please advise what i am doing wrong.

The result:

Logically, you first need to collect all the lines in an array, I would do immediately two-dimensional, well, or array structure, in the first dimension add a time of creation, in the second - the name of the line.

In the loop for one run, fill the array, outside the loop after filling the array is sorted by the first dimension, that is, the time.

The result is printed in the second loop.

As a result, we have 2 cycles and sorting between them.

That's all, if I understood the problem correctly :)

Reason: