plz convert mt4 indicator to AFL - Urgent

#1
Dear friends plz convert the following metatrader indicator to AFL code plz ..
its urgent too ..


MQL code follows :

------------------------------------------------------------------


/*
Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
Website: http://purebeam.biz
E-mail : [email protected]
*/

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_color5 DeepSkyBlue
#property indicator_color6 Red

extern int SignalPeriod = 12;
extern int ArrowPeriod = 2;
int gi_84 = 1;
int gi_88 = 1;
int gi_92 = 1;
int gi_96 = 999;
extern int SL_pips = 100;
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
extern bool AlertON = TRUE;
extern bool Email = TRUE;
bool gi_136 = FALSE;
bool gi_140 = FALSE;
datetime g_time_144;

void displayAlert(string as_0, double ad_8, double ad_16, double ad_24) {
string ls_32;
string ls_40;
string ls_48;
string ls_56;
string ls_64;
if (Time[0] != g_time_144) {
g_time_144 = Time[0];
if (ad_24 != 0.0) ls_48 = " at price " + DoubleToStr(ad_24, 4);
else ls_48 = "";
if (ad_8 != 0.0) ls_40 = ", TakeProfit on " + DoubleToStr(ad_8, 4);
else ls_40 = "";
if (ad_16 != 0.0) ls_32 = ", StopLoss on " + DoubleToStr(ad_16, 4);
else ls_32 = "";
Alert("BUYSELL MAGIC " + as_0 + ls_48 + ls_40 + ls_32 + " ", Symbol(), ", ", Period(), " minute chart");
ls_56 = "BUYSELL MAGIC - " + as_0 + ls_48;
ls_64 = "BUYSELL MAGIC " + as_0 + ls_48 + ls_40 + ls_32 + " " + Symbol() + ", " + Period() + " minute chart";
if (Email) SendMail(ls_56, ls_64);
}
}

int init() {
SetIndexBuffer(0, g_ibuf_104);
SetIndexBuffer(1, g_ibuf_108);
SetIndexBuffer(2, g_ibuf_112);
SetIndexBuffer(3, g_ibuf_116);
SetIndexBuffer(4, g_ibuf_120);
SetIndexBuffer(5, g_ibuf_124);
SetIndexStyle(0, DRAW_ARROW, 6, 0);
SetIndexStyle(1, DRAW_ARROW, 6, 0);
SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 1);
SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 1);
SetIndexStyle(4, DRAW_ZIGZAG, STYLE_DASH, 1);
SetIndexStyle(5, DRAW_ZIGZAG, STYLE_DASH, 1);
SetIndexArrow(0, 159);
SetIndexArrow(1, 159);
SetIndexArrow(2, 233);
SetIndexArrow(3, 234);
IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
string ls_0 = "BUYSELL MAGIC(" + AlertON + "," + ArrowPeriod + ")";
IndicatorShortName(ls_0);
SetIndexLabel(0, "UpTrend Stop");
SetIndexLabel(1, "DownTrend Stop");
SetIndexLabel(2, "UpTrend Signal");
SetIndexLabel(3, "DownTrend Signal");
SetIndexLabel(4, "UpTrend Line");
SetIndexLabel(5, "DownTrend Line");
SetIndexDrawBegin(0, SignalPeriod);
SetIndexDrawBegin(1, SignalPeriod);
SetIndexDrawBegin(2, SignalPeriod);
SetIndexDrawBegin(3, SignalPeriod);
SetIndexDrawBegin(4, SignalPeriod);
SetIndexDrawBegin(5, SignalPeriod);
return (0);
}

int start() {
int li_8;
double lda_12[25000];
double lda_16[25000];
double lda_20[25000];
double lda_24[25000];
double ld_28;
double l_close_36;
for (int l_shift_4 = gi_96; l_shift_4 > 0; l_shift_4--) {
g_ibuf_104[l_shift_4] = 0;
g_ibuf_108[l_shift_4] = 0;
g_ibuf_112[l_shift_4] = 0;
g_ibuf_116[l_shift_4] = 0;
g_ibuf_120[l_shift_4] = EMPTY_VALUE;
g_ibuf_124[l_shift_4] = EMPTY_VALUE;
}
for (l_shift_4 = gi_96 - SignalPeriod - 1; l_shift_4 > 0; l_shift_4--) {
lda_12[l_shift_4] = iBands(NULL, 0, SignalPeriod, ArrowPeriod, 0, PRICE_CLOSE, MODE_UPPER, l_shift_4);
lda_16[l_shift_4] = iBands(NULL, 0, SignalPeriod, ArrowPeriod, 0, PRICE_CLOSE, MODE_LOWER, l_shift_4);
if (Close[l_shift_4] > lda_12[l_shift_4 + 1]) li_8 = 1;
if (Close[l_shift_4] < lda_16[l_shift_4 + 1]) li_8 = -1;
if (li_8 > 0 && lda_16[l_shift_4] < lda_16[l_shift_4 + 1]) lda_16[l_shift_4] = lda_16[l_shift_4 + 1];
if (li_8 < 0 && lda_12[l_shift_4] > lda_12[l_shift_4 + 1]) lda_12[l_shift_4] = lda_12[l_shift_4 + 1];
lda_20[l_shift_4] = lda_12[l_shift_4] + (gi_84 - 1) / 2.0 * (lda_12[l_shift_4] - lda_16[l_shift_4]);
lda_24[l_shift_4] = lda_16[l_shift_4] - (gi_84 - 1) / 2.0 * (lda_12[l_shift_4] - lda_16[l_shift_4]);
if (li_8 > 0 && lda_24[l_shift_4] < lda_24[l_shift_4 + 1]) lda_24[l_shift_4] = lda_24[l_shift_4 + 1];
if (li_8 < 0 && lda_20[l_shift_4] > lda_20[l_shift_4 + 1]) lda_20[l_shift_4] = lda_20[l_shift_4 + 1];
if (li_8 > 0) {
if (gi_88 > 0 && g_ibuf_104[l_shift_4 + 1] == -1.0) {
g_ibuf_112[l_shift_4] = lda_24[l_shift_4];
g_ibuf_104[l_shift_4] = lda_24[l_shift_4];
if (gi_92 > 0) g_ibuf_120[l_shift_4] = lda_24[l_shift_4];
if (AlertON == TRUE && l_shift_4 == 1 && !gi_136) {
ld_28 = Low[1];
if (Low[2] < ld_28) ld_28 = Low[2];
if (Low[3] < ld_28) ld_28 = Low[3];
if (Low[4] < ld_28) ld_28 = Low[4];
ld_28 -= SL_pips * Point;
l_close_36 = Close[1];
displayAlert("Buy signal", 0, ld_28, l_close_36);
gi_136 = TRUE;
gi_140 = FALSE;
}
} else {
g_ibuf_104[l_shift_4] = lda_24[l_shift_4];
if (gi_92 > 0) g_ibuf_120[l_shift_4] = lda_24[l_shift_4];
g_ibuf_112[l_shift_4] = -1;
}
if (gi_88 == 2) g_ibuf_104[l_shift_4] = 0;
g_ibuf_116[l_shift_4] = -1;
g_ibuf_108[l_shift_4] = -1.0;
g_ibuf_124[l_shift_4] = EMPTY_VALUE;
}
if (li_8 < 0) {
if (gi_88 > 0 && g_ibuf_108[l_shift_4 + 1] == -1.0) {
g_ibuf_116[l_shift_4] = lda_20[l_shift_4];
g_ibuf_108[l_shift_4] = lda_20[l_shift_4];
if (gi_92 > 0) g_ibuf_124[l_shift_4] = lda_20[l_shift_4];
if (AlertON == TRUE && l_shift_4 == 1 && !gi_140) {
ld_28 = High[1];
if (High[2] > ld_28) ld_28 = High[2];
if (High[3] > ld_28) ld_28 = High[3];
if (High[4] > ld_28) ld_28 = High[4];
ld_28 += SL_pips * Point;
l_close_36 = Close[1];
displayAlert("Sell signal", 0, ld_28, l_close_36);
gi_140 = TRUE;
gi_136 = FALSE;
}
} else {
g_ibuf_108[l_shift_4] = lda_20[l_shift_4];
if (gi_92 > 0) g_ibuf_124[l_shift_4] = lda_20[l_shift_4];
g_ibuf_116[l_shift_4] = -1;
}
if (gi_88 == 2) g_ibuf_108[l_shift_4] = 0;
g_ibuf_112[l_shift_4] = -1;
g_ibuf_104[l_shift_4] = -1.0;
g_ibuf_120[l_shift_4] = EMPTY_VALUE;
}
}
return (0);
}
 
#4
HI
I remember ed pottasch did some work on similar code.
try searching on wisestocktrader.
the indicator name may be BuySellMagic
As per KelvinHand,it is a simple bollinger band( 12,2) based stop stuff.


My wish
It is a humble request.
Can some expert who can read the mt4 code lines give us some simple explanation on how to read the mt4 code lines and make some sense.

for example
li_86=may be line number 86


regards
 
Last edited:

KelvinHand

Well-Known Member
#5
HI
I remember ed pottasch did some work on similar code.
try searching on wisestocktrader.
the indicator name may be BuySellMagic
As per KelvinHand,it is a simple bollinger band( 12,2) based stop stuff.


My wish
It is a humble request.
Can some expert who can read the mt4 code lines give us some simple explanation on how to read the mt4 code lines and make some sense.

for example
li_86=may be line number 86


regards
You forgot about Kelvinhand's contribution again:
http://www.traderji.com/amibroker/74551-trend-catching-system-3.html

li_86 maybe integer position at byte 84, size of 4 bytes for integer, so next integer position is li_90.
Useless to read this way.

This request is same as post #1
http://www.traderji.com/metatrader/89954-conversion-mt4-code-amibroker-afl.html
 
Last edited:

mastermind007

Well-Known Member
#6
Dear friends plz convert the following metatrader indicator to AFL code plz ..
its urgent too ..


MQL code follows :

------------------------------------------------------------------


/*
Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
Website: http://purebeam.biz
E-mail : [email protected]
*/

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_color5 DeepSkyBlue
#property indicator_color6 Red

extern int SignalPeriod = 12;
extern int ArrowPeriod = 2;
int gi_84 = 1;
int gi_88 = 1;
int gi_92 = 1;
int gi_96 = 999;
extern int SL_pips = 100;
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
extern bool AlertON = TRUE;
extern bool Email = TRUE;
bool gi_136 = FALSE;
bool gi_140 = FALSE;
datetime g_time_144;

void displayAlert(string as_0, double ad_8, double ad_16, double ad_24) {
string ls_32;
string ls_40;
string ls_48;
string ls_56;
string ls_64;
if (Time[0] != g_time_144) {
g_time_144 = Time[0];
if (ad_24 != 0.0) ls_48 = " at price " + DoubleToStr(ad_24, 4);
else ls_48 = "";
if (ad_8 != 0.0) ls_40 = ", TakeProfit on " + DoubleToStr(ad_8, 4);
else ls_40 = "";
if (ad_16 != 0.0) ls_32 = ", StopLoss on " + DoubleToStr(ad_16, 4);
else ls_32 = "";
Alert("BUYSELL MAGIC " + as_0 + ls_48 + ls_40 + ls_32 + " ", Symbol(), ", ", Period(), " minute chart");
ls_56 = "BUYSELL MAGIC - " + as_0 + ls_48;
ls_64 = "BUYSELL MAGIC " + as_0 + ls_48 + ls_40 + ls_32 + " " + Symbol() + ", " + Period() + " minute chart";
if (Email) SendMail(ls_56, ls_64);
}
}

int init() {
SetIndexBuffer(0, g_ibuf_104);
SetIndexBuffer(1, g_ibuf_108);
SetIndexBuffer(2, g_ibuf_112);
SetIndexBuffer(3, g_ibuf_116);
SetIndexBuffer(4, g_ibuf_120);
SetIndexBuffer(5, g_ibuf_124);
SetIndexStyle(0, DRAW_ARROW, 6, 0);
SetIndexStyle(1, DRAW_ARROW, 6, 0);
SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 1);
SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 1);
SetIndexStyle(4, DRAW_ZIGZAG, STYLE_DASH, 1);
SetIndexStyle(5, DRAW_ZIGZAG, STYLE_DASH, 1);
SetIndexArrow(0, 159);
SetIndexArrow(1, 159);
SetIndexArrow(2, 233);
SetIndexArrow(3, 234);
IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
string ls_0 = "BUYSELL MAGIC(" + AlertON + "," + ArrowPeriod + ")";
IndicatorShortName(ls_0);
SetIndexLabel(0, "UpTrend Stop");
SetIndexLabel(1, "DownTrend Stop");
SetIndexLabel(2, "UpTrend Signal");
SetIndexLabel(3, "DownTrend Signal");
SetIndexLabel(4, "UpTrend Line");
SetIndexLabel(5, "DownTrend Line");
SetIndexDrawBegin(0, SignalPeriod);
SetIndexDrawBegin(1, SignalPeriod);
SetIndexDrawBegin(2, SignalPeriod);
SetIndexDrawBegin(3, SignalPeriod);
SetIndexDrawBegin(4, SignalPeriod);
SetIndexDrawBegin(5, SignalPeriod);
return (0);
}

int start() {
int li_8;
double lda_12[25000];
double lda_16[25000];
double lda_20[25000];
double lda_24[25000];
double ld_28;
double l_close_36;
for (int l_shift_4 = gi_96; l_shift_4 > 0; l_shift_4--) {
g_ibuf_104[l_shift_4] = 0;
g_ibuf_108[l_shift_4] = 0;
g_ibuf_112[l_shift_4] = 0;
g_ibuf_116[l_shift_4] = 0;
g_ibuf_120[l_shift_4] = EMPTY_VALUE;
g_ibuf_124[l_shift_4] = EMPTY_VALUE;
}
for (l_shift_4 = gi_96 - SignalPeriod - 1; l_shift_4 > 0; l_shift_4--) {
lda_12[l_shift_4] = iBands(NULL, 0, SignalPeriod, ArrowPeriod, 0, PRICE_CLOSE, MODE_UPPER, l_shift_4);
lda_16[l_shift_4] = iBands(NULL, 0, SignalPeriod, ArrowPeriod, 0, PRICE_CLOSE, MODE_LOWER, l_shift_4);
if (Close[l_shift_4] > lda_12[l_shift_4 + 1]) li_8 = 1;
if (Close[l_shift_4] < lda_16[l_shift_4 + 1]) li_8 = -1;
if (li_8 > 0 && lda_16[l_shift_4] < lda_16[l_shift_4 + 1]) lda_16[l_shift_4] = lda_16[l_shift_4 + 1];
if (li_8 < 0 && lda_12[l_shift_4] > lda_12[l_shift_4 + 1]) lda_12[l_shift_4] = lda_12[l_shift_4 + 1];
lda_20[l_shift_4] = lda_12[l_shift_4] + (gi_84 - 1) / 2.0 * (lda_12[l_shift_4] - lda_16[l_shift_4]);
lda_24[l_shift_4] = lda_16[l_shift_4] - (gi_84 - 1) / 2.0 * (lda_12[l_shift_4] - lda_16[l_shift_4]);
if (li_8 > 0 && lda_24[l_shift_4] < lda_24[l_shift_4 + 1]) lda_24[l_shift_4] = lda_24[l_shift_4 + 1];
if (li_8 < 0 && lda_20[l_shift_4] > lda_20[l_shift_4 + 1]) lda_20[l_shift_4] = lda_20[l_shift_4 + 1];
if (li_8 > 0) {
if (gi_88 > 0 && g_ibuf_104[l_shift_4 + 1] == -1.0) {
g_ibuf_112[l_shift_4] = lda_24[l_shift_4];
g_ibuf_104[l_shift_4] = lda_24[l_shift_4];
if (gi_92 > 0) g_ibuf_120[l_shift_4] = lda_24[l_shift_4];
if (AlertON == TRUE && l_shift_4 == 1 && !gi_136) {
ld_28 = Low[1];
if (Low[2] < ld_28) ld_28 = Low[2];
if (Low[3] < ld_28) ld_28 = Low[3];
if (Low[4] < ld_28) ld_28 = Low[4];
ld_28 -= SL_pips * Point;
l_close_36 = Close[1];
displayAlert("Buy signal", 0, ld_28, l_close_36);
gi_136 = TRUE;
gi_140 = FALSE;
}
} else {
g_ibuf_104[l_shift_4] = lda_24[l_shift_4];
if (gi_92 > 0) g_ibuf_120[l_shift_4] = lda_24[l_shift_4];
g_ibuf_112[l_shift_4] = -1;
}
if (gi_88 == 2) g_ibuf_104[l_shift_4] = 0;
g_ibuf_116[l_shift_4] = -1;
g_ibuf_108[l_shift_4] = -1.0;
g_ibuf_124[l_shift_4] = EMPTY_VALUE;
}
if (li_8 < 0) {
if (gi_88 > 0 && g_ibuf_108[l_shift_4 + 1] == -1.0) {
g_ibuf_116[l_shift_4] = lda_20[l_shift_4];
g_ibuf_108[l_shift_4] = lda_20[l_shift_4];
if (gi_92 > 0) g_ibuf_124[l_shift_4] = lda_20[l_shift_4];
if (AlertON == TRUE && l_shift_4 == 1 && !gi_140) {
ld_28 = High[1];
if (High[2] > ld_28) ld_28 = High[2];
if (High[3] > ld_28) ld_28 = High[3];
if (High[4] > ld_28) ld_28 = High[4];
ld_28 += SL_pips * Point;
l_close_36 = Close[1];
displayAlert("Sell signal", 0, ld_28, l_close_36);
gi_140 = TRUE;
gi_136 = FALSE;
}
} else {
g_ibuf_108[l_shift_4] = lda_20[l_shift_4];
if (gi_92 > 0) g_ibuf_124[l_shift_4] = lda_20[l_shift_4];
g_ibuf_116[l_shift_4] = -1;
}
if (gi_88 == 2) g_ibuf_108[l_shift_4] = 0;
g_ibuf_112[l_shift_4] = -1;
g_ibuf_104[l_shift_4] = -1.0;
g_ibuf_120[l_shift_4] = EMPTY_VALUE;
}
}
return (0);
}
This code looks very similar to the one that was posted by leoguy
 

mastermind007

Well-Known Member
#7

mastermind007

Well-Known Member
#8
HI
I remember ed pottasch did some work on similar code.
try searching on wisestocktrader.
the indicator name may be BuySellMagic
As per KelvinHand,it is a simple bollinger band( 12,2) based stop stuff.


My wish
It is a humble request.
Can some expert who can read the mt4 code lines give us some simple explanation on how to read the mt4 code lines and make some sense.

for example
li_86=may be line number 86


regards
Ford

This code plots 6 indicators and is meant for continuously trading. Code is very similar to what we see in Ami about plotting TSL but here it uses separate arrays for both. Of course, this is by just quick glance @ the code.

li_86 is automatically generated meaningless name. 99.99% this code is obtained by decompiling someone else's work.
 
Last edited:

KelvinHand

Well-Known Member
#9
Hi Ford,
PHP:
/*
Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
Website: [url]http://purebeam.biz[/url]
E-mail : [email][email protected][/email]
*/

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Red
#property indicator_color5 DeepSkyBlue
#property indicator_color6 Red

extern int SignalPeriod = 12;
extern int ArrowPeriod = 2;
int gi_84 = 1;
int gi_88 = 1;
int gi_92 = 1;
int gi_96 = 999;
extern int SL_pips = 100;
double g_ibuf_104[];
double g_ibuf_108[];
double g_ibuf_112[];
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
extern bool AlertON = TRUE;
extern bool Email = TRUE;
bool gi_136 = FALSE;
bool gi_140 = FALSE;
datetime g_time_144;

void displayAlert(string as_0, double ad_8, double ad_16, double ad_24) {
string ls_32;
string ls_40;
string ls_48;
string ls_56;
string ls_64;
if (Time[0] != g_time_144) {
g_time_144 = Time[0];
if (ad_24 != 0.0) ls_48 = " at price " + DoubleToStr(ad_24, 4);
else ls_48 = "";
if (ad_8 != 0.0) ls_40 = ", TakeProfit on " + DoubleToStr(ad_8, 4);
else ls_40 = "";
if (ad_16 != 0.0) ls_32 = ", StopLoss on " + DoubleToStr(ad_16, 4);
else ls_32 = "";
Alert("BUYSELL MAGIC " + as_0 + ls_48 + ls_40 + ls_32 + " ", Symbol(), ", ", Period(), " minute chart");
ls_56 = "BUYSELL MAGIC - " + as_0 + ls_48;
ls_64 = "BUYSELL MAGIC " + as_0 + ls_48 + ls_40 + ls_32 + " " + Symbol() + ", " + Period() + " minute chart";
if (Email) SendMail(ls_56, ls_64);
}
}

int init() {
SetIndexBuffer(0, g_ibuf_104);
SetIndexBuffer(1, g_ibuf_108);
SetIndexBuffer(2, g_ibuf_112);
SetIndexBuffer(3, g_ibuf_116);
SetIndexBuffer(4, g_ibuf_120);
SetIndexBuffer(5, g_ibuf_124);
SetIndexStyle(0, DRAW_ARROW, 6, 0);
SetIndexStyle(1, DRAW_ARROW, 6, 0);
SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 1);
SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 1);
SetIndexStyle(4, DRAW_ZIGZAG, STYLE_DASH, 1);
SetIndexStyle(5, DRAW_ZIGZAG, STYLE_DASH, 1);
SetIndexArrow(0, 159);
SetIndexArrow(1, 159);
SetIndexArrow(2, 233);
SetIndexArrow(3, 234);
IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
string ls_0 = "BUYSELL MAGIC(" + AlertON + "," + ArrowPeriod + ")";
IndicatorShortName(ls_0);
SetIndexLabel(0, "UpTrend Stop");
SetIndexLabel(1, "DownTrend Stop");
SetIndexLabel(2, "UpTrend Signal");
SetIndexLabel(3, "DownTrend Signal");
SetIndexLabel(4, "UpTrend Line");
SetIndexLabel(5, "DownTrend Line");
SetIndexDrawBegin(0, SignalPeriod);
SetIndexDrawBegin(1, SignalPeriod);
SetIndexDrawBegin(2, SignalPeriod);
SetIndexDrawBegin(3, SignalPeriod);
SetIndexDrawBegin(4, SignalPeriod);
SetIndexDrawBegin(5, SignalPeriod);
return (0);
}

int start() {
int li_8;
double lda_12[25000];
double lda_16[25000];
double lda_20[25000];
double lda_24[25000];
double ld_28;
double l_close_36;
for (int l_shift_4 = gi_96; l_shift_4 > 0; l_shift_4--) {
g_ibuf_104[l_shift_4] = 0;
g_ibuf_108[l_shift_4] = 0;
g_ibuf_112[l_shift_4] = 0;
g_ibuf_116[l_shift_4] = 0;
g_ibuf_120[l_shift_4] = EMPTY_VALUE;
g_ibuf_124[l_shift_4] = EMPTY_VALUE;
}
for (l_shift_4 = gi_96 - SignalPeriod - 1; l_shift_4 > 0; l_shift_4--) {
lda_12[l_shift_4] = iBands(NULL, 0, SignalPeriod, ArrowPeriod, 0, PRICE_CLOSE, MODE_UPPER, l_shift_4);
lda_16[l_shift_4] = iBands(NULL, 0, SignalPeriod, ArrowPeriod, 0, PRICE_CLOSE, MODE_LOWER, l_shift_4);
if (Close[l_shift_4] > lda_12[l_shift_4 + 1]) li_8 = 1;
if (Close[l_shift_4] < lda_16[l_shift_4 + 1]) li_8 = -1;
if (li_8 > 0 && lda_16[l_shift_4] < lda_16[l_shift_4 + 1]) lda_16[l_shift_4] = lda_16[l_shift_4 + 1];
if (li_8 < 0 && lda_12[l_shift_4] > lda_12[l_shift_4 + 1]) lda_12[l_shift_4] = lda_12[l_shift_4 + 1];
lda_20[l_shift_4] = lda_12[l_shift_4] + (gi_84 - 1) / 2.0 * (lda_12[l_shift_4] - lda_16[l_shift_4]);
lda_24[l_shift_4] = lda_16[l_shift_4] - (gi_84 - 1) / 2.0 * (lda_12[l_shift_4] - lda_16[l_shift_4]);
if (li_8 > 0 && lda_24[l_shift_4] < lda_24[l_shift_4 + 1]) lda_24[l_shift_4] = lda_24[l_shift_4 + 1];
if (li_8 < 0 && lda_20[l_shift_4] > lda_20[l_shift_4 + 1]) lda_20[l_shift_4] = lda_20[l_shift_4 + 1];
if (li_8 > 0) {
if (gi_88 > 0 && g_ibuf_104[l_shift_4 + 1] == -1.0) {
g_ibuf_112[l_shift_4] = lda_24[l_shift_4];
g_ibuf_104[l_shift_4] = lda_24[l_shift_4];
if (gi_92 > 0) g_ibuf_120[l_shift_4] = lda_24[l_shift_4];
if (AlertON == TRUE && l_shift_4 == 1 && !gi_136) {
ld_28 = Low[1];
if (Low[2] < ld_28) ld_28 = Low[2];
if (Low[3] < ld_28) ld_28 = Low[3];
if (Low[4] < ld_28) ld_28 = Low[4];
ld_28 -= SL_pips * Point;
l_close_36 = Close[1];
displayAlert("Buy signal", 0, ld_28, l_close_36);
gi_136 = TRUE;
gi_140 = FALSE;
}
} else {
g_ibuf_104[l_shift_4] = lda_24[l_shift_4];
if (gi_92 > 0) g_ibuf_120[l_shift_4] = lda_24[l_shift_4];
g_ibuf_112[l_shift_4] = -1;
}
if (gi_88 == 2) g_ibuf_104[l_shift_4] = 0;
g_ibuf_116[l_shift_4] = -1;
g_ibuf_108[l_shift_4] = -1.0;
g_ibuf_124[l_shift_4] = EMPTY_VALUE;
}
if (li_8 < 0) {
if (gi_88 > 0 && g_ibuf_108[l_shift_4 + 1] == -1.0) {
g_ibuf_116[l_shift_4] = lda_20[l_shift_4];
g_ibuf_108[l_shift_4] = lda_20[l_shift_4];
if (gi_92 > 0) g_ibuf_124[l_shift_4] = lda_20[l_shift_4];
if (AlertON == TRUE && l_shift_4 == 1 && !gi_140) {
ld_28 = High[1];
if (High[2] > ld_28) ld_28 = High[2];
if (High[3] > ld_28) ld_28 = High[3];
if (High[4] > ld_28) ld_28 = High[4];
ld_28 += SL_pips * Point;
l_close_36 = Close[1];
displayAlert("Sell signal", 0, ld_28, l_close_36);
gi_140 = TRUE;
gi_136 = FALSE;
}
} else {
g_ibuf_108[l_shift_4] = lda_20[l_shift_4];
if (gi_92 > 0) g_ibuf_124[l_shift_4] = lda_20[l_shift_4];
g_ibuf_116[l_shift_4] = -1;
}
if (gi_88 == 2) g_ibuf_108[l_shift_4] = 0;
g_ibuf_112[l_shift_4] = -1;
g_ibuf_104[l_shift_4] = -1.0;
g_ibuf_120[l_shift_4] = EMPTY_VALUE;
}
}
return (0);
}

Above is derived from this code. I try to give a rough guide

PHP:
//+------------------------------------------------------------------+
//|                                               BBands_Stop_v1.mq4 |
//|                           Copyright © 2006, TrendLaboratory Ltd. |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                       E-mail: [email protected] |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, TrendLaboratory Ltd."
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Chartreuse
#property indicator_color2 Orange
#property indicator_color3 Chartreuse
#property indicator_color4 Orange
#property indicator_color5 Chartreuse
#property indicator_color6 Orange
//---- input parameters
extern int    Length=  12;  //KH::=>20;      // Bollinger Bands Period
extern int    Deviation=2;    // Deviation
/*extern double */ int MoneyRisk=1; //KH::==>1.00; // Offset Factor
extern int    Signal=1;       // Display signals mode: 1-Signals & Stops; 0-only Stops; 2-only Signals;
extern int    Line=1;         // Display line mode: 0-no,1-yes  

//KH::=> Added
extern bool AlertON = TRUE;
extern bool Email = TRUE;
bool gi_136 = FALSE;
bool gi_140 = FALSE;
datetime g_time_144;

extern int    Nbars=1000;
//---- indicator buffers
double UpTrendBuffer[];
double DownTrendBuffer[];
double UpTrendSignal[];
double DownTrendSignal[];
double UpTrendLine[];
double DownTrendLine[];


/*KH:: Added
   
   Function:   displayAlert()
   AlertIf  BUY OR SELL of the latest setup on MessageBox
   Email If option is on
  

   Inputs:
     strSignal  - "BUY Signal"  OR "SELL Signal"
     TP - Target Profit
     SL - Stop Loss 
     EP - Entry Price
   
*/
void displayAlert(string strSignal , double TP, double SL, double EP) {
string ls_32;
string ls_40;
string ls_48;
string ls_56;
string ls_64;
if (Time[0] != g_time_144) {
g_time_144 = Time[0];
if (EP != 0.0) ls_48 = " at price " + DoubleToStr(EP, 4);
else ls_48 = "";
if (TP != 0.0) ls_40 = ", TakeProfit on " + DoubleToStr(TP 4);
else ls_40 = "";
if (SL != 0.0) ls_32 = ", StopLoss on " + DoubleToStr(SL, 4);
else ls_32 = "";
Alert("BUYSELL MAGIC " + strSignal  + ls_48 + ls_40 + ls_32 + " ", Symbol(), ", ", Period(), " minute chart");
ls_56 = "BUYSELL MAGIC - " + strSignal  + ls_48;
ls_64 = "BUYSELL MAGIC " + strSignal  + ls_48 + ls_40 + ls_32 + " " + Symbol() + ", " + Period() + " minute chart";
if (Email) SendMail(ls_56, ls_64);
}
}
//-----------------------------


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
  int init()
  {
   string short_name;
//---- indicator line
   
   SetIndexBuffer(0,UpTrendBuffer);
   SetIndexBuffer(1,DownTrendBuffer);
   SetIndexBuffer(2,UpTrendSignal);
   SetIndexBuffer(3,DownTrendSignal);
   SetIndexBuffer(4,UpTrendLine);
   SetIndexBuffer(5,DownTrendLine);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexStyle(4,DRAW_ZIGZAG);   //KH::=>DRAW_LINE
   SetIndexStyle(5,DRAW_ZIGZAG);   //KH::=>DRAW_LINE
   SetIndexArrow(0,159);   
   SetIndexArrow(1,159);   
   SetIndexArrow(2,233);   //change to up arrow, KH::=> 108
   SetIndexArrow(3,234);   //change to down arrow, KH::=> 108
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
   short_name="BUYSELL MAGIC("+Length+","+Deviation+")";      //KH::=>>"BBands Stop("+Length+","+Deviation+")";
   IndicatorShortName(short_name);


   SetIndexLabel(0,"UpTrend Stop");    /*KH::=> This is the Upper Trailing Stop Loss*/ 
   SetIndexLabel(1,"DownTrend Stop");  /*KH::=> This is the Lower Trailing Stop Loss*/ 

   SetIndexLabel(2,"UpTrend Signal");   /*KH::=> This is the Breakout Long Entry (Green)Arrow*/
   SetIndexLabel(3,"DownTrend Signal"); /*KH::=> This is the Breakdown Short Entry (Red)Arrow*/

   /* This formed the ZigZag Trend line from the First Buy/Sell StopLoss */
   SetIndexLabel(4,"UpTrend Line");
   SetIndexLabel(5,"DownTrend Line");
//----
   SetIndexDrawBegin(0,Length);
   SetIndexDrawBegin(1,Length);
   SetIndexDrawBegin(2,Length);
   SetIndexDrawBegin(3,Length);
   SetIndexDrawBegin(4,Length);
   SetIndexDrawBegin(5,Length);
//----
   return(0);
  }

int start()
  {
   int    i,shift,trend;
   double smax[25000],smin[25000],bsmax[25000],bsmin[25000];


  //KH::=> Initialize all display external buffers
   for (shift=Nbars;shift>=0;shift--)
   {
   UpTrendBuffer[shift]=0;
   DownTrendBuffer[shift]=0;
   UpTrendSignal[shift]=0;
   DownTrendSignal[shift]=0;
   UpTrendLine[shift]=EMPTY_VALUE;
   DownTrendLine[shift]=EMPTY_VALUE;
   }
   
   for (shift=Nbars-Length-1;shift>=0;shift--)
   {	
     //KH::=> Construct the upper and lower band
     smax[shift]=iBands(NULL,0,Length,Deviation,0,PRICE_CLOSE,MODE_UPPER,shift);
     smin[shift]=iBands(NULL,0,Length,Deviation,0,PRICE_CLOSE,MODE_LOWER,shift);
	
          //KH:: If Close up Prev BBUpper, then consider Up Trend
	  if (Close[shift]>smax[shift+1]) trend=1; 

          //KH:: If Close up Prev BBLower, then consider Down Trend
	  if (Close[shift]<smin[shift+1]) trend=-1;
		 	
          //KH:: IF UpTrend AND the BBLower expand lower, THEN .....
	  if(trend>0 && smin[shift]<smin[shift+1]) smin[shift]=smin[shift+1];

          //KH:: IF DownTrend AND the BBUpper expand Higher, THEN .....
	  if(trend<0 && smax[shift]>smax[shift+1]) smax[shift]=smax[shift+1];
	 
          //KH:: Setup the Trailing Stoploss 
  
	  bsmax[shift]=smax[shift]+0.5*(MoneyRisk-1)*(smax[shift]-smin[shift]);
	  bsmin[shift]=smin[shift]-0.5*(MoneyRisk-1)*(smax[shift]-smin[shift]);
		
	  if(trend>0 && bsmin[shift]<bsmin[shift+1]) bsmin[shift]=bsmin[shift+1];
	  if(trend<0 && bsmax[shift]>bsmax[shift+1]) bsmax[shift]=bsmax[shift+1];
	  
	  if (trend>0) 
	  {
             //KH:: Since Trend is up, Display the UpArrow and Up TSL if Signal is turn on
	     if (Signal>0 && UpTrendBuffer[shift+1]==-1.0)
	     {
	     UpTrendSignal[shift]=bsmin[shift];    //KH:: UpArrow
	     UpTrendBuffer[shift]=bsmin[shift];    //KH:: Up TSL

             //KH:: IF Line is on, THEN Draw ZIGZAG UP 
	     if(Line>0) UpTrendLine[shift]=bsmin[shift];

             //KH:: Added -------------------------------------------
             if (AlertON == TRUE && l_shift_4 == 1 && !gi_136) {

                ld_28 = Low[1];                                // Take the Previous Low as Initial SL 
                if (Low[2] < ld_28) ld_28 = Low[2];   // Find the lowest of the previous 3 bars
                if (Low[3] < ld_28) ld_28 = Low[3];   //
                if (Low[4] < ld_28) ld_28 = Low[4];   //
                ld_28 -= SL_pips * Point;                  // Added this Initial SL with define pips 
                l_close_36 = Close[1];                      // Take this previous Close As Entry Price

                //-- Display the Alert, with Entry and StopLoss, But No Target Profit is needed.
                displayAlert("Buy signal", 0, ld_28, l_close_36);

               gi_136 = TRUE;      //Buy is trigger
               gi_140 = FALSE;    //Sell is reset  
              }


	     }
	     else
	     {
	     UpTrendBuffer[shift]=bsmin[shift];
	     if(Line>0) UpTrendLine[shift]=bsmin[shift];
	     UpTrendSignal[shift]=-1;
	     }

          //KH:: IF Signal is set to 2 THEN show the UpArrow,  Up TSL turn off
	  if (Signal==2) UpTrendBuffer[shift]=0;   
	  DownTrendSignal[shift]=-1;
	  DownTrendBuffer[shift]=-1.0;
	  DownTrendLine[shift]=EMPTY_VALUE;
	  }

           //KH:: Since Trend is down, Display the DownArrow and Down TSL if Signal is turn on
	  if (trend<0) 
	  {
	  if (Signal>0 && DownTrendBuffer[shift+1]==-1.0)
	     {
	     DownTrendSignal[shift]=bsmax[shift];    //KH:: DownArrow
	     DownTrendBuffer[shift]=bsmax[shift];    //KH:: Down TSL

             //KH:: IF Line is on, THEN Draw ZIGZAG UP 
   	     if(Line>0) DownTrendLine[shift]=bsmax[shift];

              //KH:: Added  ------------------------------------------------
              if (AlertON == TRUE && l_shift_4 == 1 && !gi_140) {
              ld_28 = High[1];                                // Take the Previous Low as Initial SL 
              if (High[2] > ld_28) ld_28 = High[2];  // Find the highest of the previous 3 bars
              if (High[3] > ld_28) ld_28 = High[3];  //
              if (High[4] > ld_28) ld_28 = High[4];  //
              ld_28 += SL_pips * Point;                  // Added this Initial SL with define pips 
              l_close_36 = Close[1];                       // Take this previous Close As Entry Price

              //-- Display the Alert, with Entry and StopLoss, But No Target Profit is needed.
              displayAlert("Sell signal", 0, ld_28, l_close_36);
              gi_140 = TRUE;      //Sell is trigger
               gi_136 = FALSE;    // Buy is reset
          }



	     }
	     else
	     {
	     DownTrendBuffer[shift]=bsmax[shift];
	     if(Line>0)DownTrendLine[shift]=bsmax[shift];
	     DownTrendSignal[shift]=-1;
	     }

           //KH:: IF Signal is set to 2 THEN show the DownArrow,  Down TSL turn off
	  if (Signal==2) DownTrendBuffer[shift]=0;    
	  UpTrendSignal[shift]=-1;
	  UpTrendBuffer[shift]=-1.0;
	  UpTrendLine[shift]=EMPTY_VALUE;
	  }
	  
	 }
	return(0);	
 }
**** T H E E N D ****
 
Last edited:

bpr

Well-Known Member
#10
HI
I remember ed pottasch did some work on similar code.
try searching on wisestocktrader.
the indicator name may be BuySellMagic
As per KelvinHand,it is a simple bollinger band( 12,2) based stop stuff.


My wish
It is a humble request.
Can some expert who can read the mt4 code lines give us some simple explanation on how to read the mt4 code lines and make some sense.

for example
li_86=may be line number 86


regards
I am no expert but some ideas here...

these are the normal conventions

l -> local
g -> global
i - > int
d -> double

so li means local int and gd global double etc...
the number is a random unique number to identify the variable.
This is not the original source code.
While decompiling the decompiler unable to fetch the orginal variable name so substitue the variable names this way. or the varibales names info is lost when it is converted to ex4 file so decompiler has no way to get it back.

cheers :)
 

Similar threads