If you want static array - one with a size defined at declaration time - you must use constant to declare size.
If you want variable sized array, read about dynamic arrays and ArrayResize() function.
- docs.mql4.com
int VisibleBar=WindowFirstVisibleBar()
retrun a integer value , why give me error
I i want static array , and i suppsoe
retrun a integer value , why give me error
As I already wrote:
you must use constant to declare size
I i want static array , and i suppsoe
retrun a integer value , why give me error
If you want static array - one with a size defined at declaration time - you must use constant to declare size.
If you want variable sized array, read about dynamic arrays and ArrayResize() function.
but now why tell me out of range ?? whats wrong ?
#property indicator_chart_window extern int font_size = 10; extern color ColorBull = DodgerBlue; extern color ColorBeer = Red; extern string font_name = "Arial"; double aBodyCount[2]; //+------------------------------------------------------------------+ int start() { int VisibleBar=WindowFirstVisibleBar(); ArrayResize(aBodyCount,VisibleBar,VisibleBar); BodyCount(); } //+------------------------------------------------------------------+ int deinit() { ObjectsDeleteAll(0,OBJ_TEXT); return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| BODY COUNT VISIBLE | //+------------------------------------------------------------------+ void BodyCount() { for(int i=WindowFirstVisibleBar(); i>=0; i--) { aBodyCount[i] = ((NormalizeDouble(Open[i],Digits)/Point)-(NormalizeDouble(Close[i],Digits))/Point); } Alert("Plus ", aBodyCount[i]," pt."); return ; } //+------------------------------------------------------------------+
- Your array has two elements. WindowFirstVisibleBar is likely in the hundreds.
- Next time: Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
Array index is zero based, so if you have WindowFirstVisibleBar() elements in your array, they have indexes from array[0] to array[WindowFirstVisibleBar()-1]
Your loop from the above snippet should start from WindowFirstVisibleBar()-1
And another thing to check is if WindowFirstVisibleBar() changes
value as time passes. For example can it happen that on start WindowFirstVisibleBar() returns
value 100, and after some time some bigger number?
If that is the case, you will initialize array for 100 elements, and later you will
expect it to have more.
You should get familiar how the arrays work in MQL and C++, otherwise you will have number of problems.
Array index is zero based, so if you have WindowFirstVisibleBar() elements in your array, they have indexes from array[0] to array[WindowFirstVisibleBar()-1]
Your loop from the above snippet should start from WindowFirstVisibleBar()-1
And another thing to check is if WindowFirstVisibleBar() changes
value as time passes. For example can it happen that on start WindowFirstVisibleBar() returns
value 100, and after some time some bigger number?
If that is the case, you will initialize array for 100 elements, and later you
will expect it to have more.
You should get familiar how the arrays work in MQL and C++, otherwise you will have number of problems.
yea i understund what you tell but , my case is different i know that array start the count 0 to end and i if i create
Array [2] ,resize it, and with(WindowFirstVisibleBar() +
5)and cicle for insert inside of array with for(int i=WindowFirstVisibleBar(); i>=0; i--) , i aspect the script
runn good , but return the same2020.05.15 23:19:13.116 candle-body-size USDCHF,H1: array out of range in
'candle-body-size.mq4' (60,29)
example if WindowFirstVisibleBar()
is equal = 100 and i resize in 105 , if for start to 0 or 1 for me is no problem i have 5 position plus
yea i understund what you tell but , my case is different i know that array start the count 0 to end and i
if i create Array [2] ,resize it, and with(WindowFirstVisibleBar()
+ 5)and cicle for insert inside of array with for(int i=WindowFirstVisibleBar(); i>=0; i--) , i aspect the
script runn good , but return the same2020.05.15 23:19:13.116 candle-body-size USDCHF,H1: array
out of range in 'candle-body-size.mq4' (60,29)
example if WindowFirstVisibleBar()
is equal = 100 and i resize in 105 , if for start to 0 or 1 for me is no problem i have 5 position plus
You cannot resize an array that was created static. You can only resize a dynamic array. ArrayResize() has a return value, check it to detect
errors.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi guys , why if i decleare array in this mode return me error invalid index value ?
is a integer