Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 84
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
Then please answer my previous question
1) Writing an array of structures
2) Transferring to other functions
3) Retrieving and comparing elements of an array of structures
4) printing an array of structures
It is important for me to write it in the form of code so that I understand how it must look like.
It all depends on the task at hand. Since tasks can be as different as you want, what should be shown?
Well, I'll write it, I'll waste my time and what I've written is square. And the hole is triangular. And where do I put the square one then?
It all depends on the task at hand. Since tasks can be as varied as you like, what should be shown?
Well, I'll write it, waste my time, but what I've written is square. And the hole is triangular. And where do I put the square one then?
let's take post 699 and about
how to pass this to other functions and compare an element in the structure with the previous one
so i can take any order in order and output all values to the print
The difference is that it's not a number and there are different rules of recording.
let's take post 699 and about
how to pass this to other functions and compare the structure element with the previous one
and so I can take any order in order and print all the values
The difference is that it's not a number and different writing rules apply.
You need to loop through all of the necessary orders.
After the next necessary order is determined, you increase the array by 1, and record all data on this order in its new cell. The array cell itself is filled with the order open time (if you are searching for closed orders, then close time). The rest of the data should be written into the fields of the structure.
After the loop ends, sort the array in ascending order of values.
You should do this first. The rest can be discussed further.
This is not a problem that can be solved within a single cycle.
Thank you.
//| test.mq4 |
//| Copyright 2014, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
struct myorder
{
int Ticket;
double orderopenprice;
int ordertype;
double profit;
double stoploss;
double lot;
};
myorder orders[][5];
int i;
int Magic=444;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
CalcOrders();
}
//+------------------------------------------------------------------+
void CalcOrders()
{
int count1=-1;
ArrayResize(orders,AccountInfoInteger(ACCOUNT_LIMIT_ORDERS),10);
for(i=OrdersTotal()-1; i>=0; i--)
{
if((OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) && (OrderSymbol()==Symbol())
&& (OrderMagicNumber()==Magic) && (OrderType()<2))
{
count1++;
orders[count1][0].Ticket=OrderTicket();
orders[count1][1].lot=OrderLots();
orders[count1][2].orderopenprice=OrderOpenPrice();
orders[count1][3].ordertype=OrderType();
orders[count1][4].profit=OrderProfit();
orders[count1][5].stoploss=OrderStopLoss();
}
}
ArraySort(orders,WHOLE_ARRAY,0,MODE_ASCEND);
}
//+------------------------------------------------------------------+
I put your code in your post.
Now if you start to sort it out
I put your code in your post.
Now if you start to sort it out
1) thought that X order Y parameter number is more appropriate for the given task
2) I have it equal to 50 or 100 depending on the account type, and nothing else
3) so ifcount1++; will increase at each pass, and the array will acquire its value
1) considered that X order Y parameter number is more appropriate for this task
2) it is equal to 50 or 100 depending on the account type, and nothing else
3) so ifcount1++; will increase at each pass, and the array will acquire its value
1. what is the structure for then?
2. You need this parameter for an array of "what went and what went" market positions... The array before the loop must have a zero size.
3. That's right. The array has a zero size at the beginning. With every new order found, the array becomes equal in size to the number of orders you need.
1) What is the structure for then?
2. You need this parameter for the array of market positions "what went and what went". The array before the loop must have a zero size.
3. That's right. The array has a zero size at the beginning. With every new order found, the array becomes equal in size to the number of orders you need.
1) the compiler will complain if the second dimension is not put, "specify class type, unknown parameters" will pop up immediately
2) the bot will die immediately at launch with "critical error array out of range".
3) setint count1=-1; then go through the loop. What's wrong here?
1) the compiler will complain if the second dimension is not set
2) then the bot will die immediately on startup with "critical error array out of range"
3) immediately setint count1=-1; What's wrong here?
It's just telling you that one of the dimensions should be removed. You are declaring a one-dimensional array and want to write it into a two-dimensional one. What will you get as a result? You will get an error from the compiler, of course.
2. You have to fill the array correctly in the loop, and not just give it some random-sized variable and then shove some random-sized stuff in it.
3. you're the one who sets the variable to -1. And the array must have zero size before the loop. What's not clear here?
Let's play a game of association:
- Imagine you have a deflated balloon (empty array) that has zero internal volume (zero array size). Inside this balloon (in the array) you want to put coins (the orders you want). Here, each coin, once you decide it is suitable to be stored in the balloon (each desired order found), will increase the balloon's internal volume (only the coin itself will stretch the balloon, and you need to do it yourself - increase array size by 1 and cram one order into it).
Here's an association for you.At the end, when you find all the coins and cram them into the ball, it will not be deflated - its internal volume has been stretched by the coins (at the end of the search cycle the size of the array will be equal to the number of found necessary orders, as you increased the size of the array by 1 with each found necessary order).
Now imagine that you initially put your coins not into a ball, which is rubber and can change its size, but into a small moneybox that has a limited size (you have initially set the size of the array and haven't increased it further). What will happen? Not all the coins will fit in the piggy bank. The balloon will.