Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 71
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
Okay, let's do this.
{
if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) && (OrderSymbol()==Symbol())
&& (OrderMagicNumber()==Magic) && (OrderType()<2))
orders[count1].Ticket=OrderTicket();
orders[count1].lot=OrderLots();
orders[count1].orderopenprice=OrderOpenPrice();
orders[count1].ordertype=OrderType();
orders[count1].profit=OrderProfit();
orders[count1].stoploss=OrderStopLoss();
count1++;
}
right?
You also need curly brackets, otherwise only the first line afterif() will work. You have many brackets where you don't need them, and then there are no brackets where you need them. This breaks the program logic, sometimes very much. And the counter does not have to be global, but it is not so important.
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol()
&& OrderMagicNumber()==Magic && OrderType()<2)
{
orders[count1].Ticket=OrderTicket();
orders[count1].lot=OrderLots();
orders[count1].orderopenprice=OrderOpenPrice();
orders[count1].ordertype=OrderType();
orders[count1].profit=OrderProfit();
orders[count1].stoploss=OrderStopLoss();
count1++;
}
}
Help me write the condition: If the amount of available funds in the account is less than 50% of the deposit, then {action} MT5
From what deposit? Initial? Or from the current balance?
If compared to the balance, then so:
I thought he wanted an mt5.
I have a good idea how to get the counter to the very beginning of the ontik and then work with that.
Now how do I get something out of it in my case?
and moreover, if the array will be two-dimensional and more (there is a difference in writing and extraction)
can we talk a bit about this point?Okay, let's do this.
{
int Ticket;
double orderopenprice;
int ordertype;
double profit;
double stoploss;
double lot;
};
myorder orders[];
int i;
int count1=0;
void CalcOrders()
{
for(i=OrdersTotal()-1; i>=0; i--)
{
if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) && (OrderSymbol()==Symbol())
&& (OrderMagicNumber()==Magic) && (OrderType()<2))
orders[count1].Ticket=OrderTicket();
orders[count1].lot=OrderLots();
orders[count1].orderopenprice=OrderOpenPrice();
orders[count1].ordertype=OrderType();
orders[count1].profit=OrderProfit();
orders[count1].stoploss=OrderStopLoss();
count1++;
}
}
right?
No, it's not right.
Your array orders[] has zero value. Where are you going to write the data? Into an array with a zero size? No way. You should increment the size of the array by count1+1 - if you increment the counter after writing to the array. Usually, the counter is incremented before you write, then you increase the array size by the counter size, and then you write the values by the index [count1-1]. And, as it was rightly noted above - you need to put all other actions in curly brackets after checking conditions.
Why are you trying to do something without elementary knowledge and ideas? Just "for luck"?
No, it's not.
Your array orders[] has zero value. Where are you going to write the data? Into an array with a zero size? No way. You should increment the size of the array by count1+1 - if you increment the counter after writing to the array. Usually, the counter is incremented before you write, then you increase the array size by the counter size, and then you write the values by the index [count1-1]. And, as it was rightly noted above - you need to put all other actions in curly brackets after checking conditions.
Why are you trying to do something without elementary knowledge and ideas? Just "for luck"?
Let's not throw rotten dicks and rotten eggs at someone's ability to learn. Your proposal to solve my problem was through the way of building an array of structures. I opened textbooks and pasted together as I could understand it, and threw the code here for public review to gauge how correct it all is. You don't think that I will make an ideal variant at once, do you?
Should I be discouraged from helping after such a violent fantasy. I implore you one last time: write down the algorithm on a piece of paper and go over it with a pencil a few times. Write down the values and the array size - what and where will be written at each iteration of the loop. Don't look for pieces of code that you think fit.
Artyom, that's understandable, but I can also be understood in this case. Nothing works and it won't work in the current version. I've been writing for several pages about the need of the command itself to pull the required element of the given array and that I have no idea how it should be written for this particular case, for example the stop loss for 5th order.
As for the pencil and the leaf - the bot has been ready for a month already and perfectly plummets on any instrument, I just want to modify it by adding a branch of irregular averaging.
Artyom, that's understandable, but I can also be understood in this case. Nothing works and will not work in current variant. I have been writing for several pages about the need for the command itself to pull the required element of this array and that I have no idea how it is written for this particular case, for example stoploss for the 5th order.
I have no idea how to write it for this particular case, for example, stoploss for 5th order.
There is no such command. You need to make your own. I.e. - a function.
OK, then as I understand it, there are three different custom functions with the return of the right one (if you look for three different parameters)
ArraySort
then
ArrayBsearch by the right number
and then how do I deal with it?
Exactly the transition from an array to a structure element