Hi
I use the indicator above to help me find the trend, but when I use it on a EA using icustom() function, it donīt returns the same value displayed on the screen. Can anyone give me some clue of what could be happen?
Thanks
+++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Blue
#property indicator_width2 3
#property indicator_color3 Red
#property indicator_width3 3
extern int extremePeriods = 30;
extern string fx_pair = "EURUSD";
extern int timeframe = 240;
double buffer00[];
double buffer01[];
double buffer02[];
int init() {
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
IndicatorDigits(Digits + 1);
SetIndexBuffer(0, buffer00);
SetIndexBuffer(1, buffer01);
SetIndexBuffer(2, buffer02);
IndicatorShortName("Trend is your friend TF");
SetIndexLabel(0, "Black");
SetIndexLabel(1, "Blue");
SetIndexLabel(2, "Red");
return (0);
}
int start() {
double ld_8;
double ld_16;
double avgLowHigh;
int counted_bars = IndicatorCounted();
double expressao01 = 0;
double ld_40 = 0;
double ld_unused_48 = 0;
double ld_unused_56 = 0;
double ld_64 = 0;
double ld_unused_72 = 0;
double aux_Low = 0;
double aux_High = 0;
double act_High = 0;
double act_Low = 0;
if (counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;
for (int i = 0; i < limit; i++) {
aux_High = iHigh(fx_pair,timeframe,iHighest(fx _pair, timeframe, MODE_HIGH, extremePeriods, i));
aux_Low = iLow(fx_pair, timeframe,iLowest(fx_pair, timeframe, MODE_LOW, extremePeriods, i));
act_High = iMA(fx_pair,timeframe,1,0,MODE_SMA, PRICE_HIGH,i);
act_Low = iMA(fx_pair,timeframe,1,0,MODE_SMA, PRICE_LOW,i);
avgLowHigh = (act_High + act_Low) / 2.0;
expressao01 = 0.66 * ((avgLowHigh - aux_Low) / (aux_High - aux_Low) - 0.5) + 0.67 * ld_40;
expressao01 = MathMin(MathMax(expressao01, -0.999), 0.999);
buffer00[i] = MathLog((expressao01 + 1) / (1 - expressao01)) / 2.0 + ld_64 / 2.0;
ld_40 = expressao01;
ld_64 = buffer00[i];
}
bool li_108 = TRUE;
for (i = limit - 2; i >= 0; i--) {
ld_16 = buffer00[i];
ld_8 = buffer00[i + 1];
if ((ld_16 < 0.0 && ld_8 > 0.0) || ld_16 < 0.0) li_108 = FALSE;
if ((ld_16 > 0.0 && ld_8 < 0.0) || ld_16 > 0.0) li_108 = TRUE;
if (!li_108) {
buffer02[i] = ld_16;
buffer01[i] = 0.0;
} else {
buffer01[i] = ld_16;
buffer02[i] = 0.0;
}
}
return (0);
}
I use the indicator above to help me find the trend, but when I use it on a EA using icustom() function, it donīt returns the same value displayed on the screen. Can anyone give me some clue of what could be happen?
Thanks
+++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Blue
#property indicator_width2 3
#property indicator_color3 Red
#property indicator_width3 3
extern int extremePeriods = 30;
extern string fx_pair = "EURUSD";
extern int timeframe = 240;
double buffer00[];
double buffer01[];
double buffer02[];
int init() {
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
IndicatorDigits(Digits + 1);
SetIndexBuffer(0, buffer00);
SetIndexBuffer(1, buffer01);
SetIndexBuffer(2, buffer02);
IndicatorShortName("Trend is your friend TF");
SetIndexLabel(0, "Black");
SetIndexLabel(1, "Blue");
SetIndexLabel(2, "Red");
return (0);
}
int start() {
double ld_8;
double ld_16;
double avgLowHigh;
int counted_bars = IndicatorCounted();
double expressao01 = 0;
double ld_40 = 0;
double ld_unused_48 = 0;
double ld_unused_56 = 0;
double ld_64 = 0;
double ld_unused_72 = 0;
double aux_Low = 0;
double aux_High = 0;
double act_High = 0;
double act_Low = 0;
if (counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;
for (int i = 0; i < limit; i++) {
aux_High = iHigh(fx_pair,timeframe,iHighest(fx _pair, timeframe, MODE_HIGH, extremePeriods, i));
aux_Low = iLow(fx_pair, timeframe,iLowest(fx_pair, timeframe, MODE_LOW, extremePeriods, i));
act_High = iMA(fx_pair,timeframe,1,0,MODE_SMA, PRICE_HIGH,i);
act_Low = iMA(fx_pair,timeframe,1,0,MODE_SMA, PRICE_LOW,i);
avgLowHigh = (act_High + act_Low) / 2.0;
expressao01 = 0.66 * ((avgLowHigh - aux_Low) / (aux_High - aux_Low) - 0.5) + 0.67 * ld_40;
expressao01 = MathMin(MathMax(expressao01, -0.999), 0.999);
buffer00[i] = MathLog((expressao01 + 1) / (1 - expressao01)) / 2.0 + ld_64 / 2.0;
ld_40 = expressao01;
ld_64 = buffer00[i];
}
bool li_108 = TRUE;
for (i = limit - 2; i >= 0; i--) {
ld_16 = buffer00[i];
ld_8 = buffer00[i + 1];
if ((ld_16 < 0.0 && ld_8 > 0.0) || ld_16 < 0.0) li_108 = FALSE;
if ((ld_16 > 0.0 && ld_8 < 0.0) || ld_16 > 0.0) li_108 = TRUE;
if (!li_108) {
buffer02[i] = ld_16;
buffer01[i] = 0.0;
} else {
buffer01[i] = ld_16;
buffer02[i] = 0.0;
}
}
return (0);
}