mv = ArrayMaximum(Vol, VPeriod1, i+1); ... if (V_1_0>(mv*((V1+100)/100)) && (ATR_0>ATR_1)) buffer1[i] = BarLevl;
ArrayMaximum returns the bar number. You need:mv = Vol[ArrayMaximum(Vol, VPeriod1, i+1)];
limit=Bars-counted_bars+TimeFrame1/Period();
The first time counted_bars is zero so limit=Bars+x and you are going beyond the limits of the arrays.
//+------------------------------------------------------------------+ //| R2.mq4 | //| Copyright © 2011 | //+------------------------------------------------------------------+ #property copyright "" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Lime #property indicator_color2 Magenta #property indicator_color3 Gray #property indicator_width1 2 #property indicator_width2 2 #property indicator_width3 2 #property indicator_minimum 0 #property indicator_maximum 10 extern color LimeZone = Lime; // Strong Reverse conditions extern color MagentaZone = Magenta; // Medium Reverse Conditions extern color GrayZone = Gray; // Weak Reverse Conditions double ATR_0; double ATR_1; double V_1_0; double V_1_1; double V_1_2; double V_1_3; double V_1_4; double V_1_5; double V_1_6; double mv; string name; extern string TF = "-- Time Frame To Display --"; extern int TimeFrame1 = 0; extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF"; extern double BarLevl = 0; extern int ATRPeriod = 14; extern int VPeriod1 = 21; extern int V1 = 50; extern int V2 = 20; extern int alertSwitch = 0; //0=OFF , 1=ON extern int alertShift = 0; // 0=change color current Bars, 1=chamge color previous Bar, .... // double buffer1[], buffer2[], buffer3[]; int lastABar; int init() { SetIndexStyle(0,DRAW_ARROW, 2); SetIndexArrow(0,167); SetIndexBuffer(0,buffer1); SetIndexEmptyValue(0,EMPTY_VALUE); SetIndexStyle(1,DRAW_ARROW, 2); SetIndexArrow(1,167); SetIndexBuffer(1,buffer2); SetIndexEmptyValue(1,EMPTY_VALUE); SetIndexStyle(2,DRAW_ARROW, 2); SetIndexArrow(2,167); SetIndexBuffer(2,buffer3); SetIndexEmptyValue(2,EMPTY_VALUE); TimeFrame1=MathMax(TimeFrame1,Period()); IndicatorShortName("Vol_"+TimeFrame1); return(0); } int start() { datetime TimeArray1[], TimeArray2[], TimeArray3[]; int i,shift,limit,y1=0, counted_bars=IndicatorCounted(); double ATR_0, ATR_1; double V_1_0, V_1_1, V_1_2, V_1_3, V_1_4, V_1_5, V_1_6, mv; // Plot defined timeframe on to current timeframe ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),TimeFrame1); limit=Bars-counted_bars+TimeFrame1/Period(); for(i=0,y1=0;i<limit;i++) { if (Time[i]<TimeArray1[y1]) y1++; limit=Bars+1; buffer1[i] = 0; buffer2[i] = 0; buffer3[i] = 0; /*********************************************************** Add your main indicator loop below. You can reference an existing indicator with its iName or iCustom. Rule 1: Add extern inputs above for all neccesary values Rule 2: Use 'TimeFrame' for the indicator timeframe Rule 3: Use 'y' for the indicator's shift value **********************************************************/ ATR_0 = iATR(NULL,TimeFrame1,ATRPeriod,y1); ATR_1 = iATR(NULL,TimeFrame1,ATRPeriod,y1+1); V_1_0 = iVolume(Symbol(),TimeFrame1,y1); V_1_1 = iVolume(Symbol(),TimeFrame1,y1+1); V_1_2 = iVolume(Symbol(),TimeFrame1,y1+2); double Vol = iVolume(Symbol(),TimeFrame1,i); mv = Vol[ArrayMaximum(Vol, VPeriod1, i+1)]; buffer1[i]=EMPTY_VALUE; buffer2[i]=EMPTY_VALUE; buffer3[i]=EMPTY_VALUE; if (V_1_0>(mv*((V1+100)/100)) && (ATR_0>ATR_1)) buffer1[i] = BarLevl; else if ((V_1_0>((V_1_1+V_1_2)/2)*((V2+100)/100)/2)) buffer2[i] = BarLevl; else buffer3[i] = BarLevl; } if (alertSwitch == 1 && Bars > lastABar) { if (buffer1[alertShift] != EMPTY_VALUE && buffer1[alertShift+1] == EMPTY_VALUE) { Alert("Strong Reverse conditions, "+Symbol()+" , M_"+Period()); lastABar = Bars; } if (buffer2[alertShift] != EMPTY_VALUE && buffer2[alertShift+1] == EMPTY_VALUE) { Alert("Medium revese conditions, "+Symbol()+" , M_"+Period()); lastABar = Bars; } } return(0); }
matrixfx:
WHRoeder, thank you a lot for your answer. The info you've sent is very usefull to me. I have changed the code, the point 3 (limit=Bars+x) I'm not sure I did correctly and when I compiled I received the mesage " "[" unexpected token". Can you please help me introduce this condition? Thank you for all your help and I appologize for my unexperienced problems. Here is the code:
matrixfx:
I compiled I received the mesage "[" unexpected token".
My original post was wong. I sawI compiled I received the mesage "[" unexpected token".
ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),TimeFrame1); ... mv = ArrayMaximum(Vol, VPeriod1, i+1);and assumed Vol was the array from the ACS call.
double Vol = iVolume(Symbol(),TimeFrame1,i); mv = Vol[ArrayMaximum(Vol, VPeriod1, i+1)];Vol is a double, so arrayMax(Vol) makes no sense. Try
mv = Volume[highest(NULL,0, MODE_VOLUME, VPeriod1, i+1)];
If you mean highest volume in TimeFrame1 chart
int HVtf1 = highest(NULL,TimeFrame1, MODE_VOLUME, VPeriod1, i+1); double mv = iVolume(NULL,TimeFrame1, HVtf1);
WHRoeder:
My original post was wong. I saw and assumed Vol was the array from the ACS call.
Vol is a double, so arrayMax(Vol) makes no sense. Try
If you mean highest volume in TimeFrame1 chart
My original post was wong. I saw and assumed Vol was the array from the ACS call.
Vol is a double, so arrayMax(Vol) makes no sense. Try
If you mean highest volume in TimeFrame1 chart
Thanks a lot for your help, time and patience! You are my guru!

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
Hello all,
I'm trying to use ArrayMaximum to return and use the maximum volume value in a 20 bar period. The indicator is compiled, but if I delete the ATR condition (ATR_0>ATR_1), it doesn't work properly. In fact I think it didn't return the maximum value from the array. Can a programmer help me integrating the ArrayMaximum in the indicator. Thank you a lot for any help!
Here it is the code:
//+------------------------------------------------------------------+
//| R2.mq4 |
//| Copyright © 2011 |
//+------------------------------------------------------------------+
#property copyright ""
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Magenta
#property indicator_color3 Gray
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_minimum 0
#property indicator_maximum 10
extern color LimeZone = Lime; // Strong Reverse conditions
extern color MagentaZone = Magenta; // Medium Reverse Conditions
extern color GrayZone = Gray; // Weak Reverse Conditions
double ATR_0;
double ATR_1;
double V_1_0;
double V_1_1;
double V_1_2;
double V_1_3;
double V_1_4;
double V_1_5;
double V_1_6;
double mv;
string name;
extern string TF = "-- Time Frame To Display --";
extern int TimeFrame1 = 0;
extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
extern double BarLevl = 0;
extern int ATRPeriod = 14;
extern int VPeriod1 = 21;
extern int V1 = 50;
extern int V2 = 20;
extern int alertSwitch = 0; //0=OFF, 1=ON
extern int alertShift = 0; // 0=change color current Bars, 1=chamge color previous Bar, ....
//
double buffer1[], buffer2[], buffer3[];
int lastABar;
int init()
{
SetIndexStyle(0,DRAW_ARROW, 2); SetIndexArrow(0,167); SetIndexBuffer(0,buffer1); SetIndexEmptyValue(0,EMPTY_VALUE);
SetIndexStyle(1,DRAW_ARROW, 2); SetIndexArrow(1,167); SetIndexBuffer(1,buffer2); SetIndexEmptyValue(1,EMPTY_VALUE);
SetIndexStyle(2,DRAW_ARROW, 2); SetIndexArrow(2,167); SetIndexBuffer(2,buffer3); SetIndexEmptyValue(2,EMPTY_VALUE);
TimeFrame1=MathMax(TimeFrame1,Period());
IndicatorShortName("Vol_"+TimeFrame1);
return(0);
}
int start()
{
datetime TimeArray1[], TimeArray2[], TimeArray3[];
int i,shift,limit,y1=0, counted_bars=IndicatorCounted();
double ATR_0, ATR_1;
double V_1_0, V_1_1, V_1_2, V_1_3, V_1_4, V_1_5, V_1_6, mv;
// Plot defined timeframe on to current timeframe
ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),TimeFrame1);
limit=Bars-counted_bars+TimeFrame1/Period();
for(i=0,y1=0;i<limit;i++)
{
if (Time[i]<TimeArray1[y1]) y1++;
buffer1[i] = 0; buffer2[i] = 0; buffer3[i] = 0;
/***********************************************************
Add your main indicator loop below. You can reference an existing
indicator with its iName or iCustom.
Rule 1: Add extern inputs above for all neccesary values
Rule 2: Use 'TimeFrame' for the indicator timeframe
Rule 3: Use 'y' for the indicator's shift value
**********************************************************/
ATR_0 = iATR(NULL,TimeFrame1,ATRPeriod,y1);
ATR_1 = iATR(NULL,TimeFrame1,ATRPeriod,y1+1);
V_1_0 = iVolume(Symbol(),TimeFrame1,y1);
V_1_1 = iVolume(Symbol(),TimeFrame1,y1+1);
V_1_2 = iVolume(Symbol(),TimeFrame1,y1+2);
double Vol = iVolume(Symbol(),TimeFrame1,i);
mv = ArrayMaximum(Vol, VPeriod1, i+1);
buffer1[i]=EMPTY_VALUE; buffer2[i]=EMPTY_VALUE; buffer3[i]=EMPTY_VALUE;
if (V_1_0>(mv*((V1+100)/100)) && (ATR_0>ATR_1)) buffer1[i] = BarLevl;
else
if ((V_1_0>((V_1_1+V_1_2)/2)*((V2+100)/100)/2)) buffer2[i] = BarLevl;
else buffer3[i] = BarLevl;
}
if (alertSwitch == 1 && Bars > lastABar) {
if (buffer1[alertShift] != EMPTY_VALUE && buffer1[alertShift+1] == EMPTY_VALUE) {
Alert("Strong Reverse conditions, "+Symbol()+", M_"+Period());
lastABar = Bars;
}
if (buffer2[alertShift] != EMPTY_VALUE && buffer2[alertShift+1] == EMPTY_VALUE) {
Alert("Medium revese conditions, "+Symbol()+", M_"+Period());
lastABar = Bars;
}
}
return(0);
}