oslib/scr/exemplos/ex-HistorySelectDeals.mq5

59 lines
5 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:15:18 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| ex-HistorySelect.mq5 |
//| Copyright 2019, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
color BuyColor =clrBlue;
color SellColor=clrRed;
//--- hist<EFBFBD>ria do neg<EFBFBD>cio pedido
HistorySelect(0,TimeCurrent());
//--- cria objetos
string name;
uint total=HistoryDealsTotal();
ulong ticket=0;
double price;
double profit;
datetime time;
string symbol;
long type;
long entry;
//--- para todos os neg<EFBFBD>cios
for(uint i=0;i<total;i++)
{
//--- tentar obter ticket neg<EFBFBD>cios
if((ticket=HistoryDealGetTicket(i))>0)
{
//--- obter as propriedades neg<EFBFBD>cios
price =HistoryDealGetDouble(ticket,DEAL_PRICE);
time =(datetime)HistoryDealGetInteger(ticket,DEAL_TIME);
symbol=HistoryDealGetString(ticket,DEAL_SYMBOL);
type =HistoryDealGetInteger(ticket,DEAL_TYPE);
entry =HistoryDealGetInteger(ticket,DEAL_ENTRY);
profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
//--- apenas para o s<EFBFBD>mbolo atual
if(price && time && symbol==Symbol())
{
//--- cria o pre<EFBFBD>o do objeto
name="TradeHistory_Deal_"+string(ticket);
if(entry) ObjectCreate(0,name,OBJ_ARROW_RIGHT_PRICE,0,time,price,0,0);
else ObjectCreate(0,name,OBJ_ARROW_LEFT_PRICE,0,time,price,0,0);
//--- definir propriedades do objeto
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,0);
ObjectSetInteger(0,name,OBJPROP_BACK,0);
ObjectSetInteger(0,name,OBJPROP_COLOR,type?BuyColor:SellColor);
if(profit!=0) ObjectSetString(0,name,OBJPROP_TEXT,"Profit: "+string(profit));
}
}
}
//--- aplicar no gr<EFBFBD>fico
ChartRedraw();
}//+------------------------------------------------------------------+