Biblioteca2/Include/defs.mqh

567 lines
43 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 14:43:36 +02:00
<EFBFBD><EFBFBD>enum ENUM_OP_TYPES
{
Buy=0,
Sell=1,
None=2
};
enum ENUM_STOP_TYPES
{
Fluctuation=0,
Minimum=1,
Maximum=2,
Mean=3,
Fixed=4
};
enum MODEL_TYPES
{
Buy_hold,//Compra e segura
Sell_hold,//Venda e segura
Tendencia,//Tend<EFBFBD>ncia
Retorno,//Retorno
Gap_alta_baixa,//Modelo de Gap
Python_scripts,//Scripts Python
Buy_hold_sell_neutral//Compra e segura, vende para neutralizar
};
enum Neutralization_TYPES
{
NTTotal=0,//Total
NTBeta=1,//Beta
NTPearson=2,//Pearson
NTRisco=3,//Risco
NTBetaRisco=4,//Beta*Risco
NTPearsonRisco=5//Pearson*Risco
};
enum Periodicity
{
Mes=27*24*3600,
Dias15=15*24*3600,
Dias7=7*24*3600,
Dia=24*3600,
Horas4=4*3600,
Hora=3600,
Minutos30=1800,
Minutos15=900,
Minutos10=600,
Minutos5=300,
Minutos2=120,
Minuto=60,
Segundos30=30,
Segundos10=10
};
enum RankTypes
{
RTRent,//Rentabilidade
RTRent_atr,//Rentabilidade/atr
RTRent_mvol,//Rentabilidade/stddev
RTRent_atr_mvol,//Rentabilidade/stdrel
RTHighVolidx,//Alta volatilidade ATR
RTLowVolidx,//Baixa volatilidade 1.0/ATR
RTHighLiq,//Alto volume financeiro
RTLowLiq,//Baixo volume financeiro
RTHighNeg,//Alto volume de neg<EFBFBD>cios
RTLowNeg,//Baixo volume de neg<EFBFBD>cios
RTHighGap,//Maiores gaps de abertura
RTLowGap,//Menores gaps de abertura
RTHighGapLow,//Menores gaps de m<EFBFBD>nimo
RTLowGapLow,//Elasticidade
RTInvRent,//1/|Rentabilidade|
RTAleatory,//Aleat<EFBFBD>rio
RTHighVolstd,//Alta volatilidade desvio padr<EFBFBD>o
RTLowVolstd,//Baixa volatilidade 1.0/desvio padr<EFBFBD>o
RTHighVolrel,//Alta volatilidade desvio padr<EFBFBD>o relativo
RTLowVolrel,//Baixa volatilidade 1.0/desvio padr<EFBFBD>o relativo
RTLowVolatrpr,//Baixa volatilidade pre<EFBFBD>o/atr
RTLowVolstdpr,//Baixa volatilidade pre<EFBFBD>o/desvio padr<EFBFBD>o
RTHighCorre,//Alta correla<EFBFBD><EFBFBD>o com IBOV
RTLowCorre,//Baixa correla<EFBFBD><EFBFBD>o com IBOV
RTHighPr,//Alta pre<EFBFBD>o de fechamento
RTLowPr//Baixo pre<EFBFBD>o de fechamento
};
enum RankSelectTypes
{
RSTFixed,//N<EFBFBD>mero fixo
RSTCharge,//Seleciona at<EFBFBD> esgotar o capital
RSTPositive,//Seleciona somente os positivos
RSTAll//Seleciona todos
};
enum VolumeTypes
{
VTFixed_Lots,//Quantidade fixa de lotes
VTFixed_Money,//Capital dividido igualmente na carteira
VTOptim_ATR,//Otimiza<EFBFBD><EFBFBD>o usando ATR
VTOptim_Sigma,//Otimiza<EFBFBD><EFBFBD>o usando sigma(Pre<EFBFBD>o)
VTOptim_SigmaRel,//Otimiza<EFBFBD><EFBFBD>o usando sigma(ln(Pre<EFBFBD>o))
VTOptim_ATRRel,//Otimiza<EFBFBD><EFBFBD>o usando ATR/Pre<EFBFBD>o
VTOptim_SigmaPrice//Otimiza<EFBFBD><EFBFBD>o usando sigma(Pre<EFBFBD>o)/Pre<EFBFBD>o
};
enum OrderTypes//tipos de ordens pendentes
{
OTNone,//Nenhum
OTOpen,//Ordem pendente para abertura
OTSL,//Ordem pendente para SL
OTTP,//Ordem pendente para TP
OTClose//Ordem pendente para fechamento
};
void MyPrint(string p1)
{if (UseTelegram) StringConcatenate(TelegramBuffer,TelegramBuffer,p1,"\n");Print(p1);}
void MyPrint(string p1,string p2)
{if (UseTelegram) StringConcatenate(TelegramBuffer,TelegramBuffer,p1,p2,"\n");Print(p1,p2);}
void MyPrint(string p1,string p2,string p3)
{if (UseTelegram) StringConcatenate(TelegramBuffer,TelegramBuffer,p1,p2,p3,"\n");Print(p1,p2,p3);}
void MyPrint(string p1,string p2,string p3,string p4)
{if (UseTelegram) StringConcatenate(TelegramBuffer,TelegramBuffer,p1,p2,p3,p4,"\n");Print(p1,p2,p3,p4);}
void MyPrint(string p1,string p2,string p3,string p4,string p5)
{if (UseTelegram) StringConcatenate(TelegramBuffer,TelegramBuffer,p1,p2,p3,p4,p5,"\n");Print(p1,p2,p3,p4,p5);}
void MyPrint(string p1,string p2,string p3,string p4,string p5,string p6)
{if (UseTelegram) StringConcatenate(TelegramBuffer,TelegramBuffer,p1,p2,p3,p4,p5,p6,"\n");Print(p1,p2,p3,p4,p5,p6);}
void MyPrint(string p1,string p2,string p3,string p4,string p5,string p6,string p7)
{if (UseTelegram) StringConcatenate(TelegramBuffer,TelegramBuffer,p1,p2,p3,p4,p5,p6,p7,"\n");Print(p1,p2,p3,p4,p5,p6,p7);}
void MyPrint(string p1,string p2,string p3,string p4,string p5,string p6,string p7,string p8)
{if (UseTelegram) StringConcatenate(TelegramBuffer,TelegramBuffer,p1,p2,p3,p4,p5,p6,p7,p8,"\n");Print(p1,p2,p3,p4,p5,p6,p7,p8);}
void MyPrint(string p1,string p2,string p3,string p4,string p5,string p6,string p7,string p8,string p9)
{if (UseTelegram) StringConcatenate(TelegramBuffer,TelegramBuffer,p1,p2,p3,p4,p5,p6,p7,p8,p9,"\n");Print(p1,p2,p3,p4,p5,p6,p7,p8,p9);}
void MyPrint(string p1,string p2,string p3,string p4,string p5,string p6,string p7,string p8,string p9,string p10)
{if (UseTelegram) StringConcatenate(TelegramBuffer,TelegramBuffer,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,"\n");Print(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10);}
input bool Forex1 = false;//Desabilita hor<EFBFBD>rio de abertura
input bool Forex2 = false;//Desabilita day trade
input bool SaveTable=false;//Salva a tabela
input bool SaveData=false;//Coleta e grava<EFBFBD><EFBFBD>o de dados
input Periodicity SaveDataPeriod=Dia;//per<EFBFBD>odo da coleta de dados
input bool UseBook=false;//Usar o book para rodar ontick
input string SaveSymbolRef="IBOV";//Ativo refer<EFBFBD>ncia para coleta de dados/relat<EFBFBD>rio do tester
input bool MakePdf=false;//Gerar pdf com relat<EFBFBD>rio do teste
input bool UseAssetLock=false;//Usar trava de ativos
input int EAMAGIC=100;//magic para a trava de ativos
input bool PosTake=true;//habilitar hierarquia e tomada de posi<EFBFBD><EFBFBD>o
//input string lA2="-----------------------Bloco estrat<00>gia esgotamento-----------------";
//input ENUM_TIMEFRAMES MTrendTimeFrame=PERIOD_M15;//Timeframe
//input int PAtr=21;//Per<EFBFBD>odo do ATR
input string lB="*************** Compra ***************";
input bool EnableB=true;//Habilita compra
//input double FracB=1.0;//Tamanho do candle elefante em unidades de atr
input bool UseDTB=true;//Habilitar day trade
input int PosExpB=8;//N<EFBFBD>mero de horas para a expira<EFBFBD><EFBFBD>o
input string lS="*************** Venda ***************";
input bool EnableS=true;//Habilita venda
//input int PatrS=21;//Per<EFBFBD>odo do ATR
//input double FracS=1.0;//Tamanho do candle elefante em unidades de atr
input bool UseDTS=true;//Habilitar day trade
input int PosExpS=8;//N<EFBFBD>mero de horas para a expira<EFBFBD><EFBFBD>o
input string lsl="-----------------------SL-----------------";
input ENUM_STOP_TYPES Sl_Type=Fluctuation;//Tipo de SL
input double SLLevel=2;//Dist<EFBFBD>ncia entre SL e res em unidades de ATR (Fluctuation)
input ENUM_TIMEFRAMES SlTimeframe=PERIOD_M5;//Timeframe do SL
input int SlBars=9;//Barras do SL
//input ENUM_TIMEFRAMES SlMeanTimeframe=PERIOD_M5;//Timeframe do SL (Mean)
//input int SlMeanBars=9;//Barras do SL (Mean)
input string ltp="-----------------------TP-----------------";
input ENUM_STOP_TYPES Tp_Type=Fluctuation;//Tipo de TP
input double TPLevel=1;//Dist<EFBFBD>ncia entre TP e sup em unidades de ATR (Fluctuation)
input ENUM_TIMEFRAMES TpTimeframe=PERIOD_M5;//Timeframe do TP
input int TpBars=9;//Barras do TP
//input ENUM_TIMEFRAMES TpMeanTimeframe=PERIOD_M5;//Timeframe do TP (Mean)
//input int TpMeanBars=9;//Barras do TP (Mean)
input string lG1="-----------------------Par<00>metros gerais-----------------";
//input bool PersistSignal=false;//Usar sinal persistente
input bool AdjustSlTp=true;//Ajustar o SL/TP devido ao spread
input bool PosExp=true;//Usar expira<EFBFBD><EFBFBD>o de posi<EFBFBD><EFBFBD>es
input bool PosExpTP=false;//Usar fade para TP
input bool PosExpSL=false;//Usar fade para SL
input double Risk=0.005;//Risco por ativo
input bool UseVolLimit=false;//Habilitar limita<EFBFBD><EFBFBD>o de volume
input double VolLimit=0.01;//Fra<EFBFBD><EFBFBD>o do volume em % da m<EFBFBD>dia di<EFBFBD>ria
input VolumeTypes VolType=VTOptim_ATR;//Tipo de otimiza<EFBFBD><EFBFBD>o de portfolio
//input bool VolFixed=false;//Volume fixo
input int Nvol=5;//Quantidade de contrato (lotes) no caso de volume fixo
//bool UseRiskVol=true;//Usar risco no c<EFBFBD>lculo de volume
//int PRisk=21;//Per<EFBFBD>odo do risco
//ENUM_TIMEFRAMES RiskTimeframe=PERIOD_D1;//Timeframe do risco
input bool UseTimer=false;//Executar o rob<EFBFBD> no timer
input Periodicity TimerPeriod=Hora;//Per<EFBFBD>odo do timer(min)
input bool UseTrailingSL=false;//Trailing de SL
input bool UseTrailingTP=false;//Trailing de TP
input int LockExp=60;//Expiracao da trava em segundos
input bool UseCloseBy=false;//Muda a dire<EFBFBD><EFBFBD>o do trade se tiver sinal oposto
input int OHour=10;//Hora de abertura
input int OMin=00;//Minuto de abertura
input string pend1="//------------------Ordens pendentes--------------------";
input int OrdExp=10;//Expira<EFBFBD><EFBFBD>o das pendentes em minutos
input double OrderSlippage=0.00;//Slippage das pendentes em centavos
input string pendopen="//------------------Abertura--------------------";
input bool UsePendingOpen=false;//Usar ordens pendentes para abrir as posi<EFBFBD><EFBFBD>es
input bool UseTrailingOp=false;//Usar trailing nas ordens pendentes
input bool TrailingTopOp=false;//Mant<EFBFBD>m a pendente no topo (bid/ask)
input bool TrailingMountainOp=false;//Mant<EFBFBD>m a pendente antes da montanha de volume
input bool TrailingEscapeOp=false;//Escape - incompat<EFBFBD>vel com soma 1
input bool TrailingSoma1Op=false;//Soma 1 ticksize a cada minuto- incompat<EFBFBD>vel com escape
input bool TrailingTargetOp=false;//Usar alvo
input bool TrailingTolOp=false;//Usar toler<EFBFBD>ncia
input double TrailingTolFracOp=0.1;//Toler<EFBFBD>ncia em uindades de atr
input bool TrailingAggressionOp=false;//Usar agress<EFBFBD>o
input string pendclose="//------------------Fechamento--------------------";
input bool UsePendingClose=false;//Usar ordens pendentes para fechar as posi<EFBFBD><EFBFBD>es (Expira<EFBFBD><EFBFBD>o/N<EFBFBD>o selecionado)
input bool UseTrailingCl=false;//Usar trailing nas ordens pendentes
input bool TrailingTopCl=false;//Mant<EFBFBD>m a pendente no topo (bid/ask)
input bool TrailingMountainCl=false;//Mant<EFBFBD>m a pendente antes da montanha de volume
input bool TrailingEscapeCl=false;//Escape - incompat<EFBFBD>vel com soma 1
input bool TrailingSoma1Cl=false;//Soma 1 ticksize a cada minuto- incompat<EFBFBD>vel com escape
input bool TrailingTargetCl=false;//Usar alvo
input bool TrailingTolCl=false;//Usar toler<EFBFBD>ncia
input double TrailingTolFracCl=0.1;//Toler<EFBFBD>ncia em uindades de atr
input bool TrailingAggressionCl=false;//Usar agress<EFBFBD>o
input string pendsl="//------------------SL--------------------";
input bool UsePendingSl=false;//Usar ordens pendentes para SL
input bool UseTrailingSl=false;//Usar trailing nas ordens pendentes
input bool TrailingTopSl=false;//Mant<EFBFBD>m a pendente no topo (bid/ask)
input bool TrailingMountainSl=false;//Mant<EFBFBD>m a pendente antes da montanha de volume
input bool TrailingEscapeSl=false;//Escape - incompat<EFBFBD>vel com soma 1
input bool TrailingSoma1Sl=false;//Soma 1 ticksize a cada minuto- incompat<EFBFBD>vel com escape
input bool TrailingTargetSl=false;//Usar alvo
input bool TrailingTolSl=false;//Usar toler<EFBFBD>ncia
input double TrailingTolFracSl=0.1;//Toler<EFBFBD>ncia em uindades de atr
input bool TrailingAggressionSl=false;//Usar agress<EFBFBD>o
input string pendtp="//------------------TP--------------------";
input bool UsePendingTp=false;//Usar ordens pendentes para SL
input bool UseTrailingTp=false;//Usar trailing nas ordens pendentes
input bool TrailingTopTp=false;//Mant<EFBFBD>m a pendente no topo (bid/ask)
input bool TrailingMountainTp=false;//Mant<EFBFBD>m a pendente antes da montanha de volume
input bool TrailingEscapeTp=false;//Escape - incompat<EFBFBD>vel com soma 1
input bool TrailingSoma1Tp=false;//Soma 1 ticksize a cada minuto- incompat<EFBFBD>vel com escape
input bool TrailingTargetTp=false;//Usar alvo
input bool TrailingTolTp=false;//Usar toler<EFBFBD>ncia
input double TrailingTolFracTp=0.1;//Toler<EFBFBD>ncia em uindades de atr
input bool TrailingAggressionTp=false;//Usar agress<EFBFBD>o
input string pend2="//------------------------------------------------------";
input string G2="-----------------------Hor<00>rios day trade -----------------";
input int OCHour=15;//Hora de bloqueio de ordens
input int OCMin=30;//Minuto de bloqueio de ordens
input int DTHour=16;//Hora de encerramento day trade
input int DTMin=25;//Minuto de encerramento day trade
#ifdef USE_DLL
#import "shell32.dll"
int ShellExecuteW(int hWnd, string Verb, string File, string Parameter, string Path, int ShowCmd);
#import
#else
int ShellExecuteW(int hWnd, string Verb, string File, string Parameter, string Path, int ShowCmd){return (0);}
#endif
bool Shell(string file, string parameters="",string directory="")
{
//#define OPERATION "open" // or print
#define SW_SHOWNORMAL 1
#define SW_HIDE 0
int r=ShellExecuteW(0, "open", file, parameters, directory, SW_HIDE);
if (r > 32) return(true);
Alert("Shell failed: ",r);
return(false);
}
bool RunPython(string fname)
{
string termPath = ((MQLInfoInteger(MQL_TESTER))?
(TerminalInfoString(TERMINAL_COMMONDATA_PATH)+ "\\Files\\")://Tester
(TerminalInfoString(TERMINAL_DATA_PATH)+ "\\MQL5\\Files\\")),//Online+Optimization
script = fname,
command = "python";
return (Shell(command,script,termPath));
}
bool RunLatex(string fname)
{
string termPath = ((MQLInfoInteger(MQL_TESTER))?
(TerminalInfoString(TERMINAL_COMMONDATA_PATH)+ "\\Files\\")://Tester
(TerminalInfoString(TERMINAL_DATA_PATH)+ "\\MQL5\\Files\\")),//Online+Optimization
script = " -interaction=batchmode " + fname,
command = "pdflatex";
return (Shell(command,script,termPath));
}
bool RunGnuplot(string fname)
{
string termPath = ((MQLInfoInteger(MQL_TESTER))?
(TerminalInfoString(TERMINAL_COMMONDATA_PATH)+ "\\Files\\")://Tester
(TerminalInfoString(TERMINAL_DATA_PATH)+ "\\MQL5\\Files\\")),//Online+Optimization
script = fname,
command = "gnuplot";
return (Shell(command,script,termPath));
}
bool ShellOpenFile(string fname)
{
string termPath = ((MQLInfoInteger(MQL_TESTER))?
(TerminalInfoString(TERMINAL_COMMONDATA_PATH)+ "\\Files\\")://Tester
(TerminalInfoString(TERMINAL_DATA_PATH)+ "\\MQL5\\Files\\")),//Online+Optimization
command = fname;
return (Shell(command,"",termPath));
}
double Atr(string names,int Patr5,ENUM_TIMEFRAMES AtrTimeframe,int shift=0)
{
MqlRates rt[];
ArrayResize(rt,(Patr5+1));
double atr=0;
if (CopyRates(names,AtrTimeframe,shift,Patr5+1,rt)==(Patr5+1))
{
{
for (int cnt=1;cnt<(Patr5+1);cnt++)
atr+=(MathMax(rt[cnt].high,rt[cnt-1].close)-MathMin(rt[cnt].low,rt[cnt-1].close));
atr/=(double)Patr5;
}
}
ArrayFree(rt);
return(atr);
}
double Pearson(string nameref,string name,int period,ENUM_TIMEFRAMES timeframe)
{
MqlRates rt[],rtref[];
ArrayResize(rt,period);
ArrayResize(rtref,period);
double correlation=INT_MIN;
if (CopyRates(name,timeframe,0,period,rt)==period)
if (CopyRates(nameref,timeframe,0,period,rtref)==period)
{
double x=0,y=0,xm=0,ym=0,sxx=0,sxy=0,syy=0;
for (int j=0;j<period;j++)
{
xm+=rt[j].close;
ym+=rtref[j].close;
}
xm/=(double)period;
ym/=(double)period;
for (int j=0;j<period;j++)
{
x=rt[j].close;
y=rtref[j].close;
sxy+=(x-xm)*(y-ym);
sxx+=(x-xm)*(x-xm);
syy+=(y-ym)*(y-ym);
}
correlation=sxy/sqrt(sxx*syy);
}
return(correlation);
}
double Stddev(string name,int period,ENUM_TIMEFRAMES timeframe)
{
double pricevector[];
MqlRates rt[];
ArrayResize(rt,period);
double stddev=0;
if (CopyRates(name,timeframe,0,period,rt)==period)
{
ArrayResize(pricevector,period);
for (int j=0;j<period;j++) pricevector[j]=rt[j].close;
stddev=MathStandardDeviation(pricevector);
}
return(stddev);
}
double Stdrel(string name,int period,ENUM_TIMEFRAMES timeframe)
{
double pricevector[];
MqlRates rt[];
ArrayResize(rt,period);
double stddev=0;
if (CopyRates(name,timeframe,0,period,rt)==period)
{
ArrayResize(pricevector,period);
for (int j=0;j<period;j++) pricevector[j]=MathLog(rt[j].close);
stddev=MathStandardDeviation(pricevector);
}
return(stddev);
}
double Elasticity(string name,int period,ENUM_TIMEFRAMES timeframe)
{
MqlRates rt[];
ArrayResize(rt,period);
double elasticity=0;
if (CopyRates(name,timeframe,0,period,rt)==period)
{
for (int cnt=0;cnt<period;cnt++)
//elasticity+=(rt[cnt].close!=rt[cnt].open)?(rt[cnt].high-rt[cnt].low)/MathAbs(rt[cnt].open-rt[cnt].close):1;//(H!=L)?<|O-C|/(H-L)>:1
elasticity+=(rt[cnt].high-rt[cnt].low+0.01)/(MathAbs(rt[cnt].open-rt[cnt].close)+0.01);//(H!=L)?<|O-C|/(H-L)>:1
//elasticity+=(rt[cnt].high!=rt[cnt].low)?(MathAbs(rt[cnt].open-rt[cnt].close)+0.01)/(rt[cnt].high-rt[cnt].low+0.01):1;//(H!=L)?<|O-C|/(H-L)>:1
//elasticity+=(MathAbs(rt[cnt].open-rt[cnt].close)+0.01)/(rt[cnt].high-rt[cnt].low+0.01);//(H!=L)?<|O-C|/(H-L)>:1
elasticity/=(double)period;
}
ArrayFree(rt);
return(elasticity);
}
double Avg(string psymbol,int period,ENUM_TIMEFRAMES timeframe,int shift=0)
{
MqlRates rt[];
if (CopyRates(psymbol,timeframe,shift,period,rt)==period)
{
double avg=0;
for (int i=0;i<period;i++) avg+=rt[i].close;
avg/=(double)period;
return(avg);
}
return(0);
}
double AvgVol(string psymbol,int period,ENUM_TIMEFRAMES timeframe)
{
MqlRates rt[];
if (CopyRates(psymbol,timeframe,0,period,rt)==period)
{
double avg=0;
for (int i=0;i<period;i++) avg+=(double)rt[i].real_volume;
avg/=(double)period;
return(avg);
}
return(0);
}
double SSB(string psymbol,ENUM_TIMEFRAMES timeframe,int shift=0)
{
double max=iHigh(psymbol,timeframe,iHighest(psymbol,timeframe,MODE_HIGH,52,shift));
double min=iLow(psymbol,timeframe,iLowest(psymbol,timeframe,MODE_LOW,52,shift));
return((max+min)/2.0);
}
//+------------------------------------------------------------------+
//| Fun<EFBFBD><EFBFBD>o para ajuste de rentabilidade, algoritmo quadrados m<EFBFBD>nimos.|
//| Tamb<EFBFBD>m calcula volume m<EFBFBD>dio, sharp e m<EFBFBD>dia de neg<EFBFBD>cios |
//+------------------------------------------------------------------+
void MSQ(MqlRates &rt[],double &slope,double &r2,double &sharp,double &mvol,double &mtick,int npoints)
{
int i;
double x,y,sx=0,sy=0,sxx=0,syy=0,sxy=0,mret=0,sret=0;
mvol=0;
mtick=0;
for (i=0;i<npoints-1;i++)
{
y=MathLog(rt[i].close);
x=i;
sx+=x;
sy+=y;
sxx+=x*x;
syy+=y*y;
sxy+=x*y;
mvol+=(double)rt[i].real_volume;
mtick+=(double)rt[i].tick_volume;
}
sx/=(double)npoints;
sy/=(double)npoints;
sxx=sxx-npoints*sx*sx;
syy=syy-npoints*sy*sy;
sxy=sxy-npoints*sx*sy;
mvol/=(double)npoints;
mtick/=(double)npoints;
for (i=1;i<(npoints-1);i++)
{
y=(rt[i].close-rt[i-1].close)/rt[i-1].close;
mret+=y;
sret+=y*y;
}
mret/=(double)(npoints-1);
sret-=(npoints-1)*mret*mret;
sret/=(double)(npoints-2);
if (sret>0) sret=MathSqrt(sret);
else sret=0;
slope=sxy/sxx;
r2=sxy*sxy/(sxx*syy);
sharp=mret/sret;
return;
}
class MyTimer
{
public:
datetime LastUpdate;
Periodicity Periodicidade;
MyTimer(void){LastUpdate=0;Periodicidade=Dia;}
bool UpdateTime(bool disable_open_time=false,int Ohour=10,int Omin=0)
{
MqlDateTime today,lastupdate;
TimeLocal(today);
TimeToStruct(LastUpdate,lastupdate);
if ((LastUpdate+Periodicidade)<=TimeLocal())
{
if (Periodicidade==Dia)
{
if (today.day!=lastupdate.day)
{
if (disable_open_time) return(true);
else if ( ((today.hour>=Ohour)&&(today.min>=Omin))||(today.hour>=(Ohour+1)) ) return(true);
}
return(false);
}
else if ((Periodicidade==Dias7)||(Periodicidade==Dias15))
{
if (today.day_of_week>=WEDNESDAY)
{
if (disable_open_time) return(true);
else if ( ((today.hour>=Ohour)&&(today.min>=Omin))||(today.hour>=(Ohour+1)) ) return(true);
}
return(false);
}
else if(Periodicidade==Mes)
{
if ((today.day>=1)&&(today.mon!=lastupdate.mon))
{
if (disable_open_time) return(true);
else if ( ((today.hour>=Ohour)&&(today.min>=Omin))||(today.hour>=(Ohour+1)) ) return(true);
}
return(false);
}
else return(true);
}
return(false);
}
void SetLastUpdate(int Ohour=10,int Omin=0)
{
MqlDateTime lasttime;
TimeLocal(lasttime);
if (Periodicidade==Dia)
{
lasttime.hour=Ohour-1;
lasttime.min=Omin;
LastUpdate=StructToTime(lasttime);
}
if ((Periodicidade==Dias7)||(Periodicidade==Dias15))
{
lasttime.hour=Ohour-1;
lasttime.min=Omin;
lasttime.day+=WEDNESDAY-lasttime.day_of_week;
LastUpdate=StructToTime(lasttime);
}
if (Periodicidade==Mes)
{
lasttime.hour=Ohour-1;
lasttime.min=Omin;
lasttime.day=1;
LastUpdate=StructToTime(lasttime);
}
else
LastUpdate=Periodicidade*(datetime)floor(TimeLocal()/Periodicidade);
}
};