how to add indicator code into expertadvisor code ?? - page 3

 
i wish to add some filter on my ea, what should i do ??
 

hi, i have some trouble here... ~~

i wish to make a new ea with rvi indicator,

but seem i have big mistake.

even i looked at to this page https://www.mql5.com/en/articles/1456,

but still have problem.

here is the code i do.

anyone can please lend me a hand to make this easy ea ??

//+------------------------------------------------------------------+
//|                                                       RVI EA.mq4 |
//|                                             Copyright 2012, Abu. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, Abu."
#property link      "http://www.metaquotes.net"

//--- input parameters
extern double    TakeProfit=100.0;
extern double    StopLoss=100.0;
extern int       TotalOrder=10;
extern double    FixedLotSize=0.1;
extern double    FlexibleLotSize=0.1;
extern double    RVIPeriod=5;
//---- indicator buffers
double     ExtRVIBuffer[];
double     ExtRVISignalBuffer[];
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   if(AccountFreeMargin()<200)        //----
   {
   Print("Margin is lesser than 200");   //----
   return(0);
   for (int i=100; i<TotalOrder(); i++) {
   if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
   if (OrderSymbol()==Symbol()) {
   return(True);
   }
   } 
   } 
   return(false);
   }

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   int i,j,nLimit,CountedBars;
   double dValueUp,dValueDown,dNum,dDeNum;
//----
   if(Bars<=RVIPeriod+8) return(0);
//----
   CountedBars=IndicatorCounted();
//---- check for possible errors
   if(CountedBars<0) return(-1);
//---- last counted bar will be recounted
   Limit=Bars-RVIPeriod-4;
   if(CountedBars>RVIPeriod+4)
      Limit=Bars-CountedBars;
//---- RVI counted in the 1-st buffer
   for(int i = limit); i >= 1; i--
     {
      dNum=0.0; 
      dDeNum=0.0;
   for(int j=i; j<i+RVIPeriod; j++)
        {
         dValueUp=((Close[j]-Open[j])+2*(Close[j+1]-Open[j+1])+2*(Close[j+2]-Open[j+2])+(Close[j+3]-Open[j+3]))/6;
         dValueDown=((High[j]-Low[j])+2*(High[j+1]-Low[j+1])+2*(High[j+2]-Low[j+2])+(High[j+3]-Low[j+3]))/6;
         dNum+=dValueUp;
         dDeNum+=dValueDown;
        }
      if(dDeNum!=0.0)
         ExtRVIBuffer[i]=dNum/dDeNum;
      else
         ExtRVIBuffer[i]=dNum;   
     }

//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
   int start()
    {
      if ((i<j));
      {
         OpenSell();
         return(0);
      }
      else 
      
      if ((j<i));
      {
         OpenBuy();
         return(0);
      }
      else  
 //----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

You can NOT use Indicator buffers or other Indicator functions such as IndicatorCounted() in an EA. Create an Indicator, access the Indicators buffers from your EA using iCustom. You could also simply use the iRVI function that mql4 offers . . .

init() is for code that you want to run once when your EA starts, deinit() is for code you want to run once when your EA is closed down . . . start() is for code you want to run on each tick . . .

 

how to know the highest and the lowest of candle of any timeflame ..

 
how to define the lowest bar or highest bar ??
 
how to defined ExtDepth and shift on ea ??
 
   int a, b;
   double zag, zig; b=0; while(a<2) {
   if(zig>0) zag=zig;
   zig=iCustom(NULL, 0, "ZigZag", 0, b);
   if(zig>0) a+=1;
   b++;
   ZigZagHigh=iCustom(NULL,0,"ZigZag",MODE_HIGH,0);
   ZigZagLow=iCustom(NULL,0,"ZigZag",MODE_LOW,0);    
   double LowestBar=Low[Lowest(NULL,0,MODE_LOW,ExtDepth,shift)];
   double HighestBar=High[Highest(NULL,0,MODE_HIGH,ExtDepth,shift)];

as above, i wish to defined a= highest price of candle

and b=lowest price of candle

trying to add zigzag indicator into my EA.

but still variable not defined.

how to fix these error ??

 
Have a read of this thread: https://www.mql5.com/en/forum/139051/page2#623895 the principles are the same.
 
albert_lim83:

as above, i wish to defined a= highest price of candle

and b=lowest price of candle

trying to add zigzag indicator into my EA.

but still variable not defined.

how to fix these error ??

Did you declare ZigZagHigh, ZigZagLow and ExtDepth ?

iHighest and iLowest return the number of the bar that is the Highest/Lowest . . . an they look at bars starting with shift and by looking at ExDepth bars . . .

 

finally done the variable problem,

now is only

( - function definition unexpected

) - unbalanced right parenthesis...

is it l left put ( and ) on my code??

Reason: