How can i get total position with PositionGetTicket() MQL please someone help me
MQL5 forum
- www.mql5.com
MQL5: Forum on automated trading systems and strategy testing
userdfcv:
How can i get total position with PositionGetTicket() MQL please someone help me
How can i get total position with PositionGetTicket() MQL please someone help me
Hi , start with the positionGetSymbol for the index of the position in the list of positions.
It will automagically select the position for further analysis
int OnInit() { double exposure=getSymbolLots(NULL,false,false); Print("Exposure "+exposure); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick() { } double getSymbolLots(string _symbol_or_null_for_all, bool buy_only, bool sell_only){ double lots=0.0; //loop to all positions for(int i=0;i<PositionsTotal();i++){ //get the symbol of the position at location i and select it too string positionsymbol=PositionGetSymbol(i); //if the position is of interest to us or we accept all symbols if(positionsymbol==_symbol_or_null_for_all||_symbol_or_null_for_all==NULL){ //if its a buy and we want buys , its a sell and we want sells or we want both ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE)PositionGetInteger(POSITION_TYPE); if((buy_only&&type==ORDER_TYPE_BUY)||(sell_only&&type==ORDER_TYPE_SELL)||(!buy_only&&!sell_only)){ //get lots lots+=PositionGetDouble(POSITION_VOLUME); } } } return(lots); };
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