GG
Look at these functions https://docs.mql4.com/account
and also MarketInfo(Symbol(),MODE_MARGINREQUIRED)
Good Luck
-BB-
GG
Look at these functions https://docs.mql4.com/account
and also MarketInfo(Symbol(),MODE_MARGINREQUIRED)
Good Luck
-BB-
Thanx for your reply,
I´m using this function to calculate how much I´ll loss if all of my orders stop with StopLoss:
double CalculatePossibleLossOfMoney()
{
double oo = 0.0, // OrderOpenPrice
osl = 0.0, // OrderStopLoss
ol = 0.0, // OrderPossibleLoss in Pips
oml = 0.0, // OrderMaximumLoss in [Account Currency]
tml = 0.0, // total maximum loss if ALL OPEN ORDERS Stop with StopLoss
al = AccountLeverage(),
ls = 0.0; // LotSize
for( int i = 0; i < OrdersTotal(); i++ )
{
if( OrderSelect( i, SELECT_BY_POS ) )
if( OrderStopLoss() > 0 )
{
ls = MarketInfo( OrderSymbol(), MODE_LOTSIZE) * OrderLots();
oo = OrderOpenPrice();
osl = OrderStopLoss();
if( OrderType() == OP_BUY )
ol = oo - osl;
else ol = osl - oo;
oml = oo * ol * al * ls;
}
tml += oml;
}
return (tml);
}
So, I don´t know if it´s 100% OK, neither how to calculate this for Crosses, for example, etc...
Any help, suggestion are welcome.
This is exactly what you're looking for:
MarketInfo(Symbol(),MODE_TICKVALUE)
CB
Thank you,
I need to use also ticksize, as you wrote here 'What is a TICK?' ? ie. TV * TS?
[]´s,
Gero.
Thank you,
I need to use also ticksize, as you wrote here 'What is a TICK?' ? ie. TV * TS?
[]´s,
Gero.
No, Phy and I pretty much came to the conclusion that you shouldn't need to use ticksize.
What you will need to do is to use a 10* multiplier for 3/5 digit brokers.
So for a 3/5 digit broker:
(MarketInfo(Symbol(),MODE_TICKVALUE) * 10 * Lots * StopLoss * 100) / AccountBalance()
will yield the risk of the transaction as a % of your balance.
CB
No, Phy and I pretty much came to the conclusion that you shouldn't need to use ticksize.
What you will need to do is to use a 10* multiplier for 3/5 digit brokers.
So for a 3/5 digit broker:
(MarketInfo(Symbol(),MODE_TICKVALUE) * 10 * Lots * StopLoss * 100) / AccountBalance()
will yield the risk of the transaction as a % of your balance.
CB
Thank you,
I´m with a bug in the code somewhere, so I´ll try to correct then I´ll post the final code here, ok?
Very Thanx.
Gero.
No, Phy and I pretty much came to the conclusion that you shouldn't need to use ticksize.
What you will need to do is to use a 10* multiplier for 3/5 digit brokers.
So for a 3/5 digit broker:
(MarketInfo(Symbol(),MODE_TICKVALUE) * 10 * Lots * StopLoss * 100) / AccountBalance()
will yield the risk of the transaction as a % of your balance.
CB
Well, I think we don´t need to correct for Point difference, int the code below If you modify OP_BUY with OP_SELL and OrderStopLoss() with OrderClosePrice(), you will have all current profits (or losses) and it returns the same result as in the Terminal Window, so I think it´s ok?
So here is the code:
double CalculatePossibleLossOfMoney()
{
double oo = 0.0, // OrderOpenPrice
osl = 0.0, // OrderStopLoss
ol = 0.0, // OrderPossibleLoss in Pips
oml = 0.0, // OrderMaximumLoss in [Account Currency]
tml = 0.0, // total maximum loss if ALL OPEN ORDERS Stop with StopLoss
// al = AccountLeverage(),
ls = 0.0, // LotSize
tv = 0.0; // Tick Value
// factor = 1.0; // For diff. in pip size
// if( Digits == 5 || Digits == 3 ) factor = 10.0;
for( int i = 0; i < OrdersTotal(); i++ )
{
if( OrderSelect( i, SELECT_BY_POS ) )
if( OrderStopLoss() > 0 )
{
ls = MarketInfo( OrderSymbol(), MODE_LOTSIZE) * OrderLots();
oo = OrderOpenPrice();
osl = OrderStopLoss();
tv = MarketInfo( OrderSymbol(), MODE_TICKVALUE );
if( OrderType() == OP_BUY )
ol = oo - osl;
else ol = osl - oo;
oml = tv * ol * ls;
}
tml += oml;
}
return(tml);
}
Well, I think we don´t need to correct for Point difference, int the code below If you modify OP_BUY with OP_SELL and OrderStopLoss() with OrderClosePrice(), you will have all current profits (or losses) and it returns the same result as in the Terminal Window, so I think it´s ok?
So here is the code:
...
Yes, we have to account for Point size, and also use MarketInfo(OrderSymbol(), MODE_TICKSIZE), for example for crosses like pair GBPJPY, see new code:
double CalculatePossibleLossOfMoney() { double oo = 0.0, // OrderOpenPrice osl = 0.0, // OrderStopLoss ol = 0.0, // OrderPossibleLoss in Pips oml = 0.0, // OrderMaximumLoss in [Account Currency] tml = 0.0, // total maximum loss if ALL OPEN ORDERS Stop with StopLoss // al = AccountLeverage(), ls = 0.0, // LotSize tv = 0.0, // Tick Value factor = 1.0; // For diff. in pip size if( Digits == 5 || Digits == 3 ) factor = 10.0; for( int i = 0; i < OrdersTotal(); i++ ) { if( OrderSelect( i, SELECT_BY_POS ) ) if( OrderStopLoss() > 0 ) { ls = MarketInfo( OrderSymbol(), MODE_LOTSIZE) * OrderLots(); oo = OrderOpenPrice(); osl = OrderStopLoss(); tv = MarketInfo( OrderSymbol(), MODE_TICKVALUE ) * MarketInfo( Symbol(), MODE_TICKSIZE); if( OrderType() == OP_BUY ) ol = oo - osl; else ol = osl - oo; oml = tv * ol * ls * factor; } tml += oml; } return(tml); }
Any comment?
[]´s,
Gero.
Yes, we have to account for Point size, and also use MarketInfo(OrderSymbol(), MODE_TICKSIZE), for example for crosses like pair GBPJPY, see new code:
...
Oops, some times TICKSIZE = 0, so below is the corrected code:
double CalculatePossibleLossOfMoney() { double oo = 0.0, // OrderOpenPrice osl = 0.0, // OrderStopLoss ol = 0.0, // OrderPossibleLoss in Pips oml = 0.0, // OrderMaximumLoss in [Account Currency] tml = 0.0, // total maximum loss if ALL OPEN ORDERS Stop with StopLoss ls = 0.0, // LotSize tv = 0.0, // Tick Value ts = 0.0, // Tick Size factor = 1.0; // For diff. in pip size if( Digits == 5 || Digits == 3 ) factor = 10.0; for( int i = 0; i < OrdersTotal(); i++ ) { if( OrderSelect( i, SELECT_BY_POS ) ) if( OrderStopLoss() > 0 ) { ls = MarketInfo( OrderSymbol(), MODE_LOTSIZE) * OrderLots(); oo = OrderOpenPrice(); osl = OrderStopLoss(); tv = MarketInfo( OrderSymbol(), MODE_TICKVALUE ); ts = MarketInfo( OrderSymbol(), MODE_TICKSIZE ); if( ts > 0 ) tv *= ts; if( OrderType() == OP_BUY ) ol = oo - osl; else ol = osl - oo; oml = tv * ol * ls * factor; } tml += oml; } return(tml); }
[]´s,
Gero.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello All,
I want to calculate the cost in account currency for 1 lot, so that I can now how much money I will lost/profit for 1 pip move. With this info then I can calculate in advance how much I will lost if stopped with stoploss, or how much I will profit if takeprofit is reached.
Any hint? I´ll code in an EA, so post code if possible.
Thanx.
Gero.