How to detect the source when a custom indicator is called?

 

Hi all. 

 

I have searched this site for several day’s but I can’t find an answer for his problem.

Is it possible to check the source of the call (EA or Chart) of a custom indicator from within the code of that custom indicator?

There are two possibilities:

1e: The indicator has been called from the EA with the iCustom()/IndicatorCreate() functions.

2e: The indicator has been called when it is attached to the chart and the chart is updated with new tick data.

I have designed a custom indicator which contained 6 signal lines and some additional information which is stored in a separate indicator buffer. This additional data is only needed when the custom indicator is called by the EA, This extra data is useless when the indicator is attached to a chart because it’s for visual purposes only. So in that case, the calculation of this extra data can be disabled.

Is this approach possible in MQL5?

Please help.

Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • 2009.11.23
  • Андрей
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
 

Hi,

I found this trick while I was playing in mq5:

On your OnInit code of your indicator try this piece of code:

int OnInit()
{
   //Assume your indicator name is "SSK"
   if(ChartIndicatorGet(0,0,"SSK")>-1)
   {
      Alert("I'm placed by the user on the chart.");
   }
   else
   {
      Alert("I'm called by iCustom function with an EA.");
   }
....
   


 
I do not understand your question.
 
hoan:
I do not understand your question.

The question is: How can you detect, who is calling/using the custom indicator? 

An indicator can be called/used in two way's:

1e: The EA with the iCustom()/IndicatorCreate() functions.  

2e: When you attach the indicator to the chart and the chart is updated with new ticks. 

 

When you know this information, you can make the calculation of the indicator more efficient because,

when you attach the indicator to the chart, the indicator disables automatically the parts of the code that are only used by the EA.

 

I hope this makes sense.

 
codersguru:

Hi,

I found this trick while I was playing in mq5:

On your OnInit code of your indicator try this piece of code:

Hi codersguru.

 

Thanks for your reply. I have added your code to my indicator.

Tomorrow, I can test if it works.  

 
snelle_moda:

 

Hi all. 

 

I have searched this site for several day’s but I can’t find an answer for his problem.

Is it possible to check the source of the call (EA or Chart) of a custom indicator from within the code of that custom indicator?

There are two possibilities:

1e: The indicator has been called from the EA with the iCustom()/IndicatorCreate() functions.

2e: The indicator has been called when it is attached to the chart and the chart is updated with new tick data.

I have designed a custom indicator which contained 6 signal lines and some additional information which is stored in a separate indicator buffer. This additional data is only needed when the custom indicator is called by the EA, This extra data is useless when the indicator is attached to a chart because it’s for visual purposes only. So in that case, the calculation of this extra data can be disabled.

Is this approach possible in MQL5?

Please help.

Actually, you can use iCustom with those 6 signal lines and so you don't need "some additional information which is stored in a separate indicator buffer".

Can we see the code in OnInit() ? and please use SRC button to post the code.

 

 
phi.nuts:

Actually, you can use iCustom with those 6 signal lines and so you don't need "some additional information which is stored in a separate indicator buffer".

Can we see the code in OnInit() ? and please use SRC button to post the code.

 

Hi.

Here is the OnInit() part of the code. 

 

int OnInit()
   {

// Indicator buffers mapping.
   SetIndexBuffer(0,  LTerm_UpperLine,                   INDICATOR_DATA);
   SetIndexBuffer(1,  LTerm_LowerLine,                   INDICATOR_DATA);
   SetIndexBuffer(2,  STerm_UpperLine,                   INDICATOR_DATA);   
   SetIndexBuffer(3,  STerm_LowerLine,                   INDICATOR_DATA);
   SetIndexBuffer(4,  DAY_UpperLine,                     INDICATOR_DATA);   
   SetIndexBuffer(5,  DAY_LowerLine,                     INDICATOR_DATA);
   SetIndexBuffer(6,  LTerm_RecentIndicatorSupportData,  INDICATOR_CALCULATIONS);     

// Punten berekening.
   PipFactor = Factor(); 

// Interval tijdframe van de chart. 
   nChartTimeFrame = Period();

   return(0);
   }
 
codersguru:

Hi,

I found this trick while I was playing in mq5:

On your OnInit code of your indicator try this piece of code:

int OnInit()
{
   //Assume your indicator name is "SSK"
   if(ChartIndicatorGet(0,0,"SSK")>-1)
   {
      Alert("I'm placed by the user on the chart.");
   }
   else
   {
      Alert("I'm called by iCustom function with an EA.");
   }
....
   

Hi.

This method works when only the EA is attached to the chart. When both the EA and custom indicator are attached to the same chart, the call from the EA for the custom indicator is no longer recognized. 

 
snelle_moda:

 

Hi all. 

 

I have searched this site for several day’s but I can’t find an answer for his problem.

Is it possible to check the source of the call (EA or Chart) of a custom indicator from within the code of that custom indicator?

There are two possibilities:

1e: The indicator has been called from the EA with the iCustom()/IndicatorCreate() functions.

2e: The indicator has been called when it is attached to the chart and the chart is updated with new tick data.

I have designed a custom indicator which contained 6 signal lines and some additional information which is stored in a separate indicator buffer. This additional data is only needed when the custom indicator is called by the EA, This extra data is useless when the indicator is attached to a chart because it’s for visual purposes only. So in that case, the calculation of this extra data can be disabled.

Is this approach possible in MQL5?

Please help.

you could have two versions of the indicators  IndChart and IndEA   and in the Chart version just not calculate the extra data, which I assume is what you are trying to resolve.
 

MaxTrader:
you could have two versions of the indicators  IndChart and IndEA   and in the Chart version just not calculate the extra data, which I assume is what you are trying to resolve.

 

Hi.

You're right, I can make two versions of the indicator but this solution is not desirable. I hope it can be programmed in an "convenient way". 

If this is not possible, I'm gonna make two versions of my custom indicator.  

 

snelle_moda:

Hi.

Here is the OnInit() part of the code.  


You could do this actually,

input bool Use_this_buffer = false;

int OnInit()
  {
  if (Use_This_buffer == true)  SetIndexBuffer(6,  LTerm_RecentIndicatorSupportData,  INDICATOR_CALCULATIONS);   


  }

Anyway, from that 7 buffers you show, which one you don't want to use and where does this buffer get the data ( say for example the data you don't want to use is buffer 6 which get the data from buffer 0) ?

 

Reason: