matrixfx Posted June 7, 2011 Report Share Posted June 7, 2011 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(),Time Frame1); limit=Bars-counted_bars+TimeFrame1/Period(); for(i=0,y1=0;i<limit;i++) { if (Time<TimeArray1[y1]) y1++; buffer1 = 0; buffer2 = 0; buffer3 = 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=EMPTY_VALUE; buffer2=EMPTY_VALUE; buffer3=EMPTY_VALUE; if (V_1_0>(mv*((V1+100)/100)) && (ATR_0>ATR_1)) buffer1 = BarLevl; else if ((V_1_0>((V_1_1+V_1_2)/2)*((V2+100)/100)/2)) buffer2 = BarLevl; else buffer3 = 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); } Quote Link to comment Share on other sites More sharing options...
bgrtz Posted June 8, 2011 Report Share Posted June 8, 2011 (edited) 1. Your Vol is not an array, so 2. mv always return false, which is -1 3. When you use mv as multiplication factor, the formula mv*((V1+100)/100) always give negative results 4. Since V_1_0 is iVolume, so it always give positive results 5. Final result, formula V_1_0 > (mv*((V1+100)/100) will compare "is [any positive value] bigger than [any negative value]". Of course the answer always TRUE 6. It will pass the other condition (the else part). You will only see Lime bars NB. 1. The mv is the index of array, not the value. So I believe you should use something like Vol[mv] 2. I just read the code, did not have time to try it yet. Sorry if I was mistaken, just trying to help Regards Edited June 9, 2011 by bgrtz matrixfx 1 Quote Link to comment Share on other sites More sharing options...
matrixfx Posted June 8, 2011 Author Report Share Posted June 8, 2011 bgrtz, thanks a lot for your comments and your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.