if(counted_bars > 0) counted_bars--; if (barsCount > 0) limit = MathMin(Bars - counted_bars,barsCount); else limit = Bars - counted_bars;
Contradictory information on IndicatorCounted() - MQL4 forum Drop the decrement, drop the testlimit = Bars - counted_bars;
for(int i = 0; i < limit; i++) bbCCI[i] = iCCI(NULL,0,CCILen,PRICE_TYPICAL,0);
cci(i) not cci(0)- Always count down. Then you can combine the loops.
double bbCCI[]; double avgCCI[];
The first is not a buffer. The second one is. Look at init()
WHRoeder Thank you very much for your very prompt ansewer. An accident kept me away from home sincd ee I had to stay in hospital.
It seems I am stupid I could not understand and fix all the problems in my coding. I changed a little the code but still there are errors. I am not programmer but try to learn it.
What I have done, was copied from someone other's indicator.
I would appreciate any help from you or any other guy. I would be very obliged. Once more thank you for your help.
//+------------------------------------------------------------------+ //| Custom BB_CCI.mq4 | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2013, adoleh2000" #property link "http://www.metaquotes.net/" //---- indicator settings #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Red //Upperband #property indicator_color2 Green //Lowerband //---- indicator parameters extern int CCILen = 14; extern int BBLen = 20; extern int barsCount = 200; extern double StDv = 1.5; //---- indicator buffers double Upperband[]; // Upperband Line double Lowerband[]; // Lowerband Line //---- buffers double bbCCI[]; double avgCCI[]; double sDev; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 2 additional buffers are used for counting. IndicatorBuffers(4); //---- drawing settings SetIndexBuffer(0, Upperband); // Upperband line SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1); IndicatorDigits(Digits + 1); SetIndexLabel(0, "Upperband"); //---- SetIndexBuffer(1, Lowerband); // Lowerband line SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 1); IndicatorDigits(Digits + 1); SetIndexLabel(1, "Lowerband"); SetIndexBuffer(2, avgCCI); SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 1); SetIndexBuffer(3, bbCCI); //---- name for DataWindow and indicator subwindow label IndicatorShortName("BB on CCI(" + CCILen + "," + BBLen + ")"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+------------------------------------------------------------------+ //| Custom BB_CCI | //+------------------------------------------------------------------+ int start() { int limit; int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; if (barsCount > 0) limit = MathMin(Bars - counted_bars,barsCount); limit = Bars - counted_bars; //---- for(int i = 0; i < limit; i++) bbCCI[i] = iCCI(NULL,0,CCILen,PRICE_TYPICAL,0); //---- //---- for(i = 0; i < limit; i++) { avgCCI[i] = iMAOnArray(bbCCI, 0, BBLen, 0, MODE_SMA, i); sDev = iStdDevOnArray(bbCCI, 0, BBLen, MODE_SMA, 0, i); Upperband[i] = avgCCI[i] + (StDv * sDev); Lowerband[i] = avgCCI[i] - (StDv * sDev); } return(0); } //+------------------------------------------------------------------
for(int i = 0; i < limit; i++) bbCCI[i] = iCCI(NULL,0,CCILen,PRICE_TYPICAL,0);Why are you filling an array with the same value?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I want to create an indicator that draws Bollinger Bands on CCI. I know I can drag the bands from Navigator window but I need it as indicator for use in EA's.
I tried to code it but since I am newbie, no result. Could you tell me what is wrong in my code?
Thanks for your help.