Indicadores de múltiplos períodos de tempo - página 669

 
alessandromagno:
Olá, alguém pode fazer deste índio um índio MTF???

Muito obrigado!!!!

wprv2.mq4

alessandromagno

Experimente agora

Versão atualizada postada aqui : https://www.mql5.com/en/forum/173574

Arquivos anexados:
wprv2_mtf.mq4  8 kb
 

Ajude, por favor!

Precisa de ajustes de fuso horário.

Arquivos anexados:
 
DMNIK:
Ajuda, por favor !Precisa de ajustes de fuso horário.

Dmnik, esse indicador é uma versão descompilada qualquer chance de você ter o código fonte original.

 

Novo indicador de tendência atualizado : newtrend_mtf_nmc.mq4

Originalmente foi publicado aqui : https://www.mql5.com/en/forum/173574/page389

Arquivos anexados:
 
vaider:
newtrend.mq4mtf version_ Obrigado!

Vaider, tornou-o mtf.

Versão atualizada postada aqui : https://www.mql5.com/en/forum/173574

Arquivos anexados:
 

Atualizado 3 barras de stop loss : 3barstoploss_mtf_nmc.mq4

O original foi postado aqui : https://www.mql5.com/en/forum/173574/page389

Arquivos anexados:
 
niqcom:
Olá, pode fazer deste indi um MTF ???? Please.....

3barstoploss.mq4

Muito obrigado!

niqcom

Aqui está uma versão com vários períodos de tempo desse indicador

Versão atualizada postada aqui : https://www.mql5.com/en/forum/173574

Arquivos anexados:
 

Olá programadores, apenas uma pergunta na mosca.

De um backtest eu achei particularmente interessante este filtro laguerre. Ele pinta de novo? Pergunto isso porque vejo a variável "lookback" nas opções.

É uma espécie de indicador adaptativo/pintura?

//------------------------------------------------------------------

//

//------------------------------------------------------------------

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 LimeGreen

#property indicator_color2 Orange

#property indicator_color3 Orange

#property indicator_width1 2

#property indicator_width2 2

#property indicator_width3 2

extern string TimeFrame = "Current time frame";

extern int LookBack = 20;

extern int Median = 5;

extern int Price = PRICE_MEDIAN;

double Filter[];

double Filterda[];

double Filterdb[];

double Diff[];

double Slope[];

double sortDiff[];

string indicatorFileName;

bool returnBars;

int timeFrame;

//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//

int init()

{

IndicatorBuffers(5);

SetIndexBuffer(0,Filter);

SetIndexBuffer(1,Filterda);

SetIndexBuffer(2,Filterdb);

SetIndexBuffer(3,Diff);

SetIndexBuffer(4,Slope);

ArrayResize(sortDiff,Median);

indicatorFileName = WindowExpertName();

returnBars = TimeFrame == "returnBars"; if (returnBars) return(0);

timeFrame = stringToTimeFrame(TimeFrame);

return (0);

}

//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//

int start()

{

int counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

int limit = MathMin(Bars-counted_bars,Bars-1);

if (returnBars) { Filter[0] = limit+1; return(0); }

if (timeFrame!=Period())

{

limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));

if (Slope[limit]==-1) CleanPoint(limit,Filterda,Filterdb);

for (int i=limit; i>=0; i--)

{

int y = iBarShift(NULL,timeFrame,Time);

Filter = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",LookBack,Median,Price,0,y);

Slope = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",LookBack,Median,Price,4,y);

Filterda = EMPTY_VALUE;

Filterdb = EMPTY_VALUE;

if (Slope == -1) PlotPoint(i,Filterda,Filterdb,Filter);

}

return(0);

}

//

//

//

//

//

if (Slope[limit]==-1) CleanPoint(limit,Filterda,Filterdb);

for (i=limit; i>=0; i--)

{

double price = iMA(NULL,0,1,0,MODE_SMA,Price,i);

Diff = MathAbs(price - Filter);

double hi = Diff[ArrayMaximum(Diff,LookBack,i)];

double lo = Diff[ArrayMinimum(Diff,LookBack,i)];

double alpha = 0;

if (hi!=lo)

{

for (int j=0; j<Median; j++) sortDiff[j] = (Diff-lo)/(hi-lo);

ArraySort(sortDiff,WHOLE_ARRAY,0,MODE_ASCEND);

if (MathMod(Median,2.0) != 0) alpha = sortDiff[Median/2];

else alpha = (sortDiff[Median/2]+sortDiff[(Median/2)-1])/2;

}

Filter = iLaGuerreFilter(price, 1.0-alpha, i, 0);

Filterda = EMPTY_VALUE;

Filterdb = EMPTY_VALUE;

Slope = Slope;

if (Filter>Filter) Slope = 1;

if (Filter<Filter) Slope = -1;

if (Slope == -1) PlotPoint(i,Filterda,Filterdb,Filter);

}

return (0);

}

//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//

double workLagFil[][4];

double iLaGuerreFilter(double price, double gamma, int i, int instanceNo=0)

{

if (ArrayRange(workLagFil,0)!=Bars) ArrayResize(workLagFil,Bars); i=Bars-i-1; instanceNo*=4;

if (gamma<=0) return(price);

//

//

//

//

//

workLagFil = (1.0 - gamma)*price + gamma*workLagFil;

workLagFil = -gamma*workLagFil + workLagFil + gamma*workLagFil;

workLagFil = -gamma*workLagFil + workLagFil + gamma*workLagFil;

workLagFil = -gamma*workLagFil + workLagFil + gamma*workLagFil;

//

//

//

//

//

return((workLagFil+2.0*workLagFil+2.0*workLagFil+workLagFil)/6.0);

}

//-------------------------------------------------------------------

//

//-------------------------------------------------------------------

//

//

//

//

//

void CleanPoint(int i,double& first[],double& second[])

{

if ((second != EMPTY_VALUE) && (second != EMPTY_VALUE))

second = EMPTY_VALUE;

else

if ((first != EMPTY_VALUE) && (first != EMPTY_VALUE) && (first == EMPTY_VALUE))

first = EMPTY_VALUE;

}

//

//

//

//

//

void PlotPoint(int i,double& first[],double& second[],double& from[])

{

if (first == EMPTY_VALUE)

{

if (first == EMPTY_VALUE) {

first = from;

first = from;

second = EMPTY_VALUE;

}

else {

second = from;

second = from;

first = EMPTY_VALUE;

}

}

else

{

first = from;

second = EMPTY_VALUE;

}

}

//-------------------------------------------------------------------

//

//-------------------------------------------------------------------

//

//

//

//

//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};

int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//

//

//

//

//

int stringToTimeFrame(string tfs)

{

tfs = stringUpperCase(tfs);

for (int i=ArraySize(iTfTable)-1; i>=0; i--)

if (tfs==sTfTable || tfs==""+iTfTable) return(MathMax(iTfTable,Period()));

return(Period());

}

//

//

//

//

//

string stringUpperCase(string str)

{

string s = str;

for (int length=StringLen(str)-1; length>=0; length--)

{

int tchar = StringGetChar(s, length);

if((tchar > 96 && tchar 223 && tchar < 256))

s = StringSetChar(s, length, tchar - 32);

else if(tchar > -33 && tchar < 0)

s = StringSetChar(s, length, tchar + 224);

}

return(s);

}

 
thefxpros:
Olá programadores, apenas uma pergunta na hora.

De um backtest eu achei particularmente interessante este filtro laguerre. Ele pinta de novo? Pergunto isso porque vejo a variável "lookback" nas opções.

É uma espécie de indicador adaptativo/pintura?

//------------------------------------------------------------------

//

//------------------------------------------------------------------

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 LimeGreen

#property indicator_color2 Orange

#property indicator_color3 Orange

#property indicator_width1 2

#property indicator_width2 2

#property indicator_width3 2

extern string TimeFrame = "Current time frame";

extern int LookBack = 20;

extern int Median = 5;

extern int Price = PRICE_MEDIAN;

double Filter[];

double Filterda[];

double Filterdb[];

double Diff[];

double Slope[];

double sortDiff[];

string indicatorFileName;

bool returnBars;

int timeFrame;

//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//

int init()

{

IndicatorBuffers(5);

SetIndexBuffer(0,Filter);

SetIndexBuffer(1,Filterda);

SetIndexBuffer(2,Filterdb);

SetIndexBuffer(3,Diff);

SetIndexBuffer(4,Slope);

ArrayResize(sortDiff,Median);

indicatorFileName = WindowExpertName();

returnBars = TimeFrame == "returnBars"; if (returnBars) return(0);

timeFrame = stringToTimeFrame(TimeFrame);

return (0);

}

//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//

int start()

{

int counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

int limit = MathMin(Bars-counted_bars,Bars-1);

if (returnBars) { Filter[0] = limit+1; return(0); }

if (timeFrame!=Period())

{

limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));

if (Slope[limit]==-1) CleanPoint(limit,Filterda,Filterdb);

for (int i=limit; i>=0; i--)

{

int y = iBarShift(NULL,timeFrame,Time);

Filter = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",LookBack,Median,Price,0,y);

Slope = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",LookBack,Median,Price,4,y);

Filterda = EMPTY_VALUE;

Filterdb = EMPTY_VALUE;

if (Slope == -1) PlotPoint(i,Filterda,Filterdb,Filter);

}

return(0);

}

//

//

//

//

//

if (Slope[limit]==-1) CleanPoint(limit,Filterda,Filterdb);

for (i=limit; i>=0; i--)

{

double price = iMA(NULL,0,1,0,MODE_SMA,Price,i);

Diff = MathAbs(price - Filter);

double hi = Diff[ArrayMaximum(Diff,LookBack,i)];

double lo = Diff[ArrayMinimum(Diff,LookBack,i)];

double alpha = 0;

if (hi!=lo)

{

for (int j=0; j<Median; j++) sortDiff[j] = (Diff-lo)/(hi-lo);

ArraySort(sortDiff,WHOLE_ARRAY,0,MODE_ASCEND);

if (MathMod(Median,2.0) != 0) alpha = sortDiff[Median/2];

else alpha = (sortDiff[Median/2]+sortDiff[(Median/2)-1])/2;

}

Filter = iLaGuerreFilter(price, 1.0-alpha, i, 0);

Filterda = EMPTY_VALUE;

Filterdb = EMPTY_VALUE;

Slope = Slope;

if (Filter>Filter) Slope = 1;

if (Filter<Filter) Slope = -1;

if (Slope == -1) PlotPoint(i,Filterda,Filterdb,Filter);

}

return (0);

}

//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//

double workLagFil[][4];

double iLaGuerreFilter(double price, double gamma, int i, int instanceNo=0)

{

if (ArrayRange(workLagFil,0)!=Bars) ArrayResize(workLagFil,Bars); i=Bars-i-1; instanceNo*=4;

if (gamma<=0) return(price);

//

//

//

//

//

workLagFil = (1.0 - gamma)*price + gamma*workLagFil;

workLagFil = -gamma*workLagFil + workLagFil + gamma*workLagFil;

workLagFil = -gamma*workLagFil + workLagFil + gamma*workLagFil;

workLagFil = -gamma*workLagFil + workLagFil + gamma*workLagFil;

//

//

//

//

//

return((workLagFil+2.0*workLagFil+2.0*workLagFil+workLagFil)/6.0);

}

//-------------------------------------------------------------------

//

//-------------------------------------------------------------------

//

//

//

//

//

void CleanPoint(int i,double& first[],double& second[])

{

if ((second != EMPTY_VALUE) && (second != EMPTY_VALUE))

second = EMPTY_VALUE;

else

if ((first != EMPTY_VALUE) && (first != EMPTY_VALUE) && (first == EMPTY_VALUE))

first = EMPTY_VALUE;

}

//

//

//

//

//

void PlotPoint(int i,double& first[],double& second[],double& from[])

{

if (first == EMPTY_VALUE)

{

if (first == EMPTY_VALUE) {

first = from;

first = from;

second = EMPTY_VALUE;

}

else {

second = from;

second = from;

first = EMPTY_VALUE;

}

}

else

{

first = from;

second = EMPTY_VALUE;

}

}

//-------------------------------------------------------------------

//

//-------------------------------------------------------------------

//

//

//

//

//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};

int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//

//

//

//

//

int stringToTimeFrame(string tfs)

{

tfs = stringUpperCase(tfs);

for (int i=ArraySize(iTfTable)-1; i>=0; i--)

if (tfs==sTfTable || tfs==""+iTfTable) return(MathMax(iTfTable,Period()));

return(Period());

}

//

//

//

//

//

string stringUpperCase(string str)

{

string s = str;

for (int length=StringLen(str)-1; length>=0; length--)

{

int tchar = StringGetChar(s, length);

if((tchar > 96 && tchar 223 && tchar < 256))

s = StringSetChar(s, length, tchar - 32);

else if(tchar > -33 && tchar < 0)

s = StringSetChar(s, length, tchar + 224);

}

return(s);

}

Thefxpros, eu diria adaptável, mas não repintura.

 
thefxpros:
Olá programadores, apenas uma pergunta na mosca.

De um backtest eu achei particularmente interessante este filtro laguerre. Ele pinta de novo? Pergunto isso porque vejo a variável "lookback" nas opções.

É uma espécie de indicador adaptativo/pintura?

//------------------------------------------------------------------

//

//------------------------------------------------------------------

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 LimeGreen

#property indicator_color2 Orange

#property indicator_color3 Orange

#property indicator_width1 2

#property indicator_width2 2

#property indicator_width3 2

extern string TimeFrame = "Current time frame";

extern int LookBack = 20;

extern int Median = 5;

extern int Price = PRICE_MEDIAN;

double Filter[];

double Filterda[];

double Filterdb[];

double Diff[];

double Slope[];

double sortDiff[];

string indicatorFileName;

bool returnBars;

int timeFrame;

//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//

int init()

{

IndicatorBuffers(5);

SetIndexBuffer(0,Filter);

SetIndexBuffer(1,Filterda);

SetIndexBuffer(2,Filterdb);

SetIndexBuffer(3,Diff);

SetIndexBuffer(4,Slope);

ArrayResize(sortDiff,Median);

indicatorFileName = WindowExpertName();

returnBars = TimeFrame == "returnBars"; if (returnBars) return(0);

timeFrame = stringToTimeFrame(TimeFrame);

return (0);

}

//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//

int start()

{

int counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

int limit = MathMin(Bars-counted_bars,Bars-1);

if (returnBars) { Filter[0] = limit+1; return(0); }

if (timeFrame!=Period())

{

limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));

if (Slope[limit]==-1) CleanPoint(limit,Filterda,Filterdb);

for (int i=limit; i>=0; i--)

{

int y = iBarShift(NULL,timeFrame,Time);

Filter = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",LookBack,Median,Price,0,y);

Slope = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",LookBack,Median,Price,4,y);

Filterda = EMPTY_VALUE;

Filterdb = EMPTY_VALUE;

if (Slope == -1) PlotPoint(i,Filterda,Filterdb,Filter);

}

return(0);

}

//

//

//

//

//

if (Slope[limit]==-1) CleanPoint(limit,Filterda,Filterdb);

for (i=limit; i>=0; i--)

{

double price = iMA(NULL,0,1,0,MODE_SMA,Price,i);

Diff = MathAbs(price - Filter);

double hi = Diff[ArrayMaximum(Diff,LookBack,i)];

double lo = Diff[ArrayMinimum(Diff,LookBack,i)];

double alpha = 0;

if (hi!=lo)

{

for (int j=0; j<Median; j++) sortDiff[j] = (Diff-lo)/(hi-lo);

ArraySort(sortDiff,WHOLE_ARRAY,0,MODE_ASCEND);

if (MathMod(Median,2.0) != 0) alpha = sortDiff[Median/2];

else alpha = (sortDiff[Median/2]+sortDiff[(Median/2)-1])/2;

}

Filter = iLaGuerreFilter(price, 1.0-alpha, i, 0);

Filterda = EMPTY_VALUE;

Filterdb = EMPTY_VALUE;

Slope = Slope;

if (Filter>Filter) Slope = 1;

if (Filter<Filter) Slope = -1;

if (Slope == -1) PlotPoint(i,Filterda,Filterdb,Filter);

}

return (0);

}

//------------------------------------------------------------------

//

//------------------------------------------------------------------

//

//

//

//

//

double workLagFil[][4];

double iLaGuerreFilter(double price, double gamma, int i, int instanceNo=0)

{

if (ArrayRange(workLagFil,0)!=Bars) ArrayResize(workLagFil,Bars); i=Bars-i-1; instanceNo*=4;

if (gamma<=0) return(price);

//

//

//

//

//

workLagFil = (1.0 - gamma)*price + gamma*workLagFil;

workLagFil = -gamma*workLagFil + workLagFil + gamma*workLagFil;

workLagFil = -gamma*workLagFil + workLagFil + gamma*workLagFil;

workLagFil = -gamma*workLagFil + workLagFil + gamma*workLagFil;

//

//

//

//

//

return((workLagFil+2.0*workLagFil+2.0*workLagFil+workLagFil)/6.0);

}

//-------------------------------------------------------------------

//

//-------------------------------------------------------------------

//

//

//

//

//

void CleanPoint(int i,double& first[],double& second[])

{

if ((second != EMPTY_VALUE) && (second != EMPTY_VALUE))

second = EMPTY_VALUE;

else

if ((first != EMPTY_VALUE) && (first != EMPTY_VALUE) && (first == EMPTY_VALUE))

first = EMPTY_VALUE;

}

//

//

//

//

//

void PlotPoint(int i,double& first[],double& second[],double& from[])

{

if (first == EMPTY_VALUE)

{

if (first == EMPTY_VALUE) {

first = from;

first = from;

second = EMPTY_VALUE;

}

else {

second = from;

second = from;

first = EMPTY_VALUE;

}

}

else

{

first = from;

second = EMPTY_VALUE;

}

}

//-------------------------------------------------------------------

//

//-------------------------------------------------------------------

//

//

//

//

//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};

int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//

//

//

//

//

int stringToTimeFrame(string tfs)

{

tfs = stringUpperCase(tfs);

for (int i=ArraySize(iTfTable)-1; i>=0; i--)

if (tfs==sTfTable || tfs==""+iTfTable) return(MathMax(iTfTable,Period()));

return(Period());

}

//

//

//

//

//

string stringUpperCase(string str)

{

string s = str;

for (int length=StringLen(str)-1; length>=0; length--)

{

int tchar = StringGetChar(s, length);

if((tchar > 96 && tchar 223 && tchar < 256))

s = StringSetChar(s, length, tchar - 32);

else if(tchar > -33 && tchar < 0)

s = StringSetChar(s, length, tchar + 224);

}

return(s);

}

thefxpros

Adaptar um indicador não significa repintar Adaptar nunca significou repintar (entre muitos indicadores adaptativos, neste momento não consigo me lembrar de um único que repintasse). Adaptar é algo completamente diferente.

A partir dessa laguerre: não, não se trata de repintar. O lookBack é simplesmente um período que é usado para amostrar dados que depois serão usados para adaptação (e está usando uma espécie de " estocástico bruto" de preço a diferenças de valores/momentos anteriores da laguerre para adaptação).

Razão: