آکادمی ایران ام کیو ال ‹ انجمن ‹ سوالات MQL5 ‹ اختصاص سود یک معامله هج برای بستن قسمتی از حجم معامله جهت عکس ‹ Reply To: اختصاص سود یک معامله هج برای بستن قسمتی از حجم معامله جهت عکس
-
//+------------------------------------------------------------------+
//| TradeTransaction function |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
const MqlTradeRequest& request,
const MqlTradeResult& result)
{
// Get transaction type as enumeration value
ENUM_TRADE_TRANSACTION_TYPE type = trans.type;
// If transaction is result of addition of the transaction in history
if(type == TRADE_TRANSACTION_DEAL_ADD)
{
ResetLastError();
if(HistoryDealSelect(trans.deal))
m_deal.Ticket(trans.deal);
else
{
Print(__FILE__, " ", __FUNCTION__, ", ERROR: ", "HistoryDealSelect(", trans.deal, ") error: ", GetLastError());
return;
}
if(m_deal.DealType() == DEAL_TYPE_BUY || m_deal.DealType() == DEAL_TYPE_SELL)
{
if(m_deal.Entry() == DEAL_ENTRY_OUT)
{
long position_id = m_deal.PositionId();
if(HistorySelectByPosition(position_id))
{
uint total = HistoryDealsTotal();
ulong ticket = 0;
// For all deals
for(uint i=0; i<MathMax(total, 10); i++)
{
// Try to get deals ticket
if((ticket=HistoryDealGetTicket(i))>0)
{
if(HistoryDealGetString(ticket, DEAL_SYMBOL) == Symbol() && HistoryDealGetInteger(ticket, DEAL_MAGIC) == MagicNumber && HistoryDealGetInteger(ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT)
{
if(HistoryDealGetDouble(ticket, DEAL_PROFIT) > 0)
{
TT = HistoryDealGetDouble(ticket, DEAL_PROFIT)- HistoryDealGetDouble(ticket, DEAL_VOLUME)* 100;
DealType = HistoryDealGetInteger(ticket, DEAL_TYPE);
ApplyTT(TT, DealType);
}
}
}
}
}
}
}
}
}