//+------------------------------------------------------------------+
//| 스크립트 프로그램 시작 함수 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 거래와 주문 히스토리 요청
if(!HistorySelect(0, TimeCurrent()))
{
Print("HistorySelect() failed. Error ", GetLastError());
return;
}
//--- 계정의 모든 과거 주문 목록에 의한 루프
int total=HistoryOrdersTotal();
for(int i=0; i<total; i++)
{
//--- 루프 인덱스를 통해 리스트에서 주문 티켓 가져오기
ulong ticket=HistoryOrderGetTicket(i);
if(ticket==0)
continue;
//--- 주문 유형을 가져오고 선택한 주문의 실제 속성 목록에 대한 헤더를 표시합니다.
string type=OrderTypeDescription((ENUM_ORDER_TYPE)HistoryOrderGetInteger(ticket, ORDER_TYPE));
PrintFormat("Double properties of an history order %s #%I64u:", type, ticket);
//--- 헤더 아래에서 선택한 주문의 모든 실제 속성을 인쇄합니다.
HistoryOrderPropertiesDoublePrint(ticket, 16);
}
/*
결과:
Double properties of an history order Sell #2810847541:
Volume initial: 0.50
Volume current: 0.00
Price open: 1.10491
StopLoss: 0.00000
TakeProfit: 0.00000
Price current: 1.10491
StopLimit: 0.00000
Double properties of an history order Buy Limit #2811003507:
Volume initial: 1.00
Volume current: 1.00
Price open: 1.10547
StopLoss: 0.00000
TakeProfit: 0.00000
Price current: 1.10591
StopLimit: 0.00000
*/
}
//+------------------------------------------------------------------+
//| 저널에서 선택한 주문 히스토리의 실제 속성을 표시 |
//+------------------------------------------------------------------+
void HistoryOrderPropertiesDoublePrint(const long ticket, const uint header_width=0)
{
uint w=0;
string header="";
double value=0;
//--- 주문 심볼과 심볼의 소수 자릿수를 가져옵니다.
string symbol = HistoryOrderGetString(ticket, ORDER_SYMBOL);
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
//--- 헤더 텍스트와 헤더 필드의 너비를 정의합니다.
//--- 헤더 너비가 0과 같은 함수에 전달되면 너비는 헤더 줄 크기 + 1이 됩니다.
header="Volume initial:";
w=(header_width==0 ? header.Length()+1 : header_width);
//--- 저널에서 지정된 너비의 헤더로 주문할 때 초기 볼륨을 가져오고 표시
if(!HistoryOrderGetDouble(ticket, ORDER_VOLUME_INITIAL, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- 미체결 주문량을 저널에 표시
header="Volume current:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_VOLUME_CURRENT, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- 주문에서 지정한 가격을 저널에 표시
header="Price open:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_PRICE_OPEN, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- 저널에 StopLoss 레벨을 표시
header="StopLoss:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_SL, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- 저널에 TakeProfit 레벨을 표시
header="TakeProfit:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_TP, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- 저널의 주문 심볼로 현재 가격을 표시
header="Price current:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_PRICE_CURRENT, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- StopLimit 주문이 활성화되면 지정가 주문 가격을 저널에 표시
header="StopLimit:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!HistoryOrderGetDouble(ticket, ORDER_PRICE_STOPLIMIT, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
}
//+------------------------------------------------------------------+
//| 주문 유형 설명을 반환 |
//+------------------------------------------------------------------+
string OrderTypeDescription(const ENUM_ORDER_TYPE type)
{
switch(type)
{
case ORDER_TYPE_BUY : return("Buy");
case ORDER_TYPE_SELL : return("Sell");
case ORDER_TYPE_BUY_LIMIT : return("Buy Limit");
case ORDER_TYPE_SELL_LIMIT : return("Sell Limit");
case ORDER_TYPE_BUY_STOP : return("Buy Stop");
case ORDER_TYPE_SELL_STOP : return("Sell Stop");
case ORDER_TYPE_BUY_STOP_LIMIT : return("Buy Stop Limit");
case ORDER_TYPE_SELL_STOP_LIMIT : return("Sell Stop Limit");
default : return("Unknown order type");
}
}
|