Remaking the code shortly

To add comments, please log in or register
moonsky
487
moonsky  

Hi experts,

I 'd like to remake the following code shortly.

plz consider this


If(   High[1]>Low[1] and High[2]>Low[2] and High[3]>Low[3] and ..... High[x]>Low[x] )

A=True;


1.How to convert it to while loop or function based on x.

2. Can we replace High>Low to function,  If the algorithm has more complex than High > Low.


thank you very much

Keith Watford
Moderator
14427
Keith Watford  

Bit of a strange test as the high will almost certainly be larger than the low.

   int barsToCheck=10;
   bool result=true;
   for(int x=1;x<=barsToCheck;x++)
     {
      if(High[x]<=Low[x])
         result=false;
      break;
     }
Keith Watford
Moderator
14427
Keith Watford  

Using a function

   int barsToCheck=10;
   bool result=true;
   for(int x=1;x<=barsToCheck;x++)
     {
      result=Check(x);
      if(result==false)
         break;
     }


//+------------------------------------------------------------------+
bool Check(int x)
  {
   return(High[x]>Low[x]);
  }
//+------------------------------------------------------------------+
nicholi shen
2155
nicholi shen  

This might help... This is a pattern I use for p-hacking expressions with the optimizer. 


void OnStart()
{
   int x = 10;
   bool res = compare_arrays(High, GT, Low, 1, x);
}
//+------------------------------------------------------------------+

enum COMPARISON_OPS{LT, LTE, EQ, GTE, GT, ALWAYS_TRUE, ALWAYS_FALSE};

template <typename T>
bool compare(const T item1, const COMPARISON_OPS op, const T item2)
{
   switch(op){
      case ALWAYS_TRUE:
         return true;
      case LT:
         return item1 < item2;
      case LTE:
         return item1 <= item2;
      case EQ:
         return item1 == item2;
      case GTE:
         return item1 >= item2;
      case GT:
         return item1 > item2;
      default:
         return false;
   }
}

template <typename T>
bool compare_arrays(const T &array1[], 
                    const COMPARISON_OPS op, 
                    const T &array2[], 
                    const int start=0, 
                    const int count=WHOLE_ARRAY)
{
   int len = fmin(ArraySize(array1), ArraySize(array2));
   if(count != WHOLE_ARRAY)
      len = fmin(len, start + count);
   int i = len - 1;
   for(; i>=start; --i)
      if(!compare(array1[i], op, array2[i]))
         break;
   return i < start;
}
moonsky
487
moonsky  

@Keith Watford  Thank you , It's very clarify code

@nicholi shen  Thank for pattern, I have been trying to read this code,but still not understand it.

Could you tell me about P-hacking expression ? or leave introduction of it by link  .  

ffoorr
1151
ffoorr  
moonsky:

If(   High[1]>Low[1] and High[2]>Low[2] and High[3]>Low[3] and ..... High[x]>Low[x] )

should be something like that, no ?
If( High[i]>Low[i+x]  )


i = start  x = count   of function iHighest or iLowest

To add comments, please log in or register