Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I use 'ALLFramesTrend.mq4(picture below)' on my trading.
Sadly, this indicator's bar appears next chart bar as if there is on previous chart bar.
For example, I want the indicator's bar appears point B(previous bar), but actually appears on point A(current(next) bar).
-if current chart bar is A, indicator's bar appeared B and A chart bar.
Could anyone program this indicator as it appears current bar from the beginning ?
AllFramesTrend.mq4
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 3
#property indicator_width2 3
//extern int period = 5;
extern int method = 3;
extern int price = 5;
extern int M1 = 0;
extern int M1_per = 5;
extern int M5 = 1;
extern int M5_per = 5;
extern int M15 = 1;
extern int M15_per = 5;
extern int M30 = 1;
extern int M30_per = 5;
extern int H1 = 0;
extern int H1_per = 5;
extern int H4 = 0;
extern int H4_per = 5;
extern int D1 = 0;
extern int D1_per = 5;
double buffer0[];
double buffer1[];
double current;
int ExtCountedBars = 0;
int init()
{
IndicatorShortName("AllFramesTrend");
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexDrawBegin(0, 1);
SetIndexDrawBegin(1, 1);
SetIndexBuffer(0, buffer0);
SetIndexBuffer(1, buffer1);
return(0);
}
int start()
{
ExtCountedBars = IndicatorCounted();
if (ExtCountedBars < 0) return(-1);
if (ExtCountedBars > 0) ExtCountedBars--;
int pos = Bars - 1;
if(ExtCountedBars > 2) pos = Bars - ExtCountedBars - 1;
double M1_cur, M1_prev, M5_cur, M5_prev, M15_cur, M15_prev, M30_cur, M30_prev, H1_cur, H1_prev, H4_cur, H4_prev, D1_cur, D1_prev;
int shift;
while(pos >= 0)
{
if(M1 == 1)
{
shift = iBarShift(NULL, PERIOD_M1, Time[pos])+1;
M1_cur = iMA(NULL, PERIOD_M1, M1_per, 0, method, price, shift);
M1_prev = iMA(NULL, PERIOD_M1, M1_per, 0, method, price, shift+1);
}
if(M5 == 1)
{
shift = iBarShift(NULL, PERIOD_M5, Time[pos])+1;
M5_cur = iMA(NULL, PERIOD_M5, M5_per, 0, method, price, shift);
M5_prev = iMA(NULL, PERIOD_M5, M5_per, 0, method, price, shift+1);
}
if(M15 == 1)
{
shift = iBarShift(NULL, PERIOD_M15, Time[pos])+1;
M15_cur = iMA(NULL, PERIOD_M15, M15_per, 0, method, price, shift);
M15_prev = iMA(NULL, PERIOD_M15, M15_per, 0, method, price, shift+1);
}
if(M30 == 1)
{
shift = iBarShift(NULL, PERIOD_M30, Time[pos])+1;
M30_cur = iMA(NULL, PERIOD_M30, M30_per, 0, method, price, shift);
M30_prev = iMA(NULL, PERIOD_M30, M30_per, 0, method, price, shift+1);
}
if(H1 == 1)
{
shift = iBarShift(NULL, PERIOD_H1, Time[pos])+1;
H1_cur = iMA(NULL, PERIOD_H1, H1_per, 0, method, price, shift);
H1_prev = iMA(NULL, PERIOD_H1, H1_per, 0, method, price, shift+1);
}
if(H4 == 1)
{
shift = iBarShift(NULL, PERIOD_H4, Time[pos])+1;
H4_cur = iMA(NULL, PERIOD_H4, H4_per, 0, method, price, shift);
H4_prev = iMA(NULL, PERIOD_H4, H4_per, 0, method, price, shift+1);
}
if(D1 == 1)
{
shift = iBarShift(NULL, PERIOD_D1, Time[pos])+1;
D1_cur = iMA(NULL, PERIOD_D1, D1_per, 0, method, price, shift);
D1_prev = iMA(NULL, PERIOD_D1, D1_per, 0, method, price, shift+1);
}
shift = iBarShift(NULL, 0, Time[pos]);
if(Period() == 1) current = iMA(NULL, 0, M1_per, 0, method, price, shift);
if(Period() == 5) current = iMA(NULL, 0, M5_per, 0, method, price, shift);
if(Period() == 15) current = iMA(NULL, 0, M15_per, 0, method, price, shift);
if(Period() == 30) current = iMA(NULL, 0, M30_per, 0, method, price, shift);
if(Period() == 60) current = iMA(NULL, 0, H1_per, 0, method, price, shift);
if(Period() == 240) current = iMA(NULL, 0, H4_per, 0, method, price, shift);
if(Period() == 1440) current = iMA(NULL, 0, D1_per, 0, method, price, shift);
//current = iMA(NULL, 0, "M" + Period() + "_per", 0, method, price, shift);
if(((M1_cur > M1_prev) || M1 == 0) && ((M5_cur > M5_prev) || M5 == 0) && ((M15_cur > M15_prev) || M15 == 0) && ((M30_cur > M30_prev) || M30 == 0) && ((H1_cur > H1_prev) || H1 == 0) && ((H4_cur > H4_prev) || H4 == 0) && ((D1_cur > D1_prev) || D1 == 0)) buffer0[pos] = current;
if(((M1_cur < M1_prev) || M1 == 0) && ((M5_cur < M5_prev) || M5 == 0) && ((M15_cur < M15_prev) || M15 == 0) && ((M30_cur < M30_prev) || M30 == 0) && ((H1_cur < H1_prev) || H1 == 0) && ((H4_cur < H4_prev) || H4 == 0) && ((D1_cur < D1_prev) || D1 == 0)) buffer1[pos] = current;
pos--;
}
return(0);
}