king64: Yes and it works fine! Thank you @nicholi shen
But I have another problem I need to calculate more than one positions' profit with the same comment, I print the profit and it is printing 0 value repeatedly.
For God's sake man, take some pride in your work. That indentation is pure cringe. Also, just like stackoverflow and any other site you'd use to talk programming, post code not screenshots of code!
The first check is redundant since the for loop will never enter if all is <= 0. Also, selecting a position by symbol and magic number is already built into CPositionInfo. Finally, it is not necessary to use continue statements combined with not conditions. Since MT4 build 600 expressions stop being evaluated after it is evident that the if control statement will resolve to false, so you can just use one singe if statement.
Example:
As you see, I even hesitated to exemplify standard libs functions implication, to not to raise more questions/confusion in his head. (So I didn't use C... stuff)
I think the OP ,more than anything else, needs to learn how to tweak with others codes, change them, and see what each code line does. your suggested fine touches are for later.
I Copy/Pasted that snipped from another EA, so of course he can edit it to match his needs. (example: use the process only if 10 or more positions are open...) so : if(all>10) makes sense there.
I believe every question should be answered from the viewpoint of questioner, with a thinking/skills closer to his mind. of course it's his/her obligation to improve beyond that raw answers.
For God's sake man, take some pride in your work. That indentation is pure cringe. Also, just like stackoverflow and any other site you'd use to talk programming, post code not screenshots of code!
As you see, I even hesitated to exemplify standard libs functions implication, to not to raise more questions/confusion in his head. (So I didn't use C... stuff)
I think the OP ,more than anything else, needs to learn how to tweak with others codes, change them, and see what each code line does. your suggested fine touches are for later.
I Copy/Pasted that snipped from another EA, so of course he can edit it to match his needs. (example: use the process only if 10 or more positions are open...) so : if(all>10) makes sense there.
I believe every question should be answered from the viewpoint of questioner, with a thinking/skills closer to his mind. of course it's his/her obligation to improve beyond that raw answers.
I think I have the same problem with selecting more than one position among all positions with some specific properties like Comments, tickets or buy or sell. I use the code attached but it seems it doesn't work correctly. for selecting one position its ok but more than one position with the same identifiers it is showing wrong outcomes.
I want to select all buy positions which have "B1" comment with different Symbols (for example, EURUSD, GBPUSD and USDJPY) and calculate their profit.
//+------------------------------------------------------------------+//|B1 profit calculator Function |//+------------------------------------------------------------------+double B1profit(void){
CPositionInfo pi;
CTrade trade;
double B1Prf=0;
int i,j;
for(i=0;i<CROSS_NUMBER;i++){
for(j=0;j<MAX_LEVEL;j++){
if(pi.SelectByTicket(baseTickets[i][j])&&pi.Comment()=="B1"&&pi.PositionType()==POSITION_TYPE_BUY){
B1Prf += pi.Profit();//+PositionGetDouble(POSITION_SWAP); //*********//commision is omited
}
}
}
return B1Prf;
}
//+------------------------------------------------------------------+
I think I have the same problem with selecting more than one position among all positions with some specific properties like Comments, tickets or buy or sell. I use the code attached but it seems it doesn't work correctly. for selecting one position its ok but more than one position with the same identifiers it is showing wrong outcomes.
I want to select all buy positions which have "B1" comment with different Symbols (for example, EURUSD, GBPUSD and USDJPY) and calculate their profit.
Do you really seriously code like this? Please tell me you're trolling... you're trolling, right?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Yes and it works fine! Thank you @nicholi shen
For God's sake man, take some pride in your work. That indentation is pure cringe. Also, just like stackoverflow and any other site you'd use to talk programming, post code not screenshots of code!
The first check is redundant since the for loop will never enter if all is <= 0. Also, selecting a position by symbol and magic number is already built into CPositionInfo. Finally, it is not necessary to use continue statements combined with not conditions. Since MT4 build 600 expressions stop being evaluated after it is evident that the if control statement will resolve to false, so you can just use one singe if statement.
Example:
For God's sake man, take some pride in your work. That indentation is pure cringe. Also, just like stackoverflow and any other site you'd use to talk programming, post code not screenshots of code!
ok sorry, here it is.
ok sorry, here it is.
Nice troll bro
Nice troll bro
solved!
thank you guys.
hey guys
I think I have the same problem with selecting more than one position among all positions with some specific properties like Comments, tickets or buy or sell. I use the code attached but it seems it doesn't work correctly. for selecting one position its ok but more than one position with the same identifiers it is showing wrong outcomes.
I want to select all buy positions which have "B1" comment with different Symbols (for example, EURUSD, GBPUSD and USDJPY) and calculate their profit.hey guys
I think I have the same problem with selecting more than one position among all positions with some specific properties like Comments, tickets or buy or sell. I use the code attached but it seems it doesn't work correctly. for selecting one position its ok but more than one position with the same identifiers it is showing wrong outcomes.
I want to select all buy positions which have "B1" comment with different Symbols (for example, EURUSD, GBPUSD and USDJPY) and calculate their profit.Do you really seriously code like this? Please tell me you're trolling... you're trolling, right?
Do you really seriously code like this? Please tell me you're trolling... you're trolling, right?