Created
October 3, 2012 08:41
-
-
Save currencysecrets/3825836 to your computer and use it in GitHub Desktop.
MQL4: Calculate Profit or Loss on Trade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This method calculates the profit or loss of a position in the home currency of the account | |
* @param string sym | |
* @param int type 0 = buy, 1 = sell | |
* @param double entry | |
* @param double exit | |
* @param double lots | |
* @result double profit/loss in home currency | |
*/ | |
double calcPL(string sym, int type, double entry, double exit, double lots) { | |
var result; | |
if ( type == 0 ) { | |
result = (exit - entry) * lots * (1 / MarketInfo(sym, MODE_POINT)) * MarketInfo(sym, MODE_TICKVALUE); | |
} else if ( type == 1 ) { | |
result = (entry - exit) * lots * (1 / MarketInfo(sym, MODE_POINT)) * MarketInfo(sym, MODE_TICKVALUE); | |
} | |
return ( result ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for someone who likes to be shorter