//+------------------------------------------------------------------+
//| 스크립트 프로그램 시작 함수 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 거래와 주문 히스토리 요청
if(!HistorySelect(0, TimeCurrent()))
{
Print("HistorySelect() failed. Error ", GetLastError());
return;
}
//--- 계정 히스토리의 거래 목록에 의한 루프
int total=HistoryDealsTotal();
for(int i=0; i<total; i++)
{
//--- 다음 거래 티켓 가져오기(해당 속성을 가져오기 위해 거래가 자동으로 선택됨)
ulong ticket=HistoryDealGetTicket(i);
if(ticket==0)
continue;
//--- 거래의 유형과 방향을 가져오고 선택한 거래의 실제 속성 목록에 대한 헤더를 표시합니다.
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);
//--- 헤더 아래에 선택한 거래의 실제 속성을 모두 인쇄합니다.
HistoryDealPropertiesStringPrint(ticket, 13);
}
/*
결과:
String properties of an deal Buy entry In #2785021084:
Symbol: EURUSD
Comment: Test PositionGetString
Extarnal ID:
String properties of an deal Buy entry Out #2497993663:
Symbol: EURUSD
Comment: [tp 1.08639]
Extarnal ID:
*/
}
//+------------------------------------------------------------------+
//| 저널에서 선택한 거래의 문자열 속성을 표시합니다. |
//+------------------------------------------------------------------+
void HistoryDealPropertiesStringPrint(const ulong ticket, const uint header_width=0)
{
uint w=0;
string header="";
string value ="";
//--- 헤더 텍스트와 헤더 필드의 너비를 정의합니다.
//--- 헤더 너비가 0과 같은 함수에 전달되면 너비는 헤더 줄 크기 + 1이 됩니다.
header="Symbol:";
w=(header_width==0 ? header.Length()+1 : header_width);
//--- 저널에 지정된 헤더 너비를 가진 거래 심볼을 가져오고 표시합니다.
if(!HistoryDealGetString(ticket, DEAL_SYMBOL, value))
return;
PrintFormat("%-*s%-s", w, header, value);
//--- 거래 코멘트를 저널에 표시합니다.
header="Comment:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryDealGetString(ticket, DEAL_COMMENT, value))
return;
PrintFormat("%-*s%-s", w, header, value);
//--- 외부 거래 시스템에 거래 ID를 표시합니다.
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);
}
//+------------------------------------------------------------------+
//| 거래 타입 설명을 반환 |
//+------------------------------------------------------------------+
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);
}
}
//+------------------------------------------------------------------+
//| 포지션 변경 메서드 반환 |
//+------------------------------------------------------------------+
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);
}
}
|