Exposing Indicator Variables to EA using iCustom

 

Hi,

I am implimenting the Price Channel indicator in to an EA. The point i am struggling with is where you declare the Open and Close prices
to be either > or < the PC (price channel)

I can see where i am hitting a problem with my EA script, i am doing conditional testing on the Price channel, HOWEVER,
what i need to do is expose the individual topband and botband variables.

Using iCustom, can anyone explain how this is done?

Looking at other iCustom topics, i was thinking that i could use syntax symilar to

//---- get Price Channel
PC = iCustom(NULL,0,"Price Channel",topband,0,1);

from the errors i am getting this is clearly not the correct sysntax

So, thats my question really. How do you expose individual indicator variables to an EA ?
so that i can do conditional testing on topband[] and botband[]

many thanks for any constructive answers :-)
Nigel.

[ Below: This is a code snippet of the conditional block i am working with ]

//---- get Price Channel 
   PC = iCustom(NULL,0,"Price Channel",0,1);
 
//---- sell conditions
   if(Open[1]> PC && Close[1]< PC)  
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);
      return;
     }
     
//---- buy conditions 
   if(Open[1] < PC && Close[1] > PC)  
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);
      return;
     }
//----
 
nigelxx:

I can see where i am hitting a problem with my EA script, i am doing conditional testing on the Price channel, HOWEVER,
what i need to do is expose the individual topband and botband variables.

Using iCustom, can anyone explain how this is done?

   PC = iCustom(NULL,0,"Price Channel",0,1);
The highlighted parameter is the indicator buffer index starting from 0 in order the buffers are set in init() function, e.g.

double medianband[];
double topband[];
double botband[];
 
int init()
{
    SetIndexBuffer(0, medianband); // iCustom(NULL,0,"Price Channel",0,1)
    SetIndexBuffer(1, topband); // iCustom(NULL,0,"Price Channel",1,1)
    SetIndexBuffer(2, botband); // iCustom(NULL,0,"Price Channel",2,1)
 
    IndicatorBuffers(3);
    return (0);
}
 

Hi Irtron,

Many, many thanks to you. I have now managed to incorporate my custom Price Channel indicator in to an EA

AND i am able to interrogate the individual values of the variables from the custom indicator.
Your explaination is perfect !

with regards,
Nigel

For other peoples reference, here is the code in my EA >>

// this is a code snippet only of the CheckForClose() function which is in the EA.
 
   // declare variables
   double topband; 
   double botband; 
 
   // assign variables
   topband = iCustom(NULL,0,"Price Channel",0,1);
   botband = iCustom(NULL,0,"Price Channel",1,1);
 
   // and then do the conditional test accordingly.
   //---- check order type 
      if(OrderType()==OP_BUY)
      {
         // close out buy
       
         if(Open[1] > botband && Close[1] < botband) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
      }
Reason: