212 lines
15 KiB
MQL5
212 lines
15 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| estudo.mq5 |
|
|
//| Copyright 2021, MetaQuotes Ltd. |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
//---
|
|
//PrintFormat("saldo %.2f",CompleteProfit(0,-1,"")); //0071234569379273
|
|
// PrintFormat("saldo rápido %.2f",FastProfit());
|
|
PrintFormat("Historico completo %.2f",CompleteHistoric(0,""));
|
|
PrintFormat("Historico mensal %.2f",CompleteHistoric(0,"mês"));
|
|
// PrintFormat("Escolha %f ",opcoes(2));
|
|
// PrintFormat("Valor de lote requerido = %f feito = %f",0.0123,0.0123-MathMod(0.0123,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)));
|
|
// datetime dia = TimeCurrent();
|
|
// Print("Time",Tim());
|
|
|
|
//---
|
|
for(int i=0; i<10; i++)
|
|
{
|
|
// Print(rand()%2);
|
|
}
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//---
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Expert tick function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
//---
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Trade function |
|
|
//+------------------------------------------------------------------+
|
|
void OnTrade()
|
|
{
|
|
//---
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| ChartEvent function |
|
|
//+------------------------------------------------------------------+
|
|
void OnChartEvent(const int id,
|
|
const long &lparam,
|
|
const double &dparam,
|
|
const string &sparam)
|
|
{
|
|
//---
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| BookEvent function |
|
|
//+------------------------------------------------------------------+
|
|
void OnBookEvent(const string &symbol)
|
|
{
|
|
//---
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
double FastProfit()
|
|
{
|
|
return(AccountInfoDouble(ACCOUNT_EQUITY)-AccountInfoDouble(ACCOUNT_BALANCE));
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
double CompleteProfit(long magic,ENUM_POSITION_TYPE tipo, string simbolo)
|
|
{
|
|
double saldo=0;
|
|
|
|
|
|
for(int i=0; i<PositionsTotal(); i++)
|
|
{
|
|
PositionGetSymbol(i);
|
|
|
|
long a =PositionGetInteger(POSITION_IDENTIFIER);
|
|
long b =PositionGetInteger(POSITION_TICKET);
|
|
Comment(a);
|
|
if(magic == 0 || magic ==PositionGetInteger(POSITION_MAGIC))
|
|
{
|
|
if(tipo==-1 || tipo==PositionGetInteger(POSITION_TYPE))
|
|
{
|
|
if(simbolo =="" || simbolo==PositionGetString(POSITION_SYMBOL))
|
|
{
|
|
saldo += PositionGetDouble(POSITION_PROFIT)+PositionGetDouble(POSITION_SWAP);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return(saldo);
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
double CompleteHistoric(ulong Magic, string pesquisa)
|
|
{
|
|
double saldo=0;
|
|
HistorySelect(0,TimeCurrent());
|
|
for(int i=0; i<HistoryOrdersTotal(); i++)
|
|
{
|
|
long ticket = HistoryOrderGetTicket(i);
|
|
long identificador= HistoryOrderGetInteger(ticket,ORDER_POSITION_BY_ID);
|
|
// PrintFormat("Ticket %i",ticket);
|
|
// PrintFormat("Ticket %i tipo %i ",ticket,HistoryOrderGetInteger(ticket,ORDER_TYPE));
|
|
double resultado =0;
|
|
|
|
for(int x=0; x<HistoryDealsTotal(); x++)
|
|
{
|
|
long dealticket = HistoryDealGetTicket(x);
|
|
if(ticket == HistoryDealGetInteger(dealticket,DEAL_POSITION_ID))
|
|
{
|
|
//Print(HistoryDealGetString(dealticket,DEAL_SYMBOL)+" "+HistoryDealGetInteger(dealticket,)
|
|
// PrintFormat("Valor %.2f",HistoryDealGetDouble(dealticket,DEAL_PROFIT)+HistoryDealGetDouble(dealticket,DEAL_SWAP));
|
|
if(HistoryDealGetInteger(dealticket,DEAL_MAGIC)==Magic)
|
|
{
|
|
if(pesquisa=="mês")
|
|
{
|
|
MqlDateTime hoje,pesquisaDeal;
|
|
|
|
TimeToStruct(TimeCurrent(),hoje);
|
|
datetime dealdata = HistoryDealGetInteger(dealticket,DEAL_TIME);
|
|
TimeToStruct(dealdata,pesquisaDeal);
|
|
if(hoje.year==pesquisaDeal.year && hoje.mon==pesquisaDeal.mon)
|
|
{
|
|
saldo+=HistoryDealGetDouble(dealticket,DEAL_PROFIT)+HistoryDealGetDouble(dealticket,DEAL_SWAP)+HistoryDealGetDouble(dealticket,DEAL_COMMISSION);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(pesquisa=="semana")
|
|
{
|
|
MqlDateTime hoje,pesquisaDeal;
|
|
|
|
TimeToStruct(TimeCurrent(),hoje);
|
|
datetime dealdata = HistoryDealGetInteger(dealticket,DEAL_TIME);
|
|
TimeToStruct(dealdata,pesquisaDeal);
|
|
if(hoje.year==pesquisaDeal.year && hoje.mon==pesquisaDeal.mon && pesquisaDeal.day>=hoje.day-hoje.day_of_week)
|
|
{
|
|
saldo+=HistoryDealGetDouble(dealticket,DEAL_PROFIT)+HistoryDealGetDouble(dealticket,DEAL_SWAP)+HistoryDealGetDouble(dealticket,DEAL_COMMISSION);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
saldo+=HistoryDealGetDouble(dealticket,DEAL_PROFIT)+HistoryDealGetDouble(dealticket,DEAL_SWAP)+HistoryDealGetDouble(dealticket,DEAL_COMMISSION);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return(saldo);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
bool possonegociar()
|
|
{
|
|
bool liberado = false;
|
|
static datetime trade ;
|
|
if(trade== 0 || trade != iTime(_Symbol,PERIOD_CURRENT,Bars(_Symbol,PERIOD_CURRENT)))
|
|
{
|
|
liberado= true;
|
|
trade = iTime(_Symbol,PERIOD_CURRENT,Bars(_Symbol,PERIOD_CURRENT));
|
|
}
|
|
return(liberado);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
int opcoes(int escolha)
|
|
{
|
|
int numero = 0;
|
|
if(escolha==1)
|
|
{
|
|
numero =4;
|
|
return(7);
|
|
}
|
|
bool verdade = 5/2==10/4;
|
|
if(verdade)
|
|
{
|
|
Print("-------");
|
|
return(14);
|
|
}
|
|
return(numero);
|
|
|
|
}
|
|
//+------------------------------------------------------------------+
|