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

 
//chief2000:

I looked through your code, but what I don't understand is the following - you didn't read the data of the original array at any of the steps. only the number of elements in it


Why do I need data from the original array? I'm just sampling the array elements according to your idea. And it's up to you to decide what to do with the sampled data. I.e. if N[0]=3, if N[1]=2, if N[2]=1, if N[3]=0, we use array[N[0]], array[N[1]], array[N[2]], array[N[3]] for further analysis, and if N[0]=3, N[1]=2, N[2]<0, N[3]<0, then for further analysis we use only array[N[0]], array[N[1]] because N[2]<0 and N[3]<0. We try all possible combinations which don't repeat according to your post (taking into account that array's numeration starts from 0 to ArraySize(array)-1):

[4] <=> { 1 2 3 4 }

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

And then act according to your algorithm:

if(NewComb){
// Получили новую комбинацию в массиве N размерностью k    
    
    for(i=0;i<k;i++){// Перебираем массив N. Если N[i]<0 то элемент array[N[i]] не участвует в выборке.
                     // Например, для размерности 4 если N[0]=3,N[1]=1,N[2}<0,N[3]<0 то это выборка array[3] и array[1]
                     //                             если N[0]=3,N[1]=2,N[2]=1,N[3]=0 то это выборка array[3] и array[2] array[1] и array[0]
     if(N[i]>=0){// использовать как-то array[N[i]]}
    }

   }
 
Sepulca:


Why do I need data from the original array? I am simply sampling elements of the array according to your idea. And it's up to you to decide what to do with the sampled data. I.e. if N[0]=3, if N[1]=2, if N[2]=1, if N[3]=0, we use array[N[0]], array[N[1]], array[N[2]], array[N[3]] for further analysis, and if N[0]=3, N[1]=2, N[2]<0, N[3]<0, then for further analysis we use only array[N[0]], array[N[1]] because N[2]<0 and N[3]<0. We enumerate all possible combinations which are not repeated according to your post (taking into account that array numbering starts from 0 to ArraySize(array)-1):

And then proceed according to your algorithm:


Now it's clear (I have read data in the next step, just not used to working with code not my own).
Thank you very much!

 

Help me find an error in the function.

The problem is that if you count the bars above the MA, the function returns the correct value.

But if it is below the MA, the function always returns 1 (one)

int CheckFiltr ()
   {
   int i=1;
   for (;;)
      {
      if (NormalizeDouble(High[i],Norm)&&NormalizeDouble(Low[i],Norm)<NormalizeDouble(iMA(NULL,0,PerMa,0,MetMa,AplPr,i),Norm)||NormalizeDouble(High[i],Norm)&&NormalizeDouble(Low[i],Norm)>NormalizeDouble(iMA(NULL,0,PerMa,0,MetMa,AplPr,i),Norm))
         {
         i++;
         Comment ("Фильтр = ", i);         
         }
      else break;
      }
   return (i);
   }
 
MarkTrade:

Help me find an error in the function.

The problem is that if you count the bars above the MA, the function returns the correct value.

But if it is below the MA, the function always returns 1 (one)

At first glance this is better, although the code can be significantly optimised, as I have only corrected the grammar:

int CheckFiltr ()
   {
   int i=1;
   int Norm=Digits;
   for (;;)
      {
      if (
           (   NormalizeDouble(High[i],Norm)<NormalizeDouble(iMA(NULL,0,PerMa,0,MetMa,AplPr,i),Norm)
            && NormalizeDouble(Low[i] ,Norm)<NormalizeDouble(iMA(NULL,0,PerMa,0,MetMa,AplPr,i),Norm)
           )
          ||
           (   NormalizeDouble(High[i],Norm)>NormalizeDouble(iMA(NULL,0,PerMa,0,MetMa,AplPr,i),Norm) 
            && NormalizeDouble(Low[i] ,Norm)>NormalizeDouble(iMA(NULL,0,PerMa,0,MetMa,AplPr,i),Norm)
           )
         )

         {
         i++;
         Comment ("Фильтр = ",i);         
         }
      else break;
      }
   return (i);
   }
 
paladin80:

For your example it doesn't actually make any difference, but you have to specify the beginning and the end of the array anyway.

The beginning makes a difference if the array is large. For example, if the condition is triggered as a rule at the end of the array, it is better to start at the end. This example is typical of order/position searching. Of course, if you do the search first in this case, the program will get to this point anyway, but it will take more resources.


Thanks again! Now tried to make the number of "checkable" bars optimisable, but the results in the window just aren't there. Tried to start counting both from the beginning and the end, but in vain.

extern int number=3;
//------------------------------------+
for (int x=number; x>=1; x--)
{
 if(Open[x]==Open[x-1]) continue;
    if(Open[x]<Open[x-1])
   {
   //--- action
   }
 else{
    if(Open[x]>Open[x-1])
   {
   //--- action
  }
 }
}
 
Sepulca:
At first glance this is better, although the code could be significantly optimised:


This works... Thank you!

I just need to understand why my version doesn't want to work...

 
MarkTrade:


It works like this... Thank you!

I just wish I understood why my version doesn't want to work...


Take a closer look at your code

 if (NormalizeDouble(High[i],Norm)&&NormalizeDouble(Low[i],Norm)<NormalizeDouble(iMA(NULL,0,PerMa,0,MetMa,AplPr,i),Norm)
||NormalizeDouble(High[i],Norm)&&NormalizeDouble(Low[i],Norm)>NormalizeDouble(iMA(NULL,0,PerMa,0,MetMa,AplPr,i),Norm))
     
You are simply comparing the first term to zero, i.e. true or false.
 
MarkTrade:


It works... Thank you!

I just wish I understood why my version doesn't want to work...

Your code:

int CheckFiltr ()
   {
   int i=1;
   for (;;)
      {
      if (NormalizeDouble(High[i],Norm)&&
          NormalizeDouble(Low[i],Norm)<NormalizeDouble(iMA(NULL,0,PerMa,0,MetMa,AplPr,i),Norm)
            ||    
          NormalizeDouble(High[i],Norm)&&
          NormalizeDouble(Low[i],Norm)>NormalizeDouble(iMA(NULL,0,PerMa,0,MetMa,AplPr,i),Norm))
         {
         i++;
         Comment ("Фильтр = ",i);         
         }
      else break;
      }
   return (i);
   }

Maybe it's easier to understand...

Oops... you've already been told, you can do it without normalization...

 
Roger:


Take a closer look at your code

You simply compare the first term to zero, i.e. true or false.


So the expression "if a and c are greater than c" is not correct, but "if a is greater than c and c is greater than c" is correct?
 
MarkTrade:


It works... Thank you!

I just wish I understood why my version doesn't want to work...

Can't you see the difference? You have a wrong comparison.

if (a && b < c) - you can't do that.

if (a<c && b<c) - that works

Reason: