Hi,
I want to get the number of positions with different data in the comment column from different symbols.
For example; How many open positions are there in the EURUSD symbol with "MA BUY" in the comment column?
There is the code I wrote in the attachment. Where am I making a mistake?
I would appreciate your help.
Files:
IMG_20201217_194103_307.jpg
22 kb
- Comment Help
- Questions from a "dummy"
- How to check magic numbers of open positions
Gökhan Erdoğdu :
Hi,
Hi,
I want to get the number of positions with different data in the comment column from different symbols.
For example; How many open positions are there in the EURUSD symbol with "MA BUY" in the comment column?
There is the code I wrote in the attachment. Where am I making a mistake?
I would appreciate your help.
Paste the code correctly: use the button
Vladimir Karputov:
Paste the code correctly: use the button
//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { Comment(ToplamPsarBuy()); } //+------------------------------------------------------------------+ //| ToplamPsarBuy | //+------------------------------------------------------------------+ int ToplamPsarBuy() { int i=0; int toplam=0; for(i; i<PositionsTotal(); i++) { int ticket=PositionGetTicket(i); string symbol=PositionGetSymbol(i); PositionSelectByTicket(ticket); PositionSelect(symbol); if(PositionGetString(POSITION_COMMENT)=="PSAR BUY") {toplam=toplam+1;} } return(toplam); }
Gökhan Erdoğdu:
Use code:
//+------------------------------------------------------------------+ //| 1.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property script_show_inputs //--- #include <Trade\PositionInfo.mqh> //--- CPositionInfo m_position; // object of CPositionInfo class //--- input parameters input string InpComment = "PSAR BUY"; // Comment //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- int all_positions=CalculateAllPositions(InpComment); //--- } //+------------------------------------------------------------------+ //| Calculate all positions | //+------------------------------------------------------------------+ int CalculateAllPositions(const string &comment) { int total=0; for(int i=PositionsTotal()-1; i>=0; i--) if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties if(m_position.Comment()==comment) total++; //--- return(total); } //+------------------------------------------------------------------+
Files:
1.mq5
4 kb
Vladimir Karputov:
Thank you. I will try.
Use code:

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