- They are not called ticks, they are Close Prices for the Bars. Ticks are individual price quotes and there can be hundreds ou even thousands of ticks per bar.
- Use "Close[ i ]" instead of "iClose(NULL,0,i)".
- Percentage change is against the previous bar and not against the current bar.
- Please remeber that the current bar is in flux and incomplete with the close price continually updating.
- There is no need for the ArraySetAsSerries in this case because you are using the old style of coding. So remove it.
- Your braces are in the wrong place for the loops.
- Remember that you current code will cause this indicator to continuously redraw (which is not good)!
- And there are a few other problematic points as well:
#property indicator_separate_window #property indicator_buffers 2 #property indicator_plots 2 #property indicator_color1 Red #property indicator_color2 Yellow //--- buffers double BLIPbar[]; double pc[]; int init() { SetIndexBuffer(0,pc); SetIndexBuffer(1,BLIPbar); SetIndexStyle(1,DRAW_HISTOGRAM); return(0); } int start() { int i,counted_bars=IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars>0) counted_bars--; int limit = MathMin(Bars-counted_bars,Bars-1); pc[0] = ( Close[0] - Close[1] ) / Close[1]; BLIPbar[0] = EMPTY_VALUE; // What value do you want it to be? for(i = limit; i > 0; i--) { pc[i] = ( Close[i] - Close[i+1] ) / Close[i+1]; // finding the percent change and hopefully filling the series data if(pc[i] > pc[0]) // Comparing current tick to last tick. I have tried multiple variations of pc[0], pc[2], etc and BLIPbar[i] = pc[i]; // when current percent change is higher than last I just want a bar to "BLIP" and show up. else BLIPbar[i] = EMPTY_VALUE; // You were missing the "else". What value do you want it to be when it is not greater? } return(0); }
- Once you have fixed it, please consider using the updated modern style of MQL4+ code and not the old style.
int i,counted_bars=IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars>0) counted_bars--; int limit = MathMin(Bars-counted_bars,Bars-1);
No need for the decrement. Contradictory information on IndicatorCounted() - MQL4 forumpc[i] = ( Close[i] - Close[i+1] ) / Close[i+1]
Your look back is one. So when limit is Bars-1, you access Close[Bars] which does not exist.- Do your lookbacks correctly.
Fantastic! Thank you for your guidance. I will work on all of these points. I am aware about the continuously redrawing effect and in the end will only calculate established closed bars :) I won't be able to address these for another 14 hours, but I appreciate this first step!!
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
Simple task. I have an array that simply takes the percent change from the previous tick. Then I want a histogram to show if the current tick is higher than the last. When I apply ArraySetAsSeries() it doesn't even work. I have placed it in multiple spots in the code and it either doesn't do anything or does all sorts of crazy histograms. Here is the the code. I would suggest removing the ArraySetSeries to see how the buffer should look. I have read anything I can get my hands on ArraySetSeries and I haven't ran into this issue yet. Please help and I am grateful!