Download MetaTrader 5

What's wrong with the code? may you help me ?

To add comments, please log in or register
yalewang
606
yalewang  

hi,friends:

I download an indicator,when it works for a period of time,it will have a rest or not work at all .when reload it or turn the chart from m5 to m1,it works well again,the sign appears!! it is very strange, may you help me solve it ? thanks

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_width1 5
#property indicator_color2 Gold
#property indicator_width2 5
extern int RISK = 5;
double g_ibuf_80[];
double g_ibuf_84[];
int gi_88 = 0;
int gi_92 = 0;

int init() {
SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID);
SetIndexArrow(0, 159);
SetIndexBuffer(0, g_ibuf_80);
SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID);
SetIndexArrow(1, 159);
SetIndexBuffer(1, g_ibuf_84);
return (0);
}

int deinit() {
return (0);
}

int start() {
double ld_0;
double ld_8;
int l_count_48;
int li_52;
int li_56;
int li_60;
double ld_68;
double ld_76;
double ld_84;
double ld_92;
double lda_100[500][2];
double ld_16 = 10;
double ld_32 = 70;
double ld_40 = 30;
int li_104 = IndicatorCounted();
ld_16 = RISK << 1 + 3;
ld_32 = RISK + 67;
ld_40 = 33 - RISK;
double l_period_24 = ld_16;
if (li_104 < 0) return (-1);
if (li_104 > 0) li_104--;
int li_112 = Bars - li_104 - 1;
for (int li_108 = li_112; li_108 > 0; li_108--) {
li_52 = li_108;
ld_68 = 0;
ld_76 = 0;
for (li_52 = li_108; li_52 <= li_108 + 9; li_52++) ld_76 += MathAbs(High[li_52] - Low[li_52]);
ld_68 = ld_76 / 10.0;
li_52 = li_108;
l_count_48 = 0;
while (li_52 < li_108 + 9 && l_count_48 < 1) {
if (MathAbs(Open[li_52] - (Close[li_52 + 1])) >= 2.0 * ld_68) l_count_48++;
li_52++;
}
if (l_count_48 >= 1) li_56 = li_52;
else li_56 = -1;
li_52 = li_108;
l_count_48 = 0;
while (li_52 < li_108 + 6 && l_count_48 < 1) {
if (MathAbs(Close[li_52 + 3] - Close[li_52]) >= 4.6 * ld_68) l_count_48++;
li_52++;
}
if (l_count_48 >= 1) li_60 = li_52;
else li_60 = -1;
if (li_56 > -1) l_period_24 = 3;
else l_period_24 = ld_16;
if (li_60 > -1) l_period_24 = 4;
else l_period_24 = ld_16;
ld_0 = 100 - MathAbs(iWPR(NULL, 0, l_period_24, li_108));
lda_100[li_108][0] = li_108;
lda_100[li_108][1] = ld_0;
ld_84 = 0;
ld_92 = 0;
ld_8 = 0;
if (ld_0 < ld_40) {
for (int li_64 = 1; lda_100[li_108 + li_64][1] >= ld_40 && lda_100[li_108 + li_64][1] <= ld_32; li_64++) {
}
if (lda_100[li_108 + li_64][1] > ld_32) {
ld_8 = High[li_108] + ld_68 / 2.0;
ld_84 = ld_8;
}
}
if (ld_0 > ld_32) {
for (li_64 = 1; lda_100[li_108 + li_64][1] >= ld_40 && lda_100[li_108 + li_64][1] <= ld_32; li_64++) {
}
if (lda_100[li_108 + li_64][1] < ld_40) {
ld_8 = Low[li_108] - ld_68 / 2.0;
ld_92 = ld_8;
}
}
if (ld_92 != 0.0 && gi_88 == FALSE) {
g_ibuf_80[li_108] = ld_92 - 1.0 * Point;
gi_88 = TRUE;
gi_92 = FALSE;
if (li_112 <= 2) Alert(Symbol(), " ", Period(), "M Golden Finger BUY ");
} else g_ibuf_80[li_108] =EMPTY_VALUE;
if (ld_84 != 0.0 && gi_92 == FALSE) {
g_ibuf_84[li_108] = ld_84 + 1.0 * Point;
gi_92 = TRUE;
gi_88 = FALSE;
if (li_112 <= 2) Alert(Symbol(), " ", Period(), "M Golden Finger SELL ");
} else g_ibuf_84[li_108] = EMPTY_VALUE;

}
return (0);
}

Paul
632
Paul  

Hi YaleWang

Does it stop working after an "M gold finger" alert? Try removing the alerts if you don't need them.

yalewang
606
yalewang  
Ruptor wrote >>

Hi YaleWang

Does it stop working after an "M gold finger" alert? Try removing the alerts if you don't need them.

THANK YOU,I HAVE TRIED,IT HAS NOTHING WITH ALERT.

Paul
632
Paul  

Hi

I tried the indicator and suggested the alert was causing the problem because the only time I have seen it lock up is after an alert. It is an interesting indicator so I shall look at the problem but I have only seen it lock once. What change did you make to the code to remove the alert? Also how do you make it lock more frequently?

scalony
64
scalony  

Your code looks horrible could you make it more readable for human.

Try adding some indents, comments. And change names of variables to somethning that has meaning.

Paul
632
Paul  

Hi

Think the problem is that the main loop goes the full length of the chart that can be thousands of points. So the fixed array of 500 limit is exceeded. perhaps a fix could be fix the main loop size to less than the 2 dimensional array size so the subscript limit will not be exceeded. What do you think?

Paul
632
Paul  

Hi

Yup that fixed it. Do this for a quick fix.


// int li_104 = IndicatorCounted();
int li_104 = 450;

yalewang
606
yalewang  
Ruptor wrote >>

Hi

Yup that fixed it. Do this for a quick fix.

// int li_104 = IndicatorCounted();
int li_104 = 450;

thank you,Ruptor

i remove the alert,just add "//" infront of the code .

i change "int li_104 = IndicatorCounted();" to "int li_104 = 450;" .it seems that the sign position will be changed.

Paul
632
Paul  
YALEWANG:

thank you,Ruptor

i remove the alert,just add "//" infront of the code .

i change "int li_104 = IndicatorCounted();" to "int li_104 = 450;" .it seems that the sign position will be changed.

Hi

As you said earlier the alerts don't cause the problem so there is no need to comment them out. What do you mean "sign position changed"?

I checked the fixed version against the original and they both put the dots in the same place. Don't forget that the original will not draw dots so they may appear different but if

you switch timescales the dots will match the fixed coded.

cloudbreaker
1577
cloudbreaker  

Yalewang, count yourself very very lucky that Ruptor has opted to help you with your code.

It is, quite simply, the most hideous looking piece of code I've seen in a very long time (and I started coding 28 years ago).

What "developer" produced this?? Somewhere there is a village missing an idiot.

I've seen newbies with one day's experience produce something way better than this.

You need to ensure that any code you post here is maintainable before asking for help.

That way, folks like me will avoid the need for an expensive course of trauma treatment.


CB

yalewang
606
yalewang  

thank all of you a lot .

i download the code on the internet, and many indicator codes i download have the same style,they are very difficult to understand .

I have tried carefully again, the new version works well and normally. thank Ruptor again.

12
To add comments, please log in or register