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
I have never handled the OnTradeTransaction () event before, there was no need to do so as there was no need to consider what triggered in the trading logic. SL or TP. Are you suggesting that this is evidence of my trading experience?)))
I'm reading very carefully, but I don't see anyone giving a sensible answer in the form of a working code. Or is it a great fucking secret and a great wizardry - the secret knowledge and the ability to determine what works?
I do not write EAs to order, especially for FOREX.
You, now, have all the necessary knowledge to write a sensible code,
that meets your needs.
I don't write EAs to order, especially for FOREX.
You now have all the knowledge you need to write a sensible code,
that meets your needs.
And who asked you to write to order?
To ask a question on this forum nowadays means to write to order?
Go to hell, all of you. You are sellers.
...
And if you look at the account history to see the commentary of the last trade, would that be OK?
Something like that:
//| Возвращает причину закрытия позиции по Take Profit |
//+------------------------------------------------------------------+
bool CAccountHistory::IsClosedByTakeProfit(const string symbol)
{
//--- Получим комментарий последней сделки на указанном символе
string last_comment=LastDealComment(symbol);
//--- Если в комментарии есть строка "tp"
if(StringFind(last_comment,"tp",0)>-1)
return(true);
//--- Если нет строки "tp"
return(false);
}
//+------------------------------------------------------------------+
//| Возвращает причину закрытия позиции по Stop Loss |
//+------------------------------------------------------------------+
bool CAccountHistory::IsClosedByStopLoss(const string symbol)
{
//--- Получим комментарий последней сделки на указанном символе
string last_comment=LastDealComment(symbol);
//--- Если в комментарии есть строка "sl"
if(StringFind(last_comment,"sl",0)>-1)
return(true);
//--- Если нет строки "sl"
return(false);
}
//+------------------------------------------------------------------+
//| Возвращает комментарий последней сделки на указанном символе |
//+------------------------------------------------------------------+
string CAccountHistory::LastDealComment(const string symbol)
{
int total_deals =0; // Всего сделок в списке выбранной истории
string deal_symbol =""; // Символ сделки
string deal_comment =""; // Комментарий сделки
//--- Если история сделок получена
if(HistorySelect(0,TimeCurrent()))
{
//--- Получим количество сделок в полученном списке
total_deals=HistoryDealsTotal();
//--- Пройдемся по всем сделкам в полученном списке от последней сделки к первой
for(int i=total_deals-1; i>=0; i--)
{
//--- Получим комментарий сделки
deal_comment=HistoryDealGetString(HistoryDealGetTicket(i),DEAL_COMMENT);
//--- Получим символ сделки
deal_symbol=HistoryDealGetString(HistoryDealGetTicket(i),DEAL_SYMBOL);
//--- Если символ сделки и текущий символ равны, остановим цикл
if(deal_symbol==symbol)
break;
}
}
//---
return(deal_comment);
}
And if you look at the account history to see the commentary of the last transaction, would that be OK?
Something like that:
Thank you kind man!
Probably the most reliable way, given that SL and TP can slip and comparing prices would be useless.
And if you look at the account history to see the commentary of the last transaction, would that be OK?
Something like that:
And if there is no commentary (which is entirely possible)?
This is probably the most reliable way, given that SL and TP can slip and a price comparison would be useless.
{
int OrderType=(int)::HistoryOrderGetInteger(OrderTicket,ORDER_TYPE);
if((OrderType==ORDER_TYPE_BUY) || (OrderType==ORDER_TYPE_SELL))
{
const string OrderComment=HistoryOrderGetString(OrderTicket,ORDER_COMMENT);
const string OrderPrice=::DoubleToString(::HistoryOrderGetDouble(OrderTicket,ORDER_PRICE_OPEN),
(int)::SymbolInfoInteger(HistoryOrderGetString(OrderTicket,ORDER_SYMBOL),SYMBOL_DIGITS));
if(OrderComment=="tp "+OrderPrice)
OrderType=ORDER_TYPE_TAKEPROFIT;
else if(OrderComment=="sl "+OrderPrice)
OrderType=ORDER_TYPE_STOPLOSS;
}
return(OrderType);
}
What if there is no comment (which is entirely possible)?
Quite possible, of course. I use this one for analyzing on the history in the tester, as the easiest and fastest one.
In this case, I have to make and analyze tickets with pending orders. I do not have a ready example at hand.
closing a position .
This is not indiscriminate accusation, but the result of hours of trying to find out (no HistorySelectByPosition and other stuff helps) how everything works. And I'm happy to apologise if I'm wrong. Not to be unfounded, I am showing an Expert Advisor for the tester (it is easier to understand) on the server RoboForexEU-MetaTrader 5, which opens a position, then puts SL and TP levels.
In this EA, SL and TP of a single closed position cannot be defined (in OnDeinit). Is it supposed to do that?
Quite possible, of course. I use this one to analyse the history in the tester, as the easiest and fastest.
And so with pending orders you need to do and analyse tickets. I do not have a ready-made example at hand.
What did not suit you about this method?
if (trans.order != my_order_ticket)
{
//Сработал SL или TP
}
break;
What's wrong with this method?
if (trans.order != my_order_ticket)
{
//Сработал SL или TP
}
break;