How to get a profit of Nth open position MQL4 / MT4?

How to get a profit of Nth open position MQL4 / MT4?

Manage alerts

Loading saved threads...

Roller · External communityPost link
External question — Stack Overflow Stack Exchange Author: Roller Original post: https://stackoverflow.com/questions/64756956 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I want to create a function that can get random profit open position. For example : a profit of the Last 2 Open Position of overall Total Position a profit of the First 3 Open Position of overall Total Position Below function seems it only gets the First Open Position Profit : double BuyProfit() { Price = 0; datetime EarliestOrder = TimeCurrent(); for(int i = 0; i < OrdersTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS)) { if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if(EarliestOrder > OrderOpenTime()) { EarliestOrder = OrderOpenTime(); Price = OrderProfit()+OrderSwap()+OrderCommission(); } } } } return Price; }
Quote
Report
user3666197 · External communityPost link
External answer — Stack Overflow Stack Exchange Author: user3666197 Original post: https://stackoverflow.com/a/64759966 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Q : "How to get a profit of Nth open position MQL4/MT4?I want to create a function that can get random profit open position." You may take this rapid-prototype to complete your actual logic code: double nthNetPROFIT( const int Nth ) { if ( Nth > OrdersTotal() ) return( EMPTY ); int softCount = 0; double nthNetProfit = EMPTY;, for( int ii = 0; ii < OrdersTotal(); ii++ ) { if ( OrderSelect( ii, SELECT_BY_POS ) ) { if ( OrderType() == OP_BUY // DEPENDS ON ACTUAL LOGIC && OrderSymbol() == Symbol() // DEPENDS ON ACTUAL LOGIC && OrderMagicNumber() == MagicNumber // DEPENDS ON ACTUAL LOGIC ) { ... // DEPENDS ON ACTUAL LOGIC if ( ++softCount == Nth ){ nthNetProfit = OrderProfit() + OrderSwap() + OrderCommission(); break; } } } return( NormalizeDouble( nthNetProfit, 2 ) ); }
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Roller Source score (net votes, not local likes): 2 Original post: https://stackoverflow.com/questions/64756956 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I want to create a function that can get random profit open position. For example : a profit of the Last 2 Open Position of overall Total Position a profit of the First 3 Open Position of overall Total Position Below function seems it only gets the First Open Position Profit : double BuyProfit() { Price = 0; datetime EarliestOrder = TimeCurrent(); for(int i = 0; i < OrdersTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS)) { if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if(EarliestOrder > OrderOpenTime()) { EarliestOrder = OrderOpenTime(); Price = OrderProfit()+OrderSwap()+OrderCommission(); } } } } return Price; }

Cancel quote

Checking account access…