Is there a way to use data structure as 'Indicator Buffer" ?

 

Wish all happy beginning of the week.

I have following structure and want to use its information in the Indicator Buffer(s). To my understanding indicator buffers are allowed only of 'double' type.

Is there any work around to what I want to achieve?

struct SFxSession {
        CENUM_FxSESSION_ID      SessionID;
        datetime                                                Begin;   // FxSession time begin in broker's time
        datetime                                                End;     // FxSession time end   in broker's time
};
 

You are right, buffers can only be of 'double' type.

In your case you should use 3 buffers converting your struct values to double.

 
Try declaring a public double array as part of the struct and Setting it as indicator buffer? Not sure it works though.
 
Fabio Cavalloni #:

You are right, buffers can only be of 'double' type.

In your case you should use 3 buffers converting your struct values to double.

datetime can be used as 'double' ?

 
Anil Varma #:

datetime can be used as 'double' ?

datetime to ulong to double
 
Sardion Maranatha #:
datetime to ulong to double

Thanks Sardion :) Will give it a try

 
Anil Varma:

Let me rephrase the original question as below.

If I use the above structure as it is in the indicator without defining it as Indicator Buffer.

How can I retrieve its values in an EA or OOP Class?

As I assume CopyBuffer() should work only on indicator buffer(s).
 
Tobias Johannes Zimmer #:
Try declaring a public double array as part of the struct and Setting it as indicator buffer? Not sure it works though.

Hi Tobias

Below is the CopyBuffer() as per documentation.

int  CopyBuffer(
   int       indicator_handle,     // indicator handle
   int       buffer_num,           // indicator buffer number
   int       start_pos,            // start position
   int       count,                // amount to copy
   double    buffer[]              // target array to copy
   );

You can see it requires a double buffer[], so anything else will not work.

 
Anil Varma #:

Hi Tobias

Below is the CopyBuffer() as per documentation.

You can see it requires a double buffer[], so anything else will not work.

struct SBuf
  {
   int               handle;
   double            buf[];
   
   SBuf():handle(INVALID_HANDLE){;}
  };
  
SBuf bufStruct;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   bufStruct.handle = iMomentum(_Symbol, _Period, 7, PRICE_TYPICAL);
//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   CopyBuffer(bufStruct.handle, 0, 0, 10, bufStruct.buf);
   
   for(int i=0;i<ArraySize(bufStruct.buf);i++)
     {
      PrintFormat("buf[%d] = %g",i,bufStruct.buf[i]);
     }
  }
//+------------------------------------------------------------------+

Can this be of use to you?

 
Tobias Johannes Zimmer #:

Can this be of use to you?

Thanks @Tobias Johannes Zimmer

This is an interesting idea when one wants to use another indicator data into an indicator. However same results will be achieved without using the 'structure array'.

In my case the multiple values are calculated within the indicator and they are related (linked) to a particular bar index. e.g. three values of Pivot Range Top Central, Pivot Range Point and Pivot Range Bottom Central are linked to daily bar index.

Now I will be running this indicator on intraday chart(s) so it will have many bars which correspond to a single day.

It is bit more complex issue than just what you think. Anyways THANKS A LOT for your efforts and consideration.

Regards

Reason: