Download MetaTrader 5

iLow() or iClose() and String?

To add comments, please log in or register
fly7680
636
fly7680  

hello at all, it is possible to replace the ilow () function or iCLose () with a string?
I tried so but does not work:

extern string CloseHigh ="iLow"; // Switch iLow or iClose

CloseHigh(0,0,1)); //iLow(0,0,1)); or iClose(0,0,1));
honest_knave
Moderator
2326
honest_knave  
fly7680:

hello at all, it is possible to replace the ilow () function or iCLose () with a string?
I tried so but does not work:


Create a dropdown list:

enum functions
  {
   ILOW,  // iLow
   ICLOSE // iClose
  };
extern functions function = ILOW;


Then use a switch statement to use the correct function: 

   double value = 0;
   switch(function)
     {
      case ILOW:   value=iLow  (_Symbol,PERIOD_CURRENT,0); break;
      case ICLOSE: value=iClose(_Symbol,PERIOD_CURRENT,0); break;
     }
fly7680
636
fly7680  
honest_knave thanks, I will study this solution .. it was what I needed!!!!
fly7680
636
fly7680  
honest_knave hello, I entered the function, but unfortunately the switch does not work! The editor does not error. I display properly in external parameters function to change iLow or iClose but also changing iLow or iClose, the code reads only iLow.
honest_knave
Moderator
2326
honest_knave  
You'll need to post up your code so I can see how you implemented my code.
fly7680
636
fly7680  

I put in my condition in this way:

// Global scope
enum functions
  {
   ILOW,  // iLow
   ICLOSE // iClose
  };
extern functions function = ICLOSE;

//in OnCalculate
double value = 0;
   switch(function)
     {
      case ILOW:   value=iLow  (_Symbol,PERIOD_CURRENT,0); break;
      case ICLOSE: value=iClose(_Symbol,PERIOD_CURRENT,0); break;
     }


if(iOpen(0, 1+I) > iLow(_Symbol,PERIOD_CURRENT,3) && function < iLow(_Symbol,PERIOD_CURRENT,3))
whroeder1
15917
whroeder1  
fly7680: I entered the function, but unfortunately the switch does not work! The editor does not error. I display properly in external parameters function to change iLow or iClose but also changing iLow or iClose, the code reads only iLow.
if(iOpen(0, 1+I) > iLow(_Symbol,PERIOD_CURRENT,3) && function < iLow(_Symbol,PERIOD_CURRENT,3))
  1. Function is 0, 1, 2.. You use it in the switch. you want value < iLow.
  2. Alternate
    extern ENUM_SERIESMODE function = MODE_LOW;
    double get_price(int iBar){
       double a[]; ArrayCopySeries(a, function);
       return a[iBar];
    }


honest_knave
Moderator
2326
honest_knave  
fly7680:

I put in my condition in this way:


// Global scope
enum functions
  {
   ILOW,  // iLow
   ICLOSE // iClose
  };
extern functions function = ICLOSE;

//in OnCalculate
double value = 0;
   switch(function)
     {
      case ILOW:   value=iLow  (_Symbol,PERIOD_CURRENT,0); break;
      case ICLOSE: value=iClose(_Symbol,PERIOD_CURRENT,0); break;
     }


if(iOpen(0, 1+I) > iLow(_Symbol,PERIOD_CURRENT,3) && value < iLow(_Symbol,PERIOD_CURRENT,3))
fly7680
636
fly7680  
Excellent, now it works ...
Thanks again!!!!
honest_knave
Moderator
2326
honest_knave  
whroeder1:
  1. The switch is fine. Post your code (The enum, the external, the switch.) There are no mind-readers here.
  2. Alternate



Nice alternate.
To add comments, please log in or register