Code EA based on Indicator code

 

Hello,

Can anybody tell me how to write a EA code based on Indicator code?

I have spent several hours however I am not getting the same numbers.........

iBuff01[0] is the value which needs to be calculated for each tick and compared to another value.


I would appreciate any help.

Thank you.


#property indicator_separate_window
#property indicator_levelcolor White
#property indicator_levelstyle 0
#property indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_width1 1
#property indicator_level1 50.0

double iBuff01[];
double iBuff02[1];
int iPeriod = 14;


int init() 
{
  IndicatorBuffers(1);
  SetIndexStyle(0, DRAW_LINE);
  SetIndexBuffer(0, iBuff01);
  IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 2.0);
  IndicatorShortName("Ind1");
  return (0);
}

int deinit() 
{
  return (0);
}

int start() {
   int iArrSize;
   int iIndCount = IndicatorCounted();
   if (iIndCount < 0) return (-1);
   if (iIndCount > 0) iIndCount--;
   int iLimit = Bars - iIndCount;
   if (Bars <= iPeriod) return (0);
   if (ArraySize(iBuff02) != ArraySize(iBuff01)) 
   {
    iArrSize = ArraySize(iBuff01);
    ArraySetAsSeries(iBuff02, FALSE);
    ArrayResize(iBuff02, iArrSize);
    ArraySetAsSeries(iBuff02, TRUE);
   }

   for (int i = 0; i < iLimit; i++) iBuff02[i] = iRSI(NULL, 0, 14, PRICE_CLOSE, i);
   for (i = 0; i < iLimit; i++) iBuff01[i] = iMAOnArray(iBuff02, 0, 5, 0, MODE_EMA, i);
   
   return (0);
}
 

draho wrote:

Hello,

Can anybody tell me how to write a EA code based on Indicator code?

I have spent several hours however I am not getting the same numbers.........

iBuff01[0] is the value which needs to be calculated for each tick and compared to another value.


I would appreciate any help.

Thank you.


I think you may be looking for the iCustom function. That function allows a MQL4 program to retrieve values from another MQL4 indicator. By using that you do not have to replicate the indicator code in the EA, rather you just need to remember to take the referenced indicator file along with the EA and time you copy the EA to another computer.

Reason: