Download MetaTrader 5

Calling a function from a subwindow indicator to populate fields

To add comments, please log in or register
gary0318
185
gary0318  

Hi.

I have created an indicator, that processes arrays that are in the main chart.

I have created a subwindow (a included resource of the indicator), which holds a dashboard type display of data that is derived from the main chart indicator buffers. This is the sole purpose of the subwindow.

Within the coding of the subwindow .mq5 file, is a declared function that receives all of the data required to populate the dashboard.

I am trying to figure out how to call that function from the main indicator .mq5 to send the data to the window for display WITHOUT USING GLOBAL VARIABLES.

Main indicator: GLP-SelectTrend.mq5

//+------------------------------------------------------------------+
//|                                              GLP-SelectTrend.mq5 |
//|                                              v7.0004             |
//|                                     Copyright 2017, Gary Pfeffer |

...

#resource "\\Indicators\\GLP-SelectTrend-DataWindow-0001.ex5"
//--- Location of the SubWindow indicator in the resource
string subwindow_path         ="::Indicators\\GLP-SelectTrend-DataWindow-0001.ex5";
int    subwindow_number       =-1;               // Subwindow number
int    subwindow_handle       =INVALID_HANDLE;   // SubWindow indicator handle
string subwindow_shortname    ="GLP-SelectTrend-DataWindow-0001";      // Short name of the indicator

Subwindow: GLP-SelectTrend-DataWindow-0001.mq5

//+------------------------------------------------------------------+
//|                                   GLP-SelectTrend-DataWindow.mq5 |
//|                                     Copyright 2017, Gary Pfeffer |

...

//+------------------------------------------------------------------+
//| Include files                                                    |
//+------------------------------------------------------------------+
#include <GLP-SelectTrend-Dialog.mqh>


Since the subwindow calls an .mqh....

//+------------------------------------------------------------------+
//|                                       GLP-SelectTrend-Dialog.mqh |
//|                                     Copyright 2017, Gary Pfeffer |

...

//  The subwindow dashboard is in this file...

// The function that I wish to call to populate the subwindow dashboard...

// How do I call this from the main indicator? Without using global variables?

   bool              UpdateTrendData(  int trend_direction_long,
                                       int trend_direction_intermediate,
                                       int trend_direction_short,
                                       int trend_direction_immediate,
                                       double _current_period_rate_long_term,
                                       double _prev_period_rate_long_term,
                                       double _current_period_rate_intermediate_term,
                                       double _prev_period_rate_intermediate_term,
                                       double _current_period_rate_short_term,
                                       double _prev_period_rate_short_term,
                                       double _current_period_rate_immediate_term,
                                       double _prev_period_rate_immediate_term,
                                       int _bull_count,
                                       int _bear_count );


Any ideas or answers would be greatly appreciated.
whroeder1
17063
whroeder1  
gary0318: I am trying to figure out how to call that function from the main indicator .mq5 to send the data to the window for display

You don't. The sub-window indicator pulls data from the main indicator buffers with iCustom.

gary0318
185
gary0318  
whroeder1:

You don't. The sub-window indicator pulls data from the main indicator buffers with iCustom.

Ok. The main indicator has 8 plotted buffers, and a separate array that I am using to hold 14 values that I must display in the subwindow indicator. I am looking at the iCustom documentation and having trouble figuring out how I would specify the buffer whose data I am after. I can't even see how to specify one of the plotted buffers. But, I actually need to get to my unplotted buffer, TrendData[].

Mladen Rakic
71708
Mladen Rakic  
gary0318:

Ok. The main indicator has 8 plotted buffers, and a separate array that I am using to hold 14 values that I must display in the subwindow indicator. I am looking at the iCustom documentation and having trouble figuring out how I would specify the buffer whose data I am after. I can't even see how to specify one of the plotted buffers. But, I actually need to get to my unplotted buffer, TrendData[].

Arrays are not reachable using iCustom()

You can retrieve the values from the buffers only

You can access the "unplotted" buffer though (just use the correct buffer number)
gary0318
185
gary0318  
Mladen Rakic:

Arrays are not reachable using iCustom()

You can retrieve the values from the buffers only

You can access the "unplotted" buffer though (just use the correct buffer number)

Geez. I was referring to my array as an unplotted buffer. It's actually not an indicator buffer. I am populating 14 values from what I have analyzed in the indicator buffers, and placing them in this array. There has to be a way to read this data from the main indicator and populate my dashboard. Am I missing something here? I don't think global variables will be feasible. Because, the same indicator will be used on a multitude of charts on the same terminal.

gary0318
185
gary0318  
gary0318:

Geez. I was referring to my array as an unplotted buffer. It's actually not an indicator buffer. I am populating 14 values from what I have analyzed in the indicator buffers, and placing them in this array. There has to be a way to read this data from the main indicator and populate my dashboard. Am I missing something here? I don't think global variables will be feasible. Because, the same indicator will be used on a multitude of charts on the same terminal.

BTW, thanks, so much for your helping me out. I've been away from programming too long, and a lot has changed.
gary0318
185
gary0318  
gary0318:
BTW, thanks, so much for your helping me out. I've been away from programming too long, and a lot has changed.
Could I just turn the array into a buffer by using setIndexbuffer to INDICATOR_CALCULATIONS and then populate the [0] through [13] with my data?
Mladen Rakic
71708
Mladen Rakic  
gary0318:

Geez. I was referring to my array as an unplotted buffer. It's actually not an indicator buffer. I am populating 14 values from what I have analyzed in the indicator buffers, and placing them in this array. There has to be a way to read this data from the main indicator and populate my dashboard. Am I missing something here? I don't think global variables will be feasible. Because, the same indicator will be used on a multitude of charts on the same terminal.

Simply declare them as buffers (not arrays) and then you can access them (after all we do not have the 8 buffer restriction any more :))

gary0318:
Could I just turn the array into a buffer by using setIndexbuffer to INDICATOR_CALCULATIONS and then populate the [0] through [13] with my data?
Yes, that is the way how you do that :)
gary0318
185
gary0318  

I have set up the TrendData buffer as follows in the main indicator

double         TrendData[];

int OnInit()
  {

 
   SetIndexBuffer(8,TrendData,INDICATOR_CALCULATIONS);
   ArrayResize(TrendData,14);
   ArrayInitialize(TrendData,EMPTY_VALUE);

...

In my Dashboard subwindow indicator, I have the following:

bool CPanelDialog::UpdateTrendData(){

     double   TrendDataBuffer[];
     int      TrendDataHandle;
     int      CopyBufferSize = 0;
   
     ArrayResize(TrendDataBuffer,14);
     ArrayInitialize(TrendDataBuffer,EMPTY_VALUE);
    
     TrendDataHandle = iCustom(NULL,NULL,"GLP-SelectTrend-7.0004.ex5",5);
     if(TrendDataHandle == -1){
         Alert("GLP-SelectTrend-7.0004.ex5 could not be accessed.");
     }
     CopyBufferSize =  CopyBuffer(TrendDataHandle,8,0,14,TrendDataBuffer);    

      if(CopyBufferSize > 0){
     
     
         for( int i =0 ; i < CopyBufferSize; i++){
               Alert("TrendDataBuffer[", i, "] = ", TrendDataBuffer[i]);
         }
...        
     



The buffer is accessible. The copy appears successful , as it returns the number of elements copied.

But, even though the buffer is definitely full of data, every element in the array comes back as 0.0.


I'm not sure what to make of this.

Mladen Rakic
71708
Mladen Rakic  
gary0318:

I have set up the TrendData buffer as follows in the main indicator

double         TrendData[];

int OnInit()
  {

 
   SetIndexBuffer(8,TrendData,INDICATOR_CALCULATIONS);
   ArrayResize(TrendData,14);
   ArrayInitialize(TrendData,EMPTY_VALUE);

...

In my Dashboard subwindow indicator, I have the following:

bool CPanelDialog::UpdateTrendData(){

     double   TrendDataBuffer[];
     int      TrendDataHandle;
     int      CopyBufferSize = 0;
   
     ArrayResize(TrendDataBuffer,14);
     ArrayInitialize(TrendDataBuffer,EMPTY_VALUE);
    
     TrendDataHandle = iCustom(NULL,NULL,"GLP-SelectTrend-7.0004.ex5",5);
     if(TrendDataHandle == -1){
         Alert("GLP-SelectTrend-7.0004.ex5 could not be accessed.");
     }
     CopyBufferSize =  CopyBuffer(TrendDataHandle,8,0,14,TrendDataBuffer);    

      if(CopyBufferSize > 0){
     
     
         for( int i =0 ; i < CopyBufferSize; i++){
               Alert("TrendDataBuffer[", i, "] = ", TrendDataBuffer[i]);
         }
...        
     



The buffer is accessible. The copy appears successful , as it returns the number of elements copied.

But, even though the buffer is definitely full of data, every element in the array comes back as 0.0.


I'm not sure what to make of this.

Don't do this (in the main indicator) :

 ArrayResize(TrendData,14);
MT manages the size of buffers (unlike arrays)
gary0318
185
gary0318  
Mladen Rakic:

Don't do this (in the main indicator) :

MT manages the size of buffers (unlike arrays)

When you pointed it out, I remembered that metatrader handles the buffers. I was quite hopeful. But, alas, it didn't help the issue at hand.


Thank, though. Much appreciated.

12
To add comments, please log in or register