Profit calculation of closed orders "HELP" - page 3 123456789 New comment Renat Akhtyamov 2016.12.11 16:19 #21 Vitaly Muzichenko: It does not fit, there is no information for 10 years.It's not the same for you either.The t variable will change and you'll be aghtung.It has to be memorised before you start closing the seriescolor ProfitColor;datetime t;// START // //t=TimeCurrent();//разместить в блоке сигнала на закрытие серии ордеров if(LastProfitCL(-1)<0) ProfitColor=Red; if(LastProfitCL(-1)>0) ProfitColor=LimeGreen; if(LastProfitCL(-1)==0)ProfitColor=DarkGray; ObjectCreate("Last Profit", OBJ_LABEL, 0, 0, 0); ObjectSet("Last Profit", OBJPROP_CORNER, 1); ObjectSet("Last Profit", OBJPROP_XDISTANCE, 5); ObjectSet("Last Profit", OBJPROP_YDISTANCE, 15); ObjectSetText("Last Profit",StringConcatenate("Last Profit: ",DoubleToStr(LastProfitCL(-1),2)),10,"Arial",ProfitColor);// END START ////+----------------------------------------------------------------------------+//| Возвращает суммарный профит в валюте депозита серии закрытых ордеров |//+----------------------------------------------------------------------------+double LastProfitCL(int op=-1){ //"op" позиция (-1 любая позиция) double LastProfit=0; for(i=OrdersHistoryTotal()-1;i>=0;i--) if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderType()==OP_BUY || OrderType()==OP_SELL) && OrderSymbol()==Symbol() && OrderMagicNumber()==magic) { if (OrderType()!= op || OrderSymbol()!= Symbol() || OrderMagicNumber()!= magic) continue; if (op<0 || OrderType()==op) { if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap(); } } return(LastProfit); } How to code? Any questions from newcomers Coding help Vitaly Muzichenko 2016.12.11 16:24 #22 Renat Akhtyamov: It's not the same for you either.The t variable will change and you'll be aghast.It has to be memorized before the series closes.Have you tried it? It's memorized before closing, at the moment the signal to close. Alekseu Fedotov 2016.12.11 16:25 #23 Vitaly Muzichenko: It is not suitable, there is no information for 10 years.Current profit, , all history.By the way, it can be set to any date and time. [Deleted] 2016.12.11 16:26 #24 Vitaly Muzichenko: TryComment( 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);}Profit remembers every new one, but then something counts unknown. In screen #3 it should be 4, not 190 Renat Akhtyamov 2016.12.11 16:28 #25 Vitaly Muzichenko: Have you tried it? It remembers before it closes, at the moment the closing signal is received Just read the code. [Deleted] 2016.12.11 16:37 #26 That, too, 190if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap(); Vitaly Muzichenko 2016.12.11 16:39 #27 Natashe4ka: Profit remembers every new one, but then something counts unknown. In screen #3 it should be 4, not 190Here's the code, it works fine for me, but maybe because the series is closed correctly Files: info.mq4 9 kb Renat Akhtyamov 2016.12.11 16:40 #28 Natashe4ka: So also 190if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();Where is the command to close orders located?Did you write the variable t in there?t=TimeCurrent();//разместить в блоке сигнала на закрытие серии ордеров [Deleted] 2016.12.11 16:42 #29 Renat Akhtyamov: Where is the command to close orders located?Have you written the variable t in there? t=TimeCurrent();//place in the signal block for closing a series of ordersIt's all there of course.if(t<=OrderCloseTime()) { t=OrderCloseTime();if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap(); Renat Akhtyamov 2016.12.11 16:48 #30 Natashe4ka: It's all there, of course.if(t<=OrderCloseTime()) { t=OrderCloseTime();if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();No, this line is removed. This is already a profit calculation, it won't work that way. Where the command to close in the code - there, but not such a lineRead above. 123456789 New comment
It does not fit, there is no information for 10 years.
It's not the same for you either.
The t variable will change and you'll be aghtung.
It has to be memorised before you start closing the series
color ProfitColor;
datetime t;
// START //
//t=TimeCurrent();//разместить в блоке сигнала на закрытие серии ордеров
if(LastProfitCL(-1)<0) ProfitColor=Red;
if(LastProfitCL(-1)>0) ProfitColor=LimeGreen;
if(LastProfitCL(-1)==0)ProfitColor=DarkGray;
ObjectCreate("Last Profit", OBJ_LABEL, 0, 0, 0);
ObjectSet("Last Profit", OBJPROP_CORNER, 1);
ObjectSet("Last Profit", OBJPROP_XDISTANCE, 5);
ObjectSet("Last Profit", OBJPROP_YDISTANCE, 15);
ObjectSetText("Last Profit",StringConcatenate("Last Profit: ",DoubleToStr(LastProfitCL(-1),2)),10,"Arial",ProfitColor);
// END START //
//+----------------------------------------------------------------------------+
//| Возвращает суммарный профит в валюте депозита серии закрытых ордеров |
//+----------------------------------------------------------------------------+
double LastProfitCL(int op=-1){ //"op" позиция (-1 любая позиция)
double LastProfit=0;
for(i=OrdersHistoryTotal()-1;i>=0;i--)
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && (OrderType()==OP_BUY || OrderType()==OP_SELL) && OrderSymbol()==Symbol() && OrderMagicNumber()==magic) {
if (OrderType()!= op || OrderSymbol()!= Symbol() || OrderMagicNumber()!= magic) continue;
if (op<0 || OrderType()==op)
{
if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
return(LastProfit);
}
It's not the same for you either.
The t variable will change and you'll be aghast.
It has to be memorized before the series closes.
Have you tried it?
It's memorized before closing, at the moment the signal to close.
It is not suitable, there is no information for 10 years.
Current profit, , all history.
By the way, it can be set to any date and time.
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();
}}}}
}
Profit remembers every new one, but then something counts unknown. In screen #3 it should be 4, not 190
Have you tried it?
It remembers before it closes, at the moment the closing signal is received
That, too, 190
Profit remembers every new one, but then something counts unknown. In screen #3 it should be 4, not 190
Here's the code, it works fine for me, but maybe because the series is closed correctly
So also 190
Where is the command to close orders located?
Did you write the variable t in there?
Where is the command to close orders located?
Have you written the variable t in there?
t=TimeCurrent();//place in the signal block for closing a series of ordersIt's all there of course.
t=OrderCloseTime();
if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();
It's all there, of course.
t=OrderCloseTime();
if(OrderCloseTime()>=t)LastProfit+=OrderProfit()+OrderCommission()+OrderSwap();
No, this line is removed. This is already a profit calculation, it won't work that way.
Where the command to close in the code - there, but not such a line
Read above.