//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- no loop por todas as posições na conta
int total=PositionsTotal();
for(int i=0; i<total; i++)
{
//--- obtemos o ticket da próxima posição, selecionando automaticamente a posição para acessar suas propriedades
ulong ticket=PositionGetTicket(i);
if(ticket==0)
continue;
//--- obtemos o tipo da posição e imprimimos o cabeçalho para a lista de propriedades reais da posição
string type=(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE ? "Buy" : "Sell");
PrintFormat("Double properties of an open position %s #%I64u:", type, ticket);
//--- imprimimos sob o cabeçalho todas as propriedades reais da posição selecionada
PositionPropertiesDoublePrint(15);
}
/*
Resultado:
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
*/
}
//+------------------------------------------------------------------+
//| Imprime no log as propriedades reais da posição selecionada |
//+------------------------------------------------------------------+
void PositionPropertiesDoublePrint(const uint header_width=0)
{
uint w=0;
string header="";
double value=0;
//--- obtemos a moeda da conta, o símbolo da posição e o número de dígitos após a vírgula para o símbolo
string currency=AccountInfoString(ACCOUNT_CURRENCY);
string symbol =PositionGetString(POSITION_SYMBOL);
int digits =(int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
//--- definimos o texto do cabeçalho e a largura do campo de cabeçalho
//--- se a largura do cabeçalho for passada para a função igual a zero, a largura será o tamanho da linha do cabeçalho + 1
header="Volume:";
w=(header_width==0 ? header.Length()+1 : header_width);
//--- obtemos e imprimimos no log o volume da posição com um cabeçalho de largura definida
if(!PositionGetDouble(POSITION_VOLUME, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- imprimimos no log o valor do preço da posição
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);
//--- imprimimos no log o valor do 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);
//--- imprimimos no log o valor do 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);
//--- imprimimos no log o valor do Preço Atua
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);
l//--- imprimimos no log o valor do swap acumulado
header="Swap:";
w=(header_width==0 ? header.Length()+1 : header_width);
if(!PositionGetDouble(POSITION_SWAP, value))
return;
PrintFormat("%-*s%-.2f", w, header, value);
//--- imprimimos no log o valor do lucro atual
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);
}
|