How to pass structureArray in a Class method Call ? - page 2

 
Drazen Penic:

You can't "extract" double array from your struct array.

If you want to fill field Fastest in each struct in your array, you will have to declare helper array in your  function, fill that array with CopyBuffer and then copy those values into the struct array.

Something like this:

Code is not tested, but you should get the idea.

Hi Drazen

I have tried it and works well ...

It also gave me opportunity to Normalize the out values to a specified digits, which I was not able to do earlier in CopyBuffer().

bool Ci_VWMACD::Get_Data(int pBarCount,struct_VWMACD &pVWMACD[])
  {
    if(m_Handle == INVALID_HANDLE)
      Init_Handle();
  //--- Array to be filled and returned with Volume Weighted MACD values
    double  pMACDOsMA[], pMACDMain[], pMACDSignal[];
    ArrayResize(pMACDOsMA,pBarCount+1);
    ArrayResize(pMACDMain,pBarCount+1);
    ArrayResize(pMACDSignal,pBarCount+1);
    ArraySetAsSeries(pMACDOsMA,true);
    ArraySetAsSeries(pMACDMain,true);
    ArraySetAsSeries(pMACDSignal,true);
  //--- Copy Buffer values from Custom Indicator "iFx VWMACD"
    ResetLastError();
    if(!CopyBuffer(m_Handle,0,m_BarStart,pBarCount,pMACDOsMA) ||
       !CopyBuffer(m_Handle,2,m_BarStart,pBarCount,pMACDMain) ||
       !CopyBuffer(m_Handle,3,m_BarStart,pBarCount,pMACDSignal))
      {
        Print(__FUNCTION__,": FAILED Copy Buffers from Ci_VWMACD handle. Error Code ",GetLastError());
        return(false);
      }
  //--- XXXX
    ArrayResize(pVWMACD,pBarCount+1);
    ArraySetAsSeries(pVWMACD,true);
    for(int i = m_BarStart; i < pBarCount; i++)
      {
        pVWMACD[i].OsMA   = NormalizeDouble(tempOsMA[i],5);
        pVWMACD[i].Main   = NormalizeDouble(tempMain[i],5);
        pVWMACD[i].Signal = NormalizeDouble(tempSignal[i],5);
      }
    ArrayFree(pMACDOsMA);
    ArrayFree(pMACDMain);
    ArrayFree(pMACDSignal);
  //---
    return(true);
  } // END Of Get_Data() method
 
Anil Varma -:

Hi Drazen

I have tried it and works well ...

Yes, but you should think about Alain's suggestion because you now use CopyBuffer to copy data into temporary arrays, and then you copy that data into array of struct - you move the same data two times.

Measure the performance. If it is slow, then consider struct of arrays that Alain suggested. 

Reason: