how to expose hidden arrow objects from custom indicator in chart's objects list - page 2

To add comments, please log in or register
Vladimir Karputov
Moderator
208133
Vladimir Karputov  
Jackery :

Okay. Please how do I access the arrow objects in an EA?

Use CopyBuffer - just indicate the indicator buffer number (the indication of buffers starts from '0').

Jackery
212
Jackery  
Vladimir Karputov:

Use CopyBuffer - just indicate the indicator buffer number (the indication of buffers starts from '0').

I did that, please see code below. But that gives me MA values. How will I use the CopyBuffer for objects?


double      MA[];             
int         MA_handle;   
 
 
 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
 
 
  MA_handle=iCustom(NULL,PERIOD_M1,"MyTrendIndicator");
 
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
 
   CopyBuffer(MA_handle,0,0,3,MA);
 
   ArraySetAsSeries(MA,true);  
 
 
Print( "h MA[1]: "+MA[1]);
 
 
   }
Vladimir Karputov
Moderator
208133
Vladimir Karputov  
Jackery :

I did that, please see code below. But that gives me MA values. How will I use the CopyBuffer for objects?


There are no objects when using the 'DRAW_ARROW' style. There is only an indicator buffer.

Work with the indicator buffer - using 'CopyBuffer' receive data from the indicator buffer and check the received value.


Also I recommend: first write a simple indicator based on the 'DRAW_ARROW' style. Then the advisor.

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
  • www.mql5.com
Some technical indicators have several buffers drawn in the chart. Numbering of indicator buffers starts with 0. When copying indicator values using the CopyBuffer() function into an array of the double type, for some indicators one may indicate the identifier of a copied buffer instead of its number.
Jackery
212
Jackery  
Vladimir Karputov:

There are no objects when using the 'DRAW_ARROW' style. There is only an indicator buffer.

Work with the indicator buffer - using 'CopyBuffer' receive data from the indicator buffer and check the received value.


Also I recommend: first write a simple indicator based on the 'DRAW_ARROW' style. Then the advisor.


I updated  my code to check the CopyBuffer() value, but the value always equal to the CopyBuffer() count parameter. For example in the updated code below, the count is 123 and the CopyBuffer() value is also 123 regardless of the timeframe.


double      MA[];             
int         MA_handle;   



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {

  
  MA_handle=iCustom(NULL,PERIOD_M15,"MyTrendIndicator");

   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

   ArraySetAsSeries(MA,true); 
   int cBufValue = CopyBuffer(MA_handle,0,0,123,MA);

    Print( "buffer value for M15 is: "+cBufValue);
   


   }
Vladimir Karputov
Moderator
208133
Vladimir Karputov  
Jackery :


I updated  my code to check the CopyBuffer() value, but the value always equal to the CopyBuffer() count parameter. For example in the updated code below, the count is 123 and the CopyBuffer() value is also 123 regardless of the timeframe.


Please read the help carefullyCopyBuffer

Return Value

Returns the copied data count or -1 in case of an error.

CopyBuffer copies data INTO ARRAY. Now you need to print any value from the array (for example, the value MA [0])

Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
  • www.mql5.com
Counting of elements of copied data (indicator buffer with the index buffer_num) from the starting position is performed from the present to the past, i.e., starting position of 0 means the current bar (indicator value for the current bar). When copying the yet unknown amount of data, it is recommended to use a dynamic array as a buffer[]...
12
To add comments, please log in or register