You're setting your main buffers Peak_High and Peak_Low to series, but you're not setting high and low buffers to series in OnCalculate, so if the data will be connected correctly - you need set all used buffers in series
ArraySetAsSeries(high, true); ArraySetAsSeries(low, true);
//+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { ArraySetAsSeries(high, true); ArraySetAsSeries(low, true); showPF = GlobalVariableGet("pf_showPF"); Print("showPF = ", showPF); if(showPF) { // ArrayInitialize(Peak_High, EMPTY_VALUE); // ArrayInitialize(Peak_Low, EMPTY_VALUE); bar_high = 0; bar_low = 0; for(int i = 0; i < PeakCount; i ++) { bar_high = FindPeak(Symbol(), Period(), MODE_HIGH, shoulder, bar_high + 1); Peak_High[bar_high] = high[bar_high]; bar_low = FindPeak(Symbol(), Period(), MODE_LOW, shoulder, bar_low + 1); Peak_Low[bar_low] = low[bar_low]; PrintFormat("bar_high = %d bar_low = %d", bar_high, bar_low); PrintFormat("PeakHigh[bar_high] = %f PeakLow[bar_low] = %f", Peak_High[bar_high], Peak_Low[bar_low]); } } return(rates_total); }
Don't use ArrayInitialize freely like that. Only initialize the buffers when prev_calculated = 0.
Fix the function calls as well, you don't use the index i
for(int i = 0; i < PeakCount; i ++) { bar_high = FindPeak(Symbol(), Period(), MODE_HIGH, shoulder, i + 1); Peak_High[bar_high] = high[bar_high]; bar_low = FindPeak(Symbol(), Period(), MODE_LOW, shoulder, i + 1); Peak_Low[bar_low] = low[bar_low]; PrintFormat("bar_high = %d bar_low = %d", bar_high, bar_low); PrintFormat("PeakHigh[bar_high] = %f PeakLow[bar_low] = %f", Peak_High[bar_high], Peak_Low[bar_low]); }
There are no such good quality peaks to be found like this, as you need to continuously ignore or remove the peak or bottom if they get invalidated.
I developed this further to use a zigzag drawing to demonstrate how you find true peaks by using the same code (with added peak validation).
(A tick series version and a normal Mql5-appropriate version for educational purposes)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
While converting my MT4 indicator code to MT5, I came across a strange issue where the arrows disappeared when a new tick came in. Could anyone help with this?
When I hit [z] key to activate indicator display, peak high and low arrows appear on chart, but soon after when a new tick comes in, they disappear unintentionally.