Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 71

 
trader781:

Okay, let's do this.

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?

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.

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++;
         }
}
 
sile:
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:

if(AccountInfoDouble(ACCOUNT_MARGIN_FREE)/AccountInfoDouble(ACCOUNT_BALANCE)<0.5) {действие}
 
Vitalie Postolache:


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?
 
trader781:

Okay, let's do this.

struct myorder
{
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"?

 
Hello. Is there a universal code that can be inserted at the end of the description of any indicator that would allow to change the TF of that indicator (i.e. M5 to M1)?
 
Artyom Trishkin:

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 pissants and rotten eggs at someone's ability to learn material. Your suggestion 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?
 
trader781:
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 refuse to help you after such wild fantasies? 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 size of the array - what and where will be written at each iteration of the loop. Don't look for pieces of code that you think fit.
Understand that teaching is difficult, especially when one does not really want to learn.
 
Artyom Trishkin:
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.
Understand that teaching is difficult, especially when a person doesn't really want to learn.

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.

 
trader781:

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.

I do not have such a command. I have to make my own. I.e. - function.
 
Artyom Trishkin:
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
Reason: