-
int OnInit() { ArrayInitialize(HighsBuffer, EMPTY_VALUE); ArrayInitialize(LowsBuffer, EMPTY_VALUE); ArrayInitialize(LineBuffer, EMPTY_VALUE); ArrayInitialize(ProtectedHighsBuffer, EMPTY_VALUE); ArrayInitialize(ProtectedLowsBuffer, EMPTY_VALUE); ArrayInitialize(LineToFlipBullish, EMPTY_VALUE); ArrayInitialize(LineToFlipBearish, EMPTY_VALUE);= ArrayInitialize(LineForNewZone, EMPTY_VALUE);
Your arrays (they are not buffers yet) have no size. Your calls do nothing. Must be done in OnCalculate.
-
void OnDeinit(const int reason) { ArrayResize(HighsBuffer, 0); ArrayResize(LowsBuffer, 0); ArrayResize(LineBuffer, 0); ArrayResize(LineToFlipBullish, 0); ArrayResize(LineToFlipBearish, 0); ArrayResize(ProtectedHighsBuffer, 0); ArrayResize(ProtectedLowsBuffer, 0);
Your buffers are handled by the terminal. You can't resize buffers.
-
int start = MathMax(rates_total - int(daysback * 24 * 60 / (PeriodSeconds(_Period) / 60)), 0); start = MathMax(start, prev_calculated - 2);
Why are you processing 60*daysback worth of bars, each and every tick. If you don't have that many bars, array exceed (negative index) and your indicator crashes.
How to do your lookbacks correctly #9 — #14 & #19 (2016) -
for(int i = 0; i < rates_total- int(daysback * 24 * 60); i++)
Loop does nothing unless you have 1440*dayback worth of bars. Why are you updating the earliest bars?
-
while(continueProcessing); LineBuffer[i] = currentVC;//The line that will validate a high/low LineForNewZone[i]= currentLineForNewZone;//The line that when breached a new zone will be determined LineToFlipBullish[i] = currentLineToFlipBullish;//The line that when breached, structure will shift bullish LineToFlipBearish[i] = currentLineToFlipBearish ;//The line that when breached, structure will shift bearish }
Infinite loop.
- Gentleman26 Mattias: I have used the buffers in my indicator with increasing indexes (so not set as series).
Where do you set your buffers to non-series?
-
continueProcessing = processBar(i, rates_total, high, low, close, open); continueProcessing = updateProtectedValues(i, rates_total, high, low,
Where do you set the direction of those arrays? In MT5, you must set the direction.
To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
-
Your arrays (they are not buffers yet) have no size. Your calls do nothing. Must be done in OnCalculate.
-
Your buffers are handled by the terminal. You can't resize buffers.
-
Why are you processing 60*daysback worth of bars, each and every tick. If you don't have that many bars, array exceed (negative index) and your indicator crashes.
How to do your lookbacks correctly #9 — #14 & #19 (2016) -
Loop does nothing unless you have 1440*dayback worth of bars. Why are you updating the earliest bars?
-
Infinite loop.
-
Where do you set your buffers to non-series?
-
Where do you set the direction of those arrays? In MT5, you must set the direction.
-
Your arrays (they are not buffers yet) have no size. Your calls do nothing. Must be done in OnCalculate.
-
Your buffers are handled by the terminal. You can't resize buffers.
-
Why are you processing 60*daysback worth of bars, each and every tick. If you don't have that many bars, array exceed (negative index) and your indicator crashes.
How to do your lookbacks correctly #9 — #14 & #19 (2016) -
Loop does nothing unless you have 1440*dayback worth of bars. Why are you updating the earliest bars?
-
Infinite loop.
-
Where do you set your buffers to non-series?
-
Where do you set the direction of those arrays? In MT5, you must set the direction.
I have updated my mq5 file. I do still have some questions about some of the feedback you gave.
1: removed that whole part as indeed it didn't do anything
2: Also removed the 'resizing' as mt5 does it automatically when deleting the indicator from the chart
3: I think I now made sure that only when a new candle has formed the logic will run
4: If you are referring to the fact that i'm emptying buffers before the lookback bars, if i don't do that the indicator will plot 0 values on all bars before the lookback bars.
5: I have a logic in that needs to be run again when for instance a block of code that is in the middle part is influencing the top part. but since that has already run i need to run the whole block of code one more time for it to have incorporated the change that was made in the middle part. (i hope i make myself clear here)
6: I have now set the buffer explicitly to non-series

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have made an indicator that will show me valid highs and lows following a certain logic.
But when after a while (maybe some hours) when i have it on the chart it will start to do weird things, draw lines that shouldn't be drawn, or delete certain line without any logic behind it.
I have used the buffers in my indicator with increasing indexes (so not set as series).
Is this something that I have to do when using buffers? Since I need to update them then on each new bar created and now i don't have to do that.
attached is the indicator file.