How to access other indicators in custom indicator?

 

Hi guys,

I'm new here and have a beginner's question:

I try to create a custom indicator which will set symbols above my bars to signals me to buy or to sell. This indicator should access other indicators (exponential MA 3 and 7) and signal me if the EMA 3 is above or below the EMA 7. How can I access the results of other (built-in) indicators in my own custom indicator? 

This is my (reduced) OnCalculate method:

int OnCalculate(const int rates_total, const int prev_calculated, ...)
  {
   //--- Block for calculating indicator values
   int start=1;
   if(prev_calculated>0) start=prev_calculated-1;
   //--- Calculation loop
   for(int i=1;i<rates_total;i++)
     {
        // How to access and compare EMA 3 and 7 of the current bar here?
     
     

Thanks in advance! 

 

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.
 
FxPredator:

Hi guys,

I'm new here and have a beginner's question:

I try to create a custom indicator which will set symbols above my bars to signals me to buy or to sell. This indicator should access other indicators (exponential MA 3 and 7) and signal me if the EMA 3 is above or below the EMA 7. How can I access the results of other (built-in) indicators in my own custom indicator? 

This is my (reduced) OnCalculate method:

Thanks in advance! 

 

It's time to read a little ;-)
 

Great, thank you, that was exactly the article I was looking for (didn't find it before).

Thanks to the information provided I was able to build it but stumbled over a little problem:

In the OnCalculation method the price in close[i], open[i], high[i] and low[i] is always the same for every loop over the rates.

What am I doing wrong? 

 

 
FxPredator:

Great, thank you, that was exactly the article I was looking for (didn't find it before).

Thanks to the information provided I was able to build it but stumbled over a little problem:

In the OnCalculation method the price in close[i], open[i], high[i] and low[i] is always the same for every loop over the rates.

What am I doing wrong? 

Difficult to guess. You have to show your code if you need help.
 

I reduced the code as much as I could to keep it simple, I just want to check if the close price is below the open price: 

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

//--- Block for calculating indicator values
   int start=1;
   if(prev_calculated>0) start=prev_calculated-1;
   
//--- Calculation loop
   for(int i=start;i<rates_total;i++)
     {

      bool isRedCandle = close[i]<open[i];
      MarkBuffer[i]=isRedCandle ? high[i]: 0;

But the close, open, high and low prices are always the same when I run the debug mode and step through the loop.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
 
FxPredator:

I reduced the code as much as I could to keep it simple, I just want to check if the close price is below the open price: 

But the close, open, high and low prices are always the same when I run the debug mode and step through the loop.

See if reading this help you.
 
Actually no, it doesn't, sorry. I have no idea why the prices are the same in all arrays (same slot).
 
FxPredator:
Actually no, it doesn't, sorry. I have no idea why the prices are the same in all arrays (same slot).
I can't help you with a snippet of code. If you provide a code that compile I can try to run it and find the problem.
Reason: