Is there a way to refer to open, high, low or close buffers in a void function?

 

Hello everybody, I was working with MovingAverages.mqh when I saw that I also wanted a function to get the applied price. With the median, typical and weighted it seemed within good measure to store the results in a &dst_buffer[]. But it bothered me to do it with open, high, low and close because it seemed redundant to copy them (which ArrayInsert does). Why should I insert them when they are already existing. So the question is how can I reference &open[] etc. through &dst_buffer[] without copying them again?

void GetAppliedPrice(ENUM_APPLIED_PRICE PriceApplied,
                     const double &open_buffer[],
                     const double &high_buffer[],
                     const double &low_buffer[],
                     const double &close_buffer[],
                     double &dst_buffer[]) { // destination array
   switch(PriceApplied) {

   case PRICE_OPEN :
      ArrayInsert(dst_buffer, open_buffer, 0, 0, WHOLE_ARRAY); // it feels redundant to copy these since they are in oncalculate...
      break;

   case PRICE_HIGH :
      ArrayInsert(dst_buffer, high_buffer, 0, 0, WHOLE_ARRAY);
      break;

   case PRICE_LOW :
      ArrayInsert(dst_buffer, low_buffer, 0, 0, WHOLE_ARRAY);
      break;

   case PRICE_CLOSE :
      ArrayInsert(dst_buffer, close_buffer, 0, 0, WHOLE_ARRAY);
      break;


   case PRICE_MEDIAN :
      for(int i = 0; i < ArraySize(high_buffer); i++) {
         dst_buffer[i] = (high_buffer[i] + low_buffer[i]) / 2;
      }
      break;

   case PRICE_TYPICAL :
      for(int i = 0; i < ArraySize(high_buffer); i++) {
         dst_buffer[i] = (high_buffer[i] + low_buffer[i] + close_buffer[i]) / 3;
      }
      break;

   case PRICE_WEIGHTED :
      for(int i = 0; i < ArraySize(high_buffer); i++) {
         dst_buffer[i] = (high_buffer[i] + low_buffer[i] + (close_buffer[i] * 2)) / 4;
      }
      break;
   }
}
 
Tobias Johannes Zimmer: So the question is how can I reference &open[] etc. through &dst_buffer[] without copying them again?
You can't, dst_buffer does not have values. Stop using it, and access the values directly.
   case PRICE_MEDIAN :
      for(int i = 0; i < ArraySize(high_buffer); i++) {
         dst_buffer[i] = (high_buffer[i] + low_buffer[i]) / 2;
      }
      break;
 

Okay thank you.

Edit: here you go:

//+---------------------------------------------------------------------------+
//| Function to get the applied price in a particular position of price buffer|
//+---------------------------------------------------------------------------+
double GetPositionAppliedPrice(ENUM_APPLIED_PRICE PriceApplied,
                               const double &open_buffer[],
                               const double &high_buffer[],
                               const double &low_buffer[],
                               const double &close_buffer[],
                               const int &pos)
  {
   double result = 0.0;
   switch(PriceApplied)
     {

      case PRICE_OPEN :
         result = (open_buffer[pos]);
         break;

      case PRICE_HIGH :
         result = (high_buffer[pos]);
         break;

      case PRICE_LOW :
         result = (low_buffer[pos]);
         break;

      case PRICE_CLOSE :
         result = (close_buffer[pos]);
         break;

      case PRICE_MEDIAN :
         result = ((high_buffer[pos] + low_buffer[pos]) / 2);
         break;

      case PRICE_TYPICAL :
         result = ((high_buffer[pos] + low_buffer[pos] + close_buffer[pos]) / 3);
         break;

      case PRICE_WEIGHTED :
         result = ((high_buffer[pos] + low_buffer[pos] + (close_buffer[pos] * 2)) / 4);
         break;
     }
     return(result);
  }
//+------------------------------------------------------------------+
Reason: