Multi Timeframe Indicators - page 681

Mladen Rakic
153782
Mladen Rakic  

Updated William Blau's SMI : blau_-_smi___mtf_nmc.mq4

Original was posted here : https://www.mql5.com/en/forum/173574/page388

Mladen Rakic
153782
Mladen Rakic  
mladen:
Updated William Blau's SMI : blau_-_smi___mtf_nmc.mq4 Original was posted here : https://www.mql5.com/en/forum/173574/page388

Also the updated version with alerts : blau_-_smi___mtfalerts_nmc.mq4

Originally this one was posted here : https://www.mql5.com/en/forum/173574/page388

Mladen Rakic
153782
Mladen Rakic  

WPR v2 updated : wprv2_mtf_nmc.mq4

Originally it was posted here : https://www.mql5.com/en/forum/173574/page388

Files:
dmnik
132
dmnik  

Help, please !

Need timezone settings.

William Snyder
9493
William Snyder  
DMNIK:
Help, please ! Need timezone settings.

Dmnik, that indicator is a decompiled version any chance you have the original source code.

Mladen Rakic
153782
Mladen Rakic  

Updated new trend indicator : newtrend_mtf_nmc.mq4

Originally it was posted here : https://www.mql5.com/en/forum/173574/page389

Files:
Mladen Rakic
153782
Mladen Rakic  

Updated 3 bars stop loss : 3barstoploss_mtf_nmc.mq4

Original was posted here : https://www.mql5.com/en/forum/173574/page389

Fausto Nunziante Del Gaudio
1790
Fausto Nunziante Del Gaudio  

Hi programmers, just only one question on the fly.

From a backtest i found particular interesting this laguerre filter. Does it repaint? I ask that because i see the "lookback" variable in the options.

Is it a sort of adaptive/repainting indicator?

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

//

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

#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);

}

William Snyder
9493
William Snyder  
thefxpros:
Hi programmers, just only one question on the fly.

From a backtest i found particular interesting this laguerre filter. Does it repaint? I ask that because i see the "lookback" variable in the options.

Is it a sort of adaptive/repainting indicator?

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

//

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

#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, I would say adaptive but not repainting.

Mladen Rakic
153782
Mladen Rakic  
thefxpros:
Hi programmers, just only one question on the fly.

From a backtest i found particular interesting this laguerre filter. Does it repaint? I ask that because i see the "lookback" variable in the options.

Is it a sort of adaptive/repainting indicator?

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

//

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

#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

Making an indicator adaptive does not mean making it repaint Adapting never meant repainting (among a lot of adaptive indicators, right now I can not recall a single one that would repaint). Adapting is something completely else.

As of that laguerre : no, it does not repaint. The lookBack is simply a period that is used to sample data that will then be used for adapting (and it is using a kind of a "raw stochastic" of price to previous laguerre values diferences/momentums for adapting)