Thanks for the help everyone. I'm using the custom mql code block as I can code a little. I'm trying to output all deals (ENTRY_IN and ENTRY_OUT) and eventually I will be logging the indicator values at time of entry and exit.
At the moment it is only logging DEAL_ENTRY_OUT deals. Can anyone see what I'm doing wrong? The code is a follows and under On trade.
//===========================================
// FXDreema On Trade Custom Block Logger
//===========================================
// static variable to track last logged deal
static ulong last_logged_deal = 0;
// get total number of deals
int total_deals = HistoryDealsTotal();
if(total_deals <= 0)
return;
// get the latest deal ticket
ulong deal_ticket = HistoryDealGetTicket(total_deals - 1);
if(deal_ticket == 0)
return;
// avoid logging the same deal twice
if(deal_ticket == last_logged_deal)
return;
last_logged_deal = deal_ticket;
// select the deal
if(!HistoryDealSelect(deal_ticket))
return;
//-------------------------------------------
// get deal info
//-------------------------------------------
ulong deal_order = HistoryDealGetInteger(deal_ticket, DEAL_ORDER);
ulong position_id = HistoryDealGetInteger(deal_ticket, DEAL_POSITION_ID);
string symbol = HistoryDealGetString(deal_ticket, DEAL_SYMBOL);
long deal_type_i = HistoryDealGetInteger(deal_ticket, DEAL_TYPE);
long deal_entry_i = HistoryDealGetInteger(deal_ticket, DEAL_ENTRY);
long deal_reason_i = HistoryDealGetInteger(deal_ticket, DEAL_REASON);
datetime deal_time = (datetime)HistoryDealGetInteger(deal_ticket, DEAL_TIME);
double volume = HistoryDealGetDouble(deal_ticket, DEAL_VOLUME);
double profit = HistoryDealGetDouble(deal_ticket, DEAL_PROFIT);
double price = HistoryDealGetDouble(deal_ticket, DEAL_PRICE);
double swap = HistoryDealGetDouble(deal_ticket, DEAL_SWAP);
double commission = HistoryDealGetDouble(deal_ticket, DEAL_COMMISSION);
long magic = HistoryDealGetInteger(deal_ticket, DEAL_MAGIC);
string comment = HistoryDealGetString(deal_ticket, DEAL_COMMENT);
//-------------------------------------------
// get current market prices
//-------------------------------------------
double bid = SymbolInfoDouble(symbol, SYMBOL_BID);
double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);
double spread = ask - bid;
//-------------------------------------------
// convert enums to readable strings
//-------------------------------------------
string deal_type = "";
switch(deal_type_i)
{
case DEAL_TYPE_BUY: deal_type="DEAL_TYPE_BUY"; break;
case DEAL_TYPE_SELL: deal_type="DEAL_TYPE_SELL"; break;
case DEAL_TYPE_BALANCE: deal_type="DEAL_TYPE_BALANCE"; break;
case DEAL_TYPE_CREDIT: deal_type="DEAL_TYPE_CREDIT"; break;
default: deal_type="OTHER";
}
string deal_entry = "";
switch(deal_entry_i)
{
case DEAL_ENTRY_IN: deal_entry="DEAL_ENTRY_IN"; break;
case DEAL_ENTRY_OUT: deal_entry="DEAL_ENTRY_OUT"; break;
case DEAL_ENTRY_INOUT: deal_entry="DEAL_ENTRY_INOUT"; break;
default: deal_entry="OTHER";
}
string deal_reason = "";
switch(deal_reason_i)
{
case DEAL_REASON_EXPERT: deal_reason="DEAL_REASON_EXPERT"; break;
case DEAL_REASON_SL: deal_reason="DEAL_REASON_SL"; break;
case DEAL_REASON_TP: deal_reason="DEAL_REASON_TP"; break;
case DEAL_REASON_SO: deal_reason="DEAL_REASON_SO"; break;
case DEAL_REASON_CLIENT: deal_reason="DEAL_REASON_CLIENT"; break;
default: deal_reason=IntegerToString(deal_reason_i);
}
//-------------------------------------------
// write to CSV
//-------------------------------------------
int file = FileOpen("MyStrategy.csv",
FILE_READ|FILE_WRITE|FILE_CSV|FILE_SHARE_WRITE|FILE_COMMON, ",");
if(file != INVALID_HANDLE)
{
FileSeek(file,0,SEEK_END);
FileWrite(file,
deal_ticket,
deal_order,
position_id,
symbol,
deal_type,
deal_entry,
deal_reason,
TimeToString(deal_time,TIME_DATE|TIME_SECONDS),
DoubleToString(volume,2),
DoubleToString(profit,2),
DoubleToString(price,_Digits),
DoubleToString(swap,2),
DoubleToString(commission,2),
magic,
comment,
DoubleToString(bid,_Digits),
DoubleToString(ask,_Digits),
DoubleToString(spread,_Digits)
);
FileClose(file);
}