
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
No, I don't mean what you have already written.
Tell me in words - profit calculation for which closed orders you are interested in
- daily
- loss-making
- last order
or something else?
Describe the series
A series of last closed orders "for now"
Series of last closed orders "for now"
That is, you need information about the most recently closed series of orders, if I understand it correctly?
To implement this approach, you should first fill the array of order tickets at each successful closing and then pull out the information on closed orders in the form you need
Can you do it yourself?
Try
return(LastProfit);Comment( LastProfitCL(-1, 0) );
//+----------------------------------------------------------------------------+
//| Возвращает суммарный профит в валюте депозита серии закрытых ордеров |
//+----------------------------------------------------------------------------+
double LastProfitCL(int op=-1, datetime t=0){ //"op" позиция (-1 любая позиция)
double LastProfit=0;
for(int i=OrdersHistoryTotal()-1;i>=0;i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {
if((op<0||OrderType()==op) && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
if(t<=OrderCloseTime()) {
t=OrderCloseTime();
LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();
}}}}
}
Try
Comment( LastProfitCL(-1, 0) );
//+----------------------------------------------------------------------------+
//| Возвращает суммарный профит в валюте депозита серии закрытых ордеров |
//+----------------------------------------------------------------------------+
double LastProfitCL(int op=-1, datetime t=0){ //"op" позиция (-1 любая позиция)
double LastProfit=0;
for(int i=OrdersHistoryTotal()-1;i>=0;i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {
if((op<0||OrderType()==op) && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic){
if(t<=OrderCloseTime()) {
t=OrderCloseTime();
LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
return(LastProfit);
}
What if it doesn't close at the same time?
Not quite right.
And if you remember t when submitting the closing order, then it will be fine.
but this line...
is not necessary.
It will pull the total for the entire series
But madam wants more detailed information, as I understood from the first post
What if it doesn't close at the same time?
So you need information on the last closed series of orders, if I understand correctly?
To implement this approach, you should first create an array of order tickets at successful closing and then pull information on closed orders
Can you do it yourself?
Please advise us to use an example.
I.e.
And then compare ?
You' d better give me an example.
I.e.
And then compare ?
No problem.
Now the only thing left to clarify is how the information on the closed orders of the series should look like ?
Is it a transfer or should the amount be divided by + and - ?
There is an indicator for
i-Profit
Outputscurrent profits for today, week, month, year.
A better example would be
Here is an example:
GlobalVariableSet(GetGlobalVariableName("LastProfit"), TimeCurrent()); // запомним время закрытия
// здесь код закрытия всех и сразу, нужен цикл, чтоб не выходил с функции до полного закрытия всех
}
The rest of the story
//| Возвращает суммарный профит в валюте депозита серии закрытых позиций |
//+----------------------------------------------------------------------------+
double LastProfitCL(int op=-1, datetime t=0){ //"op" позиция (-1 любая позиция)
double LastProfit=0;
for(int i=OrdersHistoryTotal()-1;i>=0;i--) {
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) {
if((op<0||OrderType()==op) && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic){
if(t<=OrderCloseTime()) {
t=OrderCloseTime();
LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();
}}}}
return(LastProfit);
}
//===============================================================================================
//----------------------- Создает и возвращает имя глобальной переменной -----------------------+
//===============================================================================================
string GetGlobalVariableName(string name="", string symb="0") {
if(symb=="0") { symb=Symbol();}
if(!MQLInfoInteger(MQL_TESTER)) {
return(prefix+symb+"_"+(string)AccountInfoInteger(ACCOUNT_LOGIN)+"_"+MQLInfoString(MQL_PROGRAM_NAME)+"_"+name);
} else {
return(prefix+symb+"_"+(string)AccountInfoInteger(ACCOUNT_LOGIN)+"_"+MQLInfoString(MQL_PROGRAM_NAME)+"_tester"+"_"+name);
}}
We get it even if we restart the terminal
{
Comment( LastProfitCL(-1, (datetime)GlobalVariableGet(GetGlobalVariableName("LastProfit"))) );
}
There is an indicator for
i-Profit
Outputscurrent profits for today, week, month, year.