//+------------------------------------------------------------------+
//| 스크립트 프로그램 시작 함수 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 모든 계정 포지션에 의한 루프
int total=PositionsTotal();
for(int i=0; i<total; i++)
{
//--- 해당 속성에 액세스할 포지션을 자동으로 선택하여 다음 포지션의 티켓을 가져옵니다.
ulong ticket=PositionGetTicket(i);
if(ticket==0)
continue;
//--- 포지션 유형을 가져오고 포지션 실제 속성 목록에 대한 헤더를 표시
string type=(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE ? "Buy" : "Sell");
PrintFormat("Double properties of an open position %s #%I64u:", type, ticket);
//--- 헤더 아래에서 선택한 포지션의 모든 실제 속성을 인쇄
PositionPropertiesDoublePrint(15);
}
/*
결과:
Double properties of an open position Buy #2807075208:
Volume: 1.00
Price open: 1.10516
StopLoss: 0.00000
TakeProfit: 0.00000
Price current: 1.10518
Swap: 0.00
Profit: 2.00 USD
*/
}
//+------------------------------------------------------------------+
//| 선택한 포지션의 실제 속성을 저널에 표시 |
//+------------------------------------------------------------------+
void PositionPropertiesDoublePrint(const uint header_width=0)
{
uint w=0;
string header="";
double value=0;
//--- 계정 통화, 포지션 심볼 및 심볼의 소수 자릿수를 가져옵니다.
string currency=AccountInfoString(ACCOUNT_CURRENCY);
string symbol =PositionGetString(POSITION_SYMBOL);
int digits =(int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
//--- 헤더 텍스트와 헤더 필드의 너비를 정의합니다.
//--- 헤더 너비가 0과 같은 함수에 전달되면 너비는 헤더 줄 크기 + 1이 됩니다.
header="Volume:";
w=(header_width==0 ? header.Length()+1 : header_width);
//--- 저널에서 지정된 헤더 너비로 포지션 볼륨을 가져오고 표시
if(!PositionGetDouble(POSITION_VOLUME, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- 포지션 가격 값을 저널에 표시
header="Price open:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!PositionGetDouble(POSITION_PRICE_OPEN, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- 저널에 StopLoss 값을 표시
header="StopLoss:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!PositionGetDouble(POSITION_SL, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- 저널에 TakeProfit 값을 표시
header="TakeProfit:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!PositionGetDouble(POSITION_TP, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- Price current 값을 저널에 표시
header="Price current:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!PositionGetDouble(POSITION_PRICE_CURRENT, value))
return;
PrintFormat("%-*s%-.*f", w, header, digits, value);
//--- 누적된 스왑값을 저널에 표시
header="Swap:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!PositionGetDouble(POSITION_SWAP, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- 저널에 현재 수익 값을 표시
header="Profit:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!PositionGetDouble(POSITION_PROFIT, value))
return;
PrintFormat("%-*s%-.2f %s", w, header, value, currency);
}
|