Questions from Beginners MQL5 MT5 MetaTrader 5 - page 658
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
Let's check it out with a simple advisor...
There's no need to check. The logic is the same as in MQL4: Profit, Commission and Swap are separate entities.
Now let's check with a simple EA...
Vladimir, the point is that on the four I do this:
swap=OrderSwap();
commission=OrderCommission();
if(swap+commission<0.0) {
costs=NormalizeDouble(MathAbs(((swap+commission)/(SymbolInfoDouble(_symbol,SYMBOL_TRADE_TICK_VALUE)*ol))*_Point),_Digits);
} else {
costs=0.0;
}
// прибавляем количество пипок
if(((Bid-(br+costs+((BreakevenStep*_Point)*D)))>=op) && typ==0)
{
OrderModify(...);
}
How do you do it in five?
Vladimir, the point is that on the four I do this:
swap=OrderSwap();
commission=OrderCommission();
if(swap+commission<0.0) {
costs=NormalizeDouble(MathAbs(((swap+commission)/(SymbolInfoDouble(_symbol,SYMBOL_TRADE_TICK_VALUE)*ol))*_Point),_Digits);
} else {
costs=0.0;
}
// прибавляем количество пипок
if(((Bid-(br+costs+((BreakevenStep*_Point)*D)))>=op) && typ==0)
{
OrderModify(...);
}
How do you do it in five?
Please show it by code, here's a direct code in mql5 and preferably without perversions.
//| Get the property value "POSITION_COMMISSION" |
//+------------------------------------------------------------------+
double CPositionInfo::Commission(void) const
{
return(PositionGetDouble(POSITION_COMMISSION));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_SWAP" |
//+------------------------------------------------------------------+
double CPositionInfo::Swap(void) const
{
return(PositionGetDouble(POSITION_SWAP));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_PROFIT" |
//+------------------------------------------------------------------+
double CPositionInfo::Profit(void) const
{
return(PositionGetDouble(POSITION_PROFIT));
}
It's almost impossible! Pulled from SB, direct code
//| Get the property value "POSITION_COMMISSION" |
//+------------------------------------------------------------------+
double CPositionInfo::Commission(void) const
{
return(PositionGetDouble(POSITION_COMMISSION));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_SWAP" |
//+------------------------------------------------------------------+
double CPositionInfo::Swap(void) const
{
return(PositionGetDouble(POSITION_SWAP));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_PROFIT" |
//+------------------------------------------------------------------+
Forgot to put it in the documentation, but does this"POSITION_COMMISSION" work?
Forum on trading, automated trading systems and trading strategy testing
Bugs, bugs, questions
fxsaber, 2016.07.19 12:40
POSITION_COMMISSION property in the tester (RoboForexEU-MetaTrader 5) always returns zero commission.
Also POSITION_COMMISSION (== 8) is missing in help and meta-editor (highlighting), but is familiar to compiler. The position commission is not difficult to determine using another (working) method. POSITION_COMMISSION property - a rudiment?
{
double Commission = ::PositionGetDouble(POSITION_COMMISSION);
// На случай, если POSITION_COMMISSION не работает
if (Commission == 0)
{
const ulong Ticket = MT4ORDERS::GetPositionDealIn();
if (Ticket > 0)
{
const double LotsIn = ::HistoryDealGetDouble(Ticket, DEAL_VOLUME);
if (LotsIn > 0)
Commission = ::HistoryDealGetDouble(Ticket, DEAL_COMMISSION) * ::PositionGetDouble(POSITION_VOLUME) / LotsIn;
}
}
return(Commission);
}
Forum on trading, automated trading systems and strategy testing
Questions from beginners
fxsaber, 2016.10.29 16:23
I'm not imposing the MT4Orders library. But maybe it would be easier to just call the good old OrderCommission?
Still works not only on hedge accounts but also on net accounts.
Let's check it now with a simple Expert Advisor...
Here:POSITION_PROFIT shows the profit of the position
. It does not take into account swap and the like.
Vladimir, the point is that on the four I do this:
swap=OrderSwap();
commission=OrderCommission();
if(swap+commission<0.0) {
costs=NormalizeDouble(MathAbs(((swap+commission)/(SymbolInfoDouble(_symbol,SYMBOL_TRADE_TICK_VALUE)*ol))*_Point),_Digits);
} else {
costs=0.0;
}
// прибавляем количество пипок
if(((Bid-(br+costs+((BreakevenStep*_Point)*D)))>=op) && typ==0)
{
OrderModify(...);
}
How do I do it in five?
The commission is so unpredictable that it can only be determined in a closed trade. For an open position, you can only find out the current profit (which takes into account neither the impact of swap nor the impact of commissions) and swap. Here is the code:
Put a breakpoint on the line " m_trade.PositionClose(Symbol();" and run the test on history. When the tester stops at the breakpoint, compare the figures in the Profit and Swap columns with the figures that are unwritten in the tester log.
Here:POSITION_PROFIT shows the profit of the position
. It does not take into account swap and the like.
Ok. We got it.
The solution of fxsaber is good, I have applied it.
Basically, I transferred my MQL4 program to MQL5 almost without any problems.
The details are given above.
Thank you very much!