CCI alert

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
Hi all,
anyone tried to make an alarm at the cross of the zero line of the CCI for Metatrader5 ?
I want to create a alert but I do not know how it works: someone can 'help me?
Thanks.
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
You need to create a custom indicator that uses the standard CCI indicator. You need to check the current value of CCI and the previous value of CCI - if the current is >= 0, while the previous is < 0 then an alert should be issued. If the current value is < 0 and the previous value is >= 0 then an alert should be issued.
 

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
You need to create a custom indicator that uses the standard CCI indicator. You need to check the current value of CCI and the previous value of CCI - if the current is >= 0, while the previous is < 0 then an alert should be issued. If the current value is < 0 and the previous value is >= 0 then an alert should be issued.
Hi Enivid,
I created this code but I think there is any problem.
You can get an indication?
I'm not interested in seeing the ICC in chart, is important that alert only.
Thanks
#property indicator_chart_window
#property indicator_buffers 1


double CCI[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,CCI,INDICATOR_DATA);

//---
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
int limit;
int i;
int counted_bars=prev_calculated;
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=rates_total-counted_bars;
//---- cci counted in the buffer
CCI=iCCI(NULL,0,14,PRICE_CLOSE);
for(int i=0; i<limit; i--)
{
if ((CCI[i-1]<0)&&
(CCI[i-2]>0));
{
Alert ("TEST");
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
You can't do this in MT5:
CCI=iCCI(NULL,0,14,PRICE_CLOSE);

You have to get the indicator handle first and then copy its values into a buffer. Similar to this:

int myCCI = iCCI(NULL,0,14,PRICE_CLOSE);
if (CopyBuffer(myCCI, 0, 0, rates_total, CCI_Buffer) != rates_total) return(0);

You'll also want your OnCalculate() to run only on new bar openings - otherwise you'll get a lot of alerts after each cross.
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
You need to write the rates_total (amount of bars) into some global variable and check in OnCalculate() if the new rates_total is different from the old one. If it is, then remember a new amount and proceed to the rest of the function, otherwise return from the function.
 

intraforex

Active Trader
Jan 6, 2010
21
0
42
italy
I tried putting this function:
MQL5:
  for(int i=1;i<rates_total;i++)

is that correct?
I know very little programming .... I'm at the beginning....
Thanks
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
I tried putting this function:
MQL5:
  for(int i=1;i<rates_total;i++)

is that correct?
I know very little programming .... I'm at the beginning....
Thanks
No, that's just a cycle through all the chart bars (except for the very first one, with the number 0).

Look at some of my indicators here:
http://www.earnforex.com/metatrader-indicators

Look for variable LastBars and what's done with it.
 
Last edited:

Osbaldo

Trader
Feb 21, 2011
11
0
12
USA
Despite the bad press I have found them to be very good. Just stay away from numismatics and stick to bullion. When I last bought their margin above spot was very competative. The best part is that they a super professional. They are always in constant communication about your order. Highly trust worthy. Would use again.