//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- demande l'historique des transactions et des ordres
if(!HistorySelect(0, TimeCurrent()))
{
Print("HistorySelect() failed. Error ", GetLastError());
return;
}
//--- en boucle sur la liste des transactions dans l'historique du compte
int total=HistoryDealsTotal();
for(int i=0; i<total; i++)
{
//--- obtient le ticket de la prochaine transaction (la transaction est automatiquement sélectionnée pour obtenir ses propriétés)
ulong ticket=HistoryDealGetTicket(i);
if(ticket==0)
continue;
//--- obtient le type et l'orientation de la transaction et affiche l'en-tête de la liste des propriétés de la transaction sélectionnée
string type=DealTypeDescription((ENUM_DEAL_TYPE)HistoryDealGetInteger(ticket, DEAL_TYPE));
string entry=DealEntryDescription((ENUM_DEAL_ENTRY)HistoryDealGetInteger(ticket, DEAL_ENTRY));
PrintFormat("String properties of an deal %s entry %s #%I64u:", type, entry, ticket);
//--- affiche toutes les propriétés de la transaction sélectionnée sous l'en-tête
HistoryDealPropertiesStringPrint(ticket, 13);
}
/*
résultat :
String properties of an deal Buy entry In #2785021084:
Symbol: EURUSD
Comment: Test PositionGetString
External ID:
String properties of an deal Buy entry Out #2497993663:
Symbol: EURUSD
Comment: [tp 1.08639]
External ID:
*/
}
//+------------------------------------------------------------------+
//| Affiche dans le journal les propriétés réelles de la transaction |
//+------------------------------------------------------------------+
void HistoryDealPropertiesStringPrint(const ulong ticket, const uint header_width=0)
{
uint w=0;
string header="";
string value ="";
//--- définit le texte d'en-tête et la largeur du champ d'en-tête
//--- si la largeur de l'en-tête est passée à la fonction égale à zéro, alors la largeur sera la taille de la ligne d'en-tête + 1
header="Symbol:";
w=(header_width==0 ? header.Length()+1 : header_width);
//--- récupère et affiche dans le journal le symbole de la transaction avec la largeur d'en-tête spécifiée
if(!HistoryDealGetString(ticket, DEAL_SYMBOL, value))
return;
PrintFormat("%-*s%-s", w, header, value);
//--- affiche le commentaire de la transaction dans le journal
header="Comment:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryDealGetString(ticket, DEAL_COMMENT, value))
return;
PrintFormat("%-*s%-s", w, header, value);
//--- affiche l'identifiant de la transaction dans un système de trading externe
header="Extarnal ID:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryDealGetString(ticket, DEAL_EXTERNAL_ID, value))
return;
PrintFormat("%-*s%-s", w, header, value);
}
//+------------------------------------------------------------------+
//| Retourne la description du type de la transaction |
//+------------------------------------------------------------------+
string DealTypeDescription(const ENUM_DEAL_TYPE type)
{
switch(type)
{
case DEAL_TYPE_BUY : return("Buy");
case DEAL_TYPE_SELL : return("Sell");
case DEAL_TYPE_BALANCE : return("Balance");
case DEAL_TYPE_CREDIT : return("Credit");
case DEAL_TYPE_CHARGE : return("Additional charge");
case DEAL_TYPE_CORRECTION : return("Correction");
case DEAL_TYPE_BONUS : return("Bonus");
case DEAL_TYPE_COMMISSION : return("Additional commission");
case DEAL_TYPE_COMMISSION_DAILY : return("Daily commission");
case DEAL_TYPE_COMMISSION_MONTHLY : return("Monthly commission");
case DEAL_TYPE_COMMISSION_AGENT_DAILY : return("Daily agent commission");
case DEAL_TYPE_COMMISSION_AGENT_MONTHLY: return("Monthly agent commission");
case DEAL_TYPE_INTEREST : return("Interest rate");
case DEAL_TYPE_BUY_CANCELED : return("Canceled buy deal");
case DEAL_TYPE_SELL_CANCELED : return("Canceled sell deal");
case DEAL_DIVIDEND : return("Dividend operations");
case DEAL_DIVIDEND_FRANKED : return("Franked (non-taxable) dividend operations");
case DEAL_TAX : return("Tax charges");
default : return("Unknown deal type: "+(string)type);
}
}
//+------------------------------------------------------------------+
//| Retourne la méthodde de changement de position |
//+------------------------------------------------------------------+
string DealEntryDescription(const ENUM_DEAL_ENTRY entry)
{
switch(entry)
{
case DEAL_ENTRY_IN : return("In");
case DEAL_ENTRY_OUT : return("Out");
case DEAL_ENTRY_INOUT : return("Reverce");
case DEAL_ENTRY_OUT_BY : return("Out by");
case DEAL_ENTRY_STATE : return("Status record");
default : return("Unknown deal entry: "+(string)entry);
}
}
|