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

 
skyjet:

Hello! I am comparing the opening prices of 3 bars (3,2,1). How can I not count the bars where the prices are equal?

for (int x=1; x<3; x++)
{
 if(Open[x]==Open[x+1]) continue;
 if(Open[x]<Open[x+1])
   {
   //--- action
   }
}
 
Hello, help me out. I am playing on H1, I have an H4 indicator. It shows correctly. But if I run it in the tester, with visualisation, for example at the beginning of the year, it shows the current information that is now in the market. In general, it does not work in the Strategy Tester. How to make it work. Or give a link to the topic where it is solved.
 
artmedia70:
How is it empty? Does it output anything at all, or are there zeros in the array cells?


Nothing at all.

Even if you go into Objects there's nothing at all, except for the arrows and the trend lines...

artmedia70:

Why are you increasing the i in the body of the loop?

and this: i<=p, why "or equal to" ?


I made a mistake out of tiredness. I fixed it this way:

for(i=0; i<p; i++)
      {
          pr("a[i][1] = " + a[i][1]);
      }

This piece of code is in the function itself:

//+-------------------------------------------------------------------------------------+
//| Закрытие ордеров, отсортированных по размеру лотов                                  |
//+-------------------------------------------------------------------------------------+
void ClosePosBySortLots()
{
   double a[][2];
   int p = 0;
   
   for (int i=OrdersTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() < 2)
      {
         p++;
         ArrayResize(a, p);
         a[p-1][0] = OrderLots();
         a[p-1][1] = OrderTicket();
      }
   }
//   pr ("ClosePosBySortLots(): " + "p = " + p);
   if (p > 0)
   {
      ArraySort(a, WHOLE_ARRAY, 0, MODE_DESCEND);
      
      for(i=0; i<p; i++)
      {
          pr("a[i][1] = " + a[i][1]);
      }
      
      for(i=0; i<p; i++)
      {
         if (OrderSelect(a[i][1], SELECT_BY_TICKET, MODE_TRADES))
         {
             if (OrderCloseTime() == 0) ClosePosBySelect();
         }
      }
   }
}
 
hoz:


Nothing at all.

Even if you go into Objects there are no objects at all, except for the arrows and trend lines...


It was me who messed up out of fatigue. I fixed it this way:

This piece of code is in the function itself:

Before and after

if (p > 0)

unprint p value.

Do I have to write the sequence of fault-finding for you?

 
artmedia70:

Before and after.

Unprint the p-value.

Do I have to write the error sequence for you?



As a matter of fact, yes. Anyway, here's the situation:

void ClosePosBySortLots()
{
   double a[][2];
   int p = 0;
   
   for (int i=OrdersTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() < 2)
      {
         p++;
         ArrayResize(a, p);
         a[p-1][0] = OrderLots();
         a[p-1][1] = OrderTicket();
      }
   }
//   pr ("ClosePosBySortLots(): " + "p = " + p);
   pr("___p = " + p);   // Значение кол-ва позиций до if..
   
   if (p > 0)
   {
      pr("p = " + p);   // Значение кол-ва позиций после if..
      
      ArraySort(a, WHOLE_ARRAY, 0, MODE_DESCEND);
      
      for(i=0; i<p; i++)
      {
          pr("a[i][1] = " + a[i][1]);
      }
      
      for(i=0; i<p; i++)
      {
         if (OrderSelect(a[i][1], SELECT_BY_TICKET, MODE_TRADES))
         {
             if (OrderCloseTime() == 0) ClosePosBySelect();
         }
      }
   }
}

I've done it this way, but nothing comes out at this part of the chart either. Although in other places it printed 0, when one position was open and it closed at once by take. I.e., in this area kosakova works as if...

Here is a screenshot:

Should I print all these values now?

p++;
ArrayResize(a, p);
a[p-1][0] = OrderLots();
a[p-1][1] = OrderTicket();

It seems like there's a lot further to go. After all, everything is clearly and usually written there.

 
hoz:


Actually, it is. Anyway, here's the situation:

I've run it this way, but nothing comes out at this part of the chart either. Although in other places it printed 0, when one position was open and it closed at once on the take. I.e., in this sector, kosakova works as if...

Here is a screenshot:

Should I print all these values now?

It seems like there's a lot further to go. After all, it's all clearly and usually written there.

Do you understand and see what is contained in your array immediately after it is "filled" with warrant data? No. You don't know, you only assume. SPRINT the contents of all array cells, not with your pr(), but with the standard Print() and try to look into the tester's log and see what you have in the array, in every cell, right after it is filled. When you know for sure that the contents of the array matches your ideas about its contents, then print it with your pr(). If it doesn't give you the same results - it's your pr(), if the data match, then look for an error in the next step.
 
There are lot-related errors in the logbook(OrderSend error 4051). Solve this issue. Maybe it will help. Then we'll see what happens.
 
hoz:
There are lot-related errors in the logbook (OrderSend error 4051). Solve this issue. Maybe it will help. And then we'll see.

Look at the tanks, reboot, maybe it will help... :-)

P.S. I'm being kind here.

 
This is a one-dimensional array whose size can vary.
How to loop through all possible combinations of array elements with each other?
The order of elements doesn't matter, i.e. 123==213==321...

Here is an example for an array with 4 elements:
[4] <=> { 1 2 3 4 }

1, 12, 13, 14, 123, 124, 134, 1234, 
2, 23, 24, 234, 
3, 34,
4
 
Roman.:

Look at the tanks, reboot, maybe it will help... :-)

P.S. I'm being kind.

Nah. Tanks are not an option. If you really want to do something like that. It's only the result that calms you down))