Your question is a bit vague...
See ArraySetAsSeries() -- sometimes that is needed to align "your" array data with the indicator buffer data
If you are using indicator buffer data for calculations, make two loops... one to collect the indicator buffer data, and another loop to act upon it. The indicator buffer data seems to not always be "complete" during the first pass.
Your question is a bit vague...
See ArraySetAsSeries() -- sometimes that is needed to align "your" array data with the indicator buffer data
If you are using indicator buffer data for calculations, make two loops... one to collect the indicator buffer data, and another loop to act upon it. The indicator buffer data seems to not always be "complete" during the first pass.
I'll give you an example. The first code works. The second doesn't. The only difference between them is: I took out the follow part
SetIndexStyle(2, DRAW_NONE); SetIndexBuffer(2,ExtMapBuffer3); SetIndexStyle(3, DRAW_NONE); SetIndexBuffer(3,ExtMapBuffer4); SetIndexStyle(4, DRAW_NONE); SetIndexBuffer(4,ExtMapBuffer5); SetIndexStyle(5, DRAW_NONE); SetIndexBuffer(5,ExtMapBuffer6);
First Code:
//+------------------------------------------------------------------+ //| Acima_Abaixo_AccelarationBands.mq4 | //| | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "**" #property link "**" #property indicator_separate_window #property indicator_minimum -1 #property indicator_maximum +1 #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Green //---- input parameters extern double Factor=2;// extern int smPeriod=15;// extern int smMethod=1;// 0 - SMA, 1 - EMA, 2 - SMMA, 3 - LWMA //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[]; double ExtMapBuffer5[]; double ExtMapBuffer6[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(6); //--- Plot a line SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); SetIndexStyle(1, DRAW_LINE); SetIndexBuffer(1,ExtMapBuffer2); //--- Internal Variables SetIndexStyle(2, DRAW_NONE); SetIndexBuffer(2,ExtMapBuffer3); SetIndexStyle(3, DRAW_NONE); SetIndexBuffer(3,ExtMapBuffer4); SetIndexStyle(4, DRAW_NONE); SetIndexBuffer(4,ExtMapBuffer5); SetIndexStyle(5, DRAW_NONE); SetIndexBuffer(5,ExtMapBuffer6); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- last counted bar will be recounted int counted_bars = IndicatorCounted(); if(counted_bars>0) counted_bars--; int limit=Bars-counted_bars; for(int i=limit-1;i>=0;i--) // Count down for one pass ExtMapBuffer3[i]=High[i]*(1+Factor*(High[i]-Low[i])/((High[i]+Low[i])/2)); for(i = limit-1; i>=0; i--)// Count down for one pass ExtMapBuffer4[i]=Low[i]*(1-Factor*(High[i]-Low[i])/((High[i]+Low[i])/2)); for(i = limit-1; i>=0; i--)// Count down for one pass ExtMapBuffer5[i]=iMAOnArray(ExtMapBuffer3,0,smPeriod,0,smMethod,i); for(i = limit-1; i>=0; i--)// Count down for one pass ExtMapBuffer6[i]=iMAOnArray(ExtMapBuffer4,0,smPeriod,0,smMethod,i); for(i=limit-1;i>=0;i--) // Count down for one pass { if(High[i]>ExtMapBuffer5[i]) ExtMapBuffer1[i]=1; else ExtMapBuffer1[i]=0; } for(i=limit-1;i>=0;i--) // Count down for one pass { if(Low[i]<ExtMapBuffer6[i]) ExtMapBuffer2[i]=-1; else ExtMapBuffer2[i]=0; } //---- return(0); } //+------------------------------------------------------------------+
Second code
//+------------------------------------------------------------------+ //| Acima_Abaixo_AccelarationBands.mq4 | //| | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "**" #property link "**" #property indicator_separate_window #property indicator_minimum -1 #property indicator_maximum +1 #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Green //---- input parameters extern double Factor=2;// extern int smPeriod=15;// extern int smMethod=1;// 0 - SMA, 1 - EMA, 2 - SMMA, 3 - LWMA //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[]; double ExtMapBuffer5[]; double ExtMapBuffer6[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(2); //--- Plot a line SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); SetIndexStyle(1, DRAW_LINE); SetIndexBuffer(1,ExtMapBuffer2); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- last counted bar will be recounted int counted_bars = IndicatorCounted(); if(counted_bars>0) counted_bars--; int limit=Bars-counted_bars; for(int i=limit-1;i>=0;i--) // Count down for one pass ExtMapBuffer3[i]=High[i]*(1+Factor*(High[i]-Low[i])/((High[i]+Low[i])/2)); for(i = limit-1; i>=0; i--)// Count down for one pass ExtMapBuffer4[i]=Low[i]*(1-Factor*(High[i]-Low[i])/((High[i]+Low[i])/2)); for(i = limit-1; i>=0; i--)// Count down for one pass ExtMapBuffer5[i]=iMAOnArray(ExtMapBuffer3,0,smPeriod,0,smMethod,i); for(i = limit-1; i>=0; i--)// Count down for one pass ExtMapBuffer6[i]=iMAOnArray(ExtMapBuffer4,0,smPeriod,0,smMethod,i); for(i=limit-1;i>=0;i--) // Count down for one pass { if(High[i]>ExtMapBuffer5[i]) ExtMapBuffer1[i]=1; else ExtMapBuffer1[i]=0; } for(i=limit-1;i>=0;i--) // Count down for one pass { if(Low[i]<ExtMapBuffer6[i]) ExtMapBuffer2[i]=-1; else ExtMapBuffer2[i]=0; } //---- return(0); } //+-----------------------------------------------
Thanks phy
Thanks 7bit.
I´ll test it today.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everybody
Every time that I need to find a value for an array [] I have been using buffers, even if I don´t need to plot a line. That´s a big problem, once there are a limited number of buffers to be used. When I try to replace it for a common array the indicator does no work
Anyone knows how to bring a value for an array, without using buffers?
Thanks
Rodrigosm