show your code
#property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Red //---- input parameters extern int AtrPeriod=14; //---- buffers double AtrBuffer[]; double TempBuffer[]; double MaBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; //---- 1 additional buffer used for counting. IndicatorBuffers(2); //---- indicator line SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,AtrBuffer); SetIndexBuffer(1,TempBuffer); SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(2,MaBuffer); //---- name for DataWindow and indicator subwindow label short_name="ATR("+AtrPeriod+")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name); //---- SetIndexDrawBegin(0,AtrPeriod); //---- return(0); } //+------------------------------------------------------------------+ //| Average True Range | //+------------------------------------------------------------------+ int start() { int i,counted_bars=IndicatorCounted(); //---- if(Bars<=AtrPeriod) return(0); //---- initial zero if(counted_bars<1) for(i=1;i<=AtrPeriod;i++) AtrBuffer[Bars-i]=0.0; //---- i=Bars-counted_bars-1; while(i>=0) { double high=High[i]; double low =Low[i]; if(i==Bars-1) TempBuffer[i]=high-low; else { double prevclose=Close[i+1]; TempBuffer[i]=MathMax(high,prevclose)-MathMin(low,prevclose); } i--; } //---- if(counted_bars>0) counted_bars--; int limit=Bars-counted_bars; for(i=0; i<limit; i++) AtrBuffer[i]=iMAOnArray(TempBuffer,Bars,AtrPeriod,0,MODE_SMA,i); //---- double MyArray[]; if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; ArrayResize( MyArray, limit); ArraySetAsSeries(MyArray,true); for(i=0; i<limit; i++) { MyArray[i] = AtrBuffer[i]; } for(i=0; i<limit; i++) { MaBuffer[i] = iMAOnArray(MyArray,limit,10,0,MODE_SMA,i); } //---- return(0); } //+------------------------------------------------------------------+
OK, you have 2 buffers
#property indicator_buffers 2
(or do you have 3 ?)
and 2 arrays . . . for arrays you need to declare them with a size or use ArrayResize
double TempBuffer[]; // <---- set a size or use use ArrayResize double MyArray[];
ArrayResize( MyArray, limit);
In the final part of code..
I have solved first problem..but now indicator don' t update live..anyone can help me?
#property copyright "" #property link "" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Blue //---- input parameters extern int BB_period = 20; extern int BB_std_deviation = 2; extern int MA_period = 20; //---- buffers double ExtMapBuffer1[]; //BollingerBandWidth double ExtMapBuffer2[]; //BandWidthSmoothing double Upper_Band; double Middle_Band; double Lower_Band; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- BollingerBandWidth SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, ExtMapBuffer1); SetIndexDrawBegin(0, BB_period); //---- BandWidthSmoothing SetIndexStyle(1, DRAW_LINE); SetIndexBuffer(1, ExtMapBuffer2); SetIndexDrawBegin(1, MA_period); return (0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { return (0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit; int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(int i=0; i<limit; i++) { //---- BollingerBand configuration Upper_Band = iBands(Symbol(), 0, BB_period, BB_std_deviation, 0, PRICE_CLOSE, MODE_UPPER, i); Middle_Band = iBands(Symbol(), 0, BB_period, BB_std_deviation, 0, PRICE_CLOSE, MODE_BASE, i); Lower_Band = iBands(Symbol(), 0, BB_period, BB_std_deviation, 0, PRICE_CLOSE, MODE_LOWER, i); //---- BollingerBandWidth configuration ExtMapBuffer1[i] = ((Upper_Band - Lower_Band) / Middle_Band) * 100.0; //---- BandWidthSmoothing configuration ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer1,0,MA_period ,0,MODE_SMA,i); } return (0); } //+------------------------------------------------------------------+
Does iMAOnArray work with Indicator buffers ?
Good..but when I insert indicator in chart..it loading until that time..and not next candle..don' t update itself..
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
Thanks