int max=ArrayMaximum(opPrices);//line 845 level = opPrices[max];//line 846What happens when you have no positions?
What happens when you have no positions?
Thanks for the reply.
I only call the function if I have open position(s).
bool inProfits=false; if(Sell_opened){ //check for open sell position double openLevel=checkAllProfit("Sell"); if(openLevel>bprice) { //bprice is the current bid price inProfits=true; } }
Hello! I'm writing a function that will compare the open prices of all open positions.
In case it is a buy, it will determine and return the open price with highest value.
In case it is a sell, it will determine and return the open price with the lowest value.
The purpose is to make sure all previous positions in the selected symbol are in profits before opening/adding another position when the conditions are met.
I tried this code but I get an error when I attach the expert(array out of range on line 846 and 850).
I tried to initialize the array with empty value first but no avail.
I'm new in mql5 arrays. I will be happy if anyone could point out what I'm not doing right. Or point me in the
right direction.
Are positions opened? It should work. Most likely no position is opened, or maybe the symbol (_symbol) of the current chart, is not same with that of your opened position. Troubleshoot
opPrices[] array
to ensure the opens were added, then write a conditional statement to ensure the array have values before line 845
Are positions opened? It should work. Most likely no position is opened, or maybe the symbol (_symbol) of the current chart, is not same with that of your opened position. Troubleshoot
to ensure the opens were added, then write a conditional statement to ensure the array have values before line 845
Thanks a lot for the directions. I found out my issue.
I had performed the Sell_Opened in the OnInit() block instead of in the OnTick() block. So the variable Sell_Opened was set to true once and it remained so as long as the expert was still attached. That's why it was always calling the function even when I had no open positions. I also modified my function further to return a value which would make InProfits variable false if there are no open positions(opPrices is empty) just to make sure I don't encounter similar problems in the future. Thanks a lot guys for your help.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello! I'm writing a function that will compare the open prices of all open positions.
In case it is a buy, it will determine and return the open price with highest value.
In case it is a sell, it will determine and return the open price with the lowest value.
The purpose is to make sure all previous positions in the selected symbol are in profits before opening/adding another position when the conditions are met.
I tried this code but I get an error when I attach the expert(array out of range on line 846 and 850).
I tried to initialize the array with empty value first but no avail.
I'm new in mql5 arrays. I will be happy if anyone could point out what I'm not doing right. Or point me in the
right direction.